Fossil SCM

Omit SHA3-224 as an option. The only two artifact naming hash options are SHA1 and SHA3-256.

drh 2017-03-01 11:29 fossil-2.0
Commit c88662873f2a3a5e7b8ce61611e5cd12144e4a7e
2 files changed +5 -34 +3 -3
+5 -34
--- src/hname.c
+++ src/hname.c
@@ -28,12 +28,11 @@
2828
/*
2929
** Code numbers for the allowed hash algorithms.
3030
*/
3131
#define HNAME_ERROR 0 /* Not a valid hash */
3232
#define HNAME_SHA1 1 /* SHA1 */
33
-#define HNAME_K224 2 /* SHA3-224 */
34
-#define HNAME_K256 3 /* SHA3-256 */
33
+#define HNAME_K256 2 /* SHA3-256 */
3534
3635
/*
3736
** Minimum and maximum lengths for a hash value when hex encoded.
3837
*/
3938
#define HNAME_MIN 40 /* Length for SHA1 */
@@ -41,45 +40,23 @@
4140
4241
/*
4342
** Hash lengths for the various algorithms
4443
*/
4544
#define HNAME_LEN_SHA1 40
46
-#define HNAME_LEN_K224 56
4745
#define HNAME_LEN_K256 64
4846
4947
#endif /* INTERFACE */
5048
51
-
52
-/*
53
-** Convert a hash algorithm code number into a string name for that algorithm.
54
-*/
55
-const char *hname_algname(int aid){
56
- if( aid==HNAME_K224 ) return "SHA3-224";
57
- return "SHA1";
58
-}
59
-
60
-/*
61
-** Given a hash algorithm name, return its appropriate number. Return
62
-** HNAME_ERROR if the name is unknown.
63
-*/
64
-int hname_algid(const char *zName){
65
- if( fossil_stricmp(zName,"sha1")==0 ) return HNAME_SHA1;
66
- if( fossil_stricmp(zName,"sha3-224")==0 ) return HNAME_K224;
67
- if( fossil_stricmp(zName,"sha3-256")==0 ) return HNAME_K256;
68
- return HNAME_ERROR;
69
-}
70
-
7149
/*
7250
** Return the integer hash algorithm code number (ex: HNAME_K224) for
7351
** the hash string provided. Or return HNAME_ERROR (0) if the input string
7452
** is not a valid artifact hash string.
7553
*/
7654
int hname_validate(const char *zHash, int nHash){
7755
int id;
7856
switch( nHash ){
7957
case HNAME_LEN_SHA1: id = HNAME_SHA1; break;
80
- case HNAME_LEN_K224: id = HNAME_K224; break;
8158
case HNAME_LEN_K256: id = HNAME_K256; break;
8259
default: return HNAME_ERROR;
8360
}
8461
if( !validate16(zHash, nHash) ) return HNAME_ERROR;
8562
return id;
@@ -103,17 +80,14 @@
10380
sha1sum_blob(pContent, &hash);
10481
if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1;
10582
blob_reset(&hash);
10683
break;
10784
}
108
- case HNAME_LEN_K224:
10985
case HNAME_LEN_K256: {
110
- sha3sum_init(nHash*4);
86
+ sha3sum_init(256);
11187
sha3sum_step_blob(pContent);
112
- if( memcmp(sha3sum_finish(0),zHash,nHash)==0 ){
113
- id = nHash==HNAME_LEN_K224 ? HNAME_K224 : HNAME_K256;
114
- }
88
+ if( memcmp(sha3sum_finish(0),zHash,64)==0 ) id = HNAME_K256;
11589
break;
11690
}
11791
}
11892
return id;
11993
}
@@ -138,18 +112,15 @@
138112
sha1sum_file(zFile, &hash);
139113
if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1;
140114
blob_reset(&hash);
141115
break;
142116
}
143
- case HNAME_LEN_K224:
144117
case HNAME_LEN_K256: {
145118
Blob hash;
146
- sha3sum_file(zFile, nHash*4, &hash);
147
- if( memcmp(blob_buffer(&hash),zHash,nHash)==0 ){
148
- id = nHash==HNAME_LEN_K224 ? HNAME_K224 : HNAME_K256;
149
- }
119
+ sha3sum_file(zFile, 256, &hash);
120
+ if( memcmp(blob_buffer(&hash),zHash,64)==0 ) id = HNAME_LEN_K256;
150121
blob_reset(&hash);
151122
break;
152123
}
153124
}
154125
return id;
155126
}
156127
--- src/hname.c
+++ src/hname.c
@@ -28,12 +28,11 @@
28 /*
29 ** Code numbers for the allowed hash algorithms.
30 */
31 #define HNAME_ERROR 0 /* Not a valid hash */
32 #define HNAME_SHA1 1 /* SHA1 */
33 #define HNAME_K224 2 /* SHA3-224 */
34 #define HNAME_K256 3 /* SHA3-256 */
35
36 /*
37 ** Minimum and maximum lengths for a hash value when hex encoded.
38 */
39 #define HNAME_MIN 40 /* Length for SHA1 */
@@ -41,45 +40,23 @@
41
42 /*
43 ** Hash lengths for the various algorithms
44 */
45 #define HNAME_LEN_SHA1 40
46 #define HNAME_LEN_K224 56
47 #define HNAME_LEN_K256 64
48
49 #endif /* INTERFACE */
50
51
52 /*
53 ** Convert a hash algorithm code number into a string name for that algorithm.
54 */
55 const char *hname_algname(int aid){
56 if( aid==HNAME_K224 ) return "SHA3-224";
57 return "SHA1";
58 }
59
60 /*
61 ** Given a hash algorithm name, return its appropriate number. Return
62 ** HNAME_ERROR if the name is unknown.
63 */
64 int hname_algid(const char *zName){
65 if( fossil_stricmp(zName,"sha1")==0 ) return HNAME_SHA1;
66 if( fossil_stricmp(zName,"sha3-224")==0 ) return HNAME_K224;
67 if( fossil_stricmp(zName,"sha3-256")==0 ) return HNAME_K256;
68 return HNAME_ERROR;
69 }
70
71 /*
72 ** Return the integer hash algorithm code number (ex: HNAME_K224) for
73 ** the hash string provided. Or return HNAME_ERROR (0) if the input string
74 ** is not a valid artifact hash string.
75 */
76 int hname_validate(const char *zHash, int nHash){
77 int id;
78 switch( nHash ){
79 case HNAME_LEN_SHA1: id = HNAME_SHA1; break;
80 case HNAME_LEN_K224: id = HNAME_K224; break;
81 case HNAME_LEN_K256: id = HNAME_K256; break;
82 default: return HNAME_ERROR;
83 }
84 if( !validate16(zHash, nHash) ) return HNAME_ERROR;
85 return id;
@@ -103,17 +80,14 @@
103 sha1sum_blob(pContent, &hash);
104 if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1;
105 blob_reset(&hash);
106 break;
107 }
108 case HNAME_LEN_K224:
109 case HNAME_LEN_K256: {
110 sha3sum_init(nHash*4);
111 sha3sum_step_blob(pContent);
112 if( memcmp(sha3sum_finish(0),zHash,nHash)==0 ){
113 id = nHash==HNAME_LEN_K224 ? HNAME_K224 : HNAME_K256;
114 }
115 break;
116 }
117 }
118 return id;
119 }
@@ -138,18 +112,15 @@
138 sha1sum_file(zFile, &hash);
139 if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1;
140 blob_reset(&hash);
141 break;
142 }
143 case HNAME_LEN_K224:
144 case HNAME_LEN_K256: {
145 Blob hash;
146 sha3sum_file(zFile, nHash*4, &hash);
147 if( memcmp(blob_buffer(&hash),zHash,nHash)==0 ){
148 id = nHash==HNAME_LEN_K224 ? HNAME_K224 : HNAME_K256;
149 }
150 blob_reset(&hash);
151 break;
152 }
153 }
154 return id;
155 }
156
--- src/hname.c
+++ src/hname.c
@@ -28,12 +28,11 @@
28 /*
29 ** Code numbers for the allowed hash algorithms.
30 */
31 #define HNAME_ERROR 0 /* Not a valid hash */
32 #define HNAME_SHA1 1 /* SHA1 */
33 #define HNAME_K256 2 /* SHA3-256 */
 
34
35 /*
36 ** Minimum and maximum lengths for a hash value when hex encoded.
37 */
38 #define HNAME_MIN 40 /* Length for SHA1 */
@@ -41,45 +40,23 @@
40
41 /*
42 ** Hash lengths for the various algorithms
43 */
44 #define HNAME_LEN_SHA1 40
 
45 #define HNAME_LEN_K256 64
46
47 #endif /* INTERFACE */
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49 /*
50 ** Return the integer hash algorithm code number (ex: HNAME_K224) for
51 ** the hash string provided. Or return HNAME_ERROR (0) if the input string
52 ** is not a valid artifact hash string.
53 */
54 int hname_validate(const char *zHash, int nHash){
55 int id;
56 switch( nHash ){
57 case HNAME_LEN_SHA1: id = HNAME_SHA1; break;
 
58 case HNAME_LEN_K256: id = HNAME_K256; break;
59 default: return HNAME_ERROR;
60 }
61 if( !validate16(zHash, nHash) ) return HNAME_ERROR;
62 return id;
@@ -103,17 +80,14 @@
80 sha1sum_blob(pContent, &hash);
81 if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1;
82 blob_reset(&hash);
83 break;
84 }
 
85 case HNAME_LEN_K256: {
86 sha3sum_init(256);
87 sha3sum_step_blob(pContent);
88 if( memcmp(sha3sum_finish(0),zHash,64)==0 ) id = HNAME_K256;
 
 
89 break;
90 }
91 }
92 return id;
93 }
@@ -138,18 +112,15 @@
112 sha1sum_file(zFile, &hash);
113 if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1;
114 blob_reset(&hash);
115 break;
116 }
 
117 case HNAME_LEN_K256: {
118 Blob hash;
119 sha3sum_file(zFile, 256, &hash);
120 if( memcmp(blob_buffer(&hash),zHash,64)==0 ) id = HNAME_LEN_K256;
 
 
121 blob_reset(&hash);
122 break;
123 }
124 }
125 return id;
126 }
127
+3 -3
--- src/sha3.c
+++ src/sha3.c
@@ -624,22 +624,22 @@
624624
** Compute an SHA3 checksum of all files named on the command-line.
625625
** If a file is named "-" then take its content from standard input.
626626
**
627627
** Options:
628628
**
629
-** --224 Compute a SHA3-224 hash (the default)
630
-** --256 Compute a SHA3-256 hash
629
+** --224 Compute a SHA3-224 hash
630
+** --256 Compute a SHA3-256 hash (the default)
631631
** --384 Compute a SHA3-384 hash
632632
** --512 Compute a SHA3-512 hash
633633
** --size N An N-bit hash. N must be a multiple of 32 between 128
634634
** and 512.
635635
*/
636636
void sha3sum_test(void){
637637
int i;
638638
Blob in;
639639
Blob cksum;
640
- int iSize = 224;
640
+ int iSize = 256;
641641
642642
if( find_option("224",0,0)!=0 ) iSize = 224;
643643
else if( find_option("256",0,0)!=0 ) iSize = 256;
644644
else if( find_option("384",0,0)!=0 ) iSize = 384;
645645
else if( find_option("512",0,0)!=0 ) iSize = 512;
646646
--- src/sha3.c
+++ src/sha3.c
@@ -624,22 +624,22 @@
624 ** Compute an SHA3 checksum of all files named on the command-line.
625 ** If a file is named "-" then take its content from standard input.
626 **
627 ** Options:
628 **
629 ** --224 Compute a SHA3-224 hash (the default)
630 ** --256 Compute a SHA3-256 hash
631 ** --384 Compute a SHA3-384 hash
632 ** --512 Compute a SHA3-512 hash
633 ** --size N An N-bit hash. N must be a multiple of 32 between 128
634 ** and 512.
635 */
636 void sha3sum_test(void){
637 int i;
638 Blob in;
639 Blob cksum;
640 int iSize = 224;
641
642 if( find_option("224",0,0)!=0 ) iSize = 224;
643 else if( find_option("256",0,0)!=0 ) iSize = 256;
644 else if( find_option("384",0,0)!=0 ) iSize = 384;
645 else if( find_option("512",0,0)!=0 ) iSize = 512;
646
--- src/sha3.c
+++ src/sha3.c
@@ -624,22 +624,22 @@
624 ** Compute an SHA3 checksum of all files named on the command-line.
625 ** If a file is named "-" then take its content from standard input.
626 **
627 ** Options:
628 **
629 ** --224 Compute a SHA3-224 hash
630 ** --256 Compute a SHA3-256 hash (the default)
631 ** --384 Compute a SHA3-384 hash
632 ** --512 Compute a SHA3-512 hash
633 ** --size N An N-bit hash. N must be a multiple of 32 between 128
634 ** and 512.
635 */
636 void sha3sum_test(void){
637 int i;
638 Blob in;
639 Blob cksum;
640 int iSize = 256;
641
642 if( find_option("224",0,0)!=0 ) iSize = 224;
643 else if( find_option("256",0,0)!=0 ) iSize = 256;
644 else if( find_option("384",0,0)!=0 ) iSize = 384;
645 else if( find_option("512",0,0)!=0 ) iSize = 512;
646

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button