Fossil SCM
Omit SHA3-224 as an option. The only two artifact naming hash options are SHA1 and SHA3-256.
Commit
c88662873f2a3a5e7b8ce61611e5cd12144e4a7e
Parent
7bd36bc52dca8d5…
2 files changed
+5
-34
+3
-3
+5
-34
| --- src/hname.c | ||
| +++ src/hname.c | ||
| @@ -28,12 +28,11 @@ | ||
| 28 | 28 | /* |
| 29 | 29 | ** Code numbers for the allowed hash algorithms. |
| 30 | 30 | */ |
| 31 | 31 | #define HNAME_ERROR 0 /* Not a valid hash */ |
| 32 | 32 | #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 */ | |
| 35 | 34 | |
| 36 | 35 | /* |
| 37 | 36 | ** Minimum and maximum lengths for a hash value when hex encoded. |
| 38 | 37 | */ |
| 39 | 38 | #define HNAME_MIN 40 /* Length for SHA1 */ |
| @@ -41,45 +40,23 @@ | ||
| 41 | 40 | |
| 42 | 41 | /* |
| 43 | 42 | ** Hash lengths for the various algorithms |
| 44 | 43 | */ |
| 45 | 44 | #define HNAME_LEN_SHA1 40 |
| 46 | -#define HNAME_LEN_K224 56 | |
| 47 | 45 | #define HNAME_LEN_K256 64 |
| 48 | 46 | |
| 49 | 47 | #endif /* INTERFACE */ |
| 50 | 48 | |
| 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 | 49 | /* |
| 72 | 50 | ** Return the integer hash algorithm code number (ex: HNAME_K224) for |
| 73 | 51 | ** the hash string provided. Or return HNAME_ERROR (0) if the input string |
| 74 | 52 | ** is not a valid artifact hash string. |
| 75 | 53 | */ |
| 76 | 54 | int hname_validate(const char *zHash, int nHash){ |
| 77 | 55 | int id; |
| 78 | 56 | switch( nHash ){ |
| 79 | 57 | case HNAME_LEN_SHA1: id = HNAME_SHA1; break; |
| 80 | - case HNAME_LEN_K224: id = HNAME_K224; break; | |
| 81 | 58 | case HNAME_LEN_K256: id = HNAME_K256; break; |
| 82 | 59 | default: return HNAME_ERROR; |
| 83 | 60 | } |
| 84 | 61 | if( !validate16(zHash, nHash) ) return HNAME_ERROR; |
| 85 | 62 | return id; |
| @@ -103,17 +80,14 @@ | ||
| 103 | 80 | sha1sum_blob(pContent, &hash); |
| 104 | 81 | if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1; |
| 105 | 82 | blob_reset(&hash); |
| 106 | 83 | break; |
| 107 | 84 | } |
| 108 | - case HNAME_LEN_K224: | |
| 109 | 85 | case HNAME_LEN_K256: { |
| 110 | - sha3sum_init(nHash*4); | |
| 86 | + sha3sum_init(256); | |
| 111 | 87 | 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; | |
| 115 | 89 | break; |
| 116 | 90 | } |
| 117 | 91 | } |
| 118 | 92 | return id; |
| 119 | 93 | } |
| @@ -138,18 +112,15 @@ | ||
| 138 | 112 | sha1sum_file(zFile, &hash); |
| 139 | 113 | if( memcmp(blob_buffer(&hash),zHash,HNAME_LEN_SHA1)==0 ) id = HNAME_SHA1; |
| 140 | 114 | blob_reset(&hash); |
| 141 | 115 | break; |
| 142 | 116 | } |
| 143 | - case HNAME_LEN_K224: | |
| 144 | 117 | case HNAME_LEN_K256: { |
| 145 | 118 | 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; | |
| 150 | 121 | blob_reset(&hash); |
| 151 | 122 | break; |
| 152 | 123 | } |
| 153 | 124 | } |
| 154 | 125 | return id; |
| 155 | 126 | } |
| 156 | 127 |
| --- 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 @@ | ||
| 624 | 624 | ** Compute an SHA3 checksum of all files named on the command-line. |
| 625 | 625 | ** If a file is named "-" then take its content from standard input. |
| 626 | 626 | ** |
| 627 | 627 | ** Options: |
| 628 | 628 | ** |
| 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) | |
| 631 | 631 | ** --384 Compute a SHA3-384 hash |
| 632 | 632 | ** --512 Compute a SHA3-512 hash |
| 633 | 633 | ** --size N An N-bit hash. N must be a multiple of 32 between 128 |
| 634 | 634 | ** and 512. |
| 635 | 635 | */ |
| 636 | 636 | void sha3sum_test(void){ |
| 637 | 637 | int i; |
| 638 | 638 | Blob in; |
| 639 | 639 | Blob cksum; |
| 640 | - int iSize = 224; | |
| 640 | + int iSize = 256; | |
| 641 | 641 | |
| 642 | 642 | if( find_option("224",0,0)!=0 ) iSize = 224; |
| 643 | 643 | else if( find_option("256",0,0)!=0 ) iSize = 256; |
| 644 | 644 | else if( find_option("384",0,0)!=0 ) iSize = 384; |
| 645 | 645 | else if( find_option("512",0,0)!=0 ) iSize = 512; |
| 646 | 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 (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 |