| | @@ -42,10 +42,15 @@ |
| 42 | 42 | ** Hash lengths for the various algorithms |
| 43 | 43 | */ |
| 44 | 44 | #define HNAME_LEN_SHA1 40 |
| 45 | 45 | #define HNAME_LEN_K256 64 |
| 46 | 46 | |
| 47 | +/* |
| 48 | +** The number of distinct hash algorithms: |
| 49 | +*/ |
| 50 | +#define HNAME_COUNT 2 /* Just SHA1 and SHA3-256. Let's keep it that way! */ |
| 51 | + |
| 47 | 52 | #endif /* INTERFACE */ |
| 48 | 53 | |
| 49 | 54 | /* |
| 50 | 55 | ** Return the integer hash algorithm code number (ex: HNAME_K224) for |
| 51 | 56 | ** the hash string provided. Or return HNAME_ERROR (0) if the input string |
| | @@ -122,5 +127,31 @@ |
| 122 | 127 | break; |
| 123 | 128 | } |
| 124 | 129 | } |
| 125 | 130 | return id; |
| 126 | 131 | } |
| 132 | + |
| 133 | +/* |
| 134 | +** Compute a hash on blob pContent. Write the hash into blob pHashOut. |
| 135 | +** This routine assumes that pHashOut is uninitialized. |
| 136 | +** |
| 137 | +** The preferred hash is used for iHType==0, and various alternative hashes |
| 138 | +** are used for iHType>0 && iHType<NHAME_COUNT. |
| 139 | +*/ |
| 140 | +void hname_hash(const Blob *pContent, unsigned int iHType, Blob *pHashOut){ |
| 141 | +#if RELEASE_VERSION_NUMBER>=20100 |
| 142 | + /* For Fossil 2.1 and later, the preferred hash algorithm is SHA3-256 and |
| 143 | + ** SHA1 is the secondary hash algorithm. */ |
| 144 | + switch( iHType ){ |
| 145 | + case 0: sha3sum_blob(pContent, 256, pHashOut); break; |
| 146 | + case 1: sha1sum_blob(pContent, pHashOut); break; |
| 147 | + } |
| 148 | +#else |
| 149 | + /* Prior to Fossil 2.1, the preferred hash algorithm is SHA1 (for backwards |
| 150 | + ** compatibility with Fossil 1.x) and SHA3-256 is the only auxiliary |
| 151 | + ** algorithm */ |
| 152 | + switch( iHType ){ |
| 153 | + case 0: sha1sum_blob(pContent, pHashOut); break; |
| 154 | + case 1: sha3sum_blob(pContent, 256, pHashOut); break; |
| 155 | + } |
| 156 | +#endif |
| 157 | +} |
| 127 | 158 | |