diff options
Diffstat (limited to 'src/hash/sha2')
-rw-r--r-- | src/hash/sha2/sha2_32.cpp | 11 | ||||
-rw-r--r-- | src/hash/sha2/sha2_32.h | 12 | ||||
-rw-r--r-- | src/hash/sha2/sha2_64.cpp | 10 | ||||
-rw-r--r-- | src/hash/sha2/sha2_64.h | 12 |
4 files changed, 23 insertions, 22 deletions
diff --git a/src/hash/sha2/sha2_32.cpp b/src/hash/sha2/sha2_32.cpp index f6e124470..f0710469b 100644 --- a/src/hash/sha2/sha2_32.cpp +++ b/src/hash/sha2/sha2_32.cpp @@ -46,10 +46,11 @@ inline void F1(u32bit A, u32bit B, u32bit C, u32bit& D, /************************************************* * SHA-256 Compression Function * *************************************************/ -void SHA_224256_BASE::hash(const byte input[]) +void SHA_224_256_BASE::hash(const byte input[]) { for(u32bit j = 0; j != 16; ++j) W[j] = load_be<u32bit>(input, j); + for(u32bit j = 16; j != 64; ++j) W[j] = sigma(W[j- 2], 17, 19, 10) + W[j- 7] + sigma(W[j-15], 7, 18, 3) + W[j-16]; @@ -99,7 +100,7 @@ void SHA_224256_BASE::hash(const byte input[]) /************************************************* * Copy out the digest * *************************************************/ -void SHA_224256_BASE::copy_out(byte output[]) +void SHA_224_256_BASE::copy_out(byte output[]) { for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) store_be(digest[j/4], output + j); @@ -108,7 +109,7 @@ void SHA_224256_BASE::copy_out(byte output[]) /************************************************* * Clear memory of sensitive data * *************************************************/ -void SHA_224256_BASE::clear() throw() +void SHA_224_256_BASE::clear() throw() { MDx_HashFunction::clear(); W.clear(); @@ -119,7 +120,7 @@ void SHA_224256_BASE::clear() throw() *************************************************/ void SHA_224::clear() throw() { - SHA_224256_BASE::clear(); + SHA_224_256_BASE::clear(); digest[0] = 0xc1059ed8; digest[1] = 0x367cd507; digest[2] = 0x3070dd17; @@ -135,7 +136,7 @@ void SHA_224::clear() throw() *************************************************/ void SHA_256::clear() throw() { - SHA_224256_BASE::clear(); + SHA_224_256_BASE::clear(); digest[0] = 0x6A09E667; digest[1] = 0xBB67AE85; digest[2] = 0x3C6EF372; diff --git a/src/hash/sha2/sha2_32.h b/src/hash/sha2/sha2_32.h index a767b3d10..220767c1b 100644 --- a/src/hash/sha2/sha2_32.h +++ b/src/hash/sha2/sha2_32.h @@ -14,11 +14,11 @@ namespace Botan { /************************************************* * SHA-{224,256} Base * *************************************************/ -class BOTAN_DLL SHA_224256_BASE : public MDx_HashFunction +class BOTAN_DLL SHA_224_256_BASE : public MDx_HashFunction { protected: void clear() throw(); - SHA_224256_BASE(u32bit out) : + SHA_224_256_BASE(u32bit out) : MDx_HashFunction(out, 64, true, true) { clear(); } SecureBuffer<u32bit, 64> W; @@ -31,25 +31,25 @@ class BOTAN_DLL SHA_224256_BASE : public MDx_HashFunction /************************************************* * SHA-224 * *************************************************/ -class BOTAN_DLL SHA_224 : public SHA_224256_BASE +class BOTAN_DLL SHA_224 : public SHA_224_256_BASE { public: void clear() throw(); std::string name() const { return "SHA-224"; } HashFunction* clone() const { return new SHA_224; } - SHA_224() : SHA_224256_BASE(28) { clear(); } + SHA_224() : SHA_224_256_BASE(28) { clear(); } }; /************************************************* * SHA-256 * *************************************************/ -class BOTAN_DLL SHA_256 : public SHA_224256_BASE +class BOTAN_DLL SHA_256 : public SHA_224_256_BASE { public: void clear() throw(); std::string name() const { return "SHA-256"; } HashFunction* clone() const { return new SHA_256; } - SHA_256() : SHA_224256_BASE(32) { clear (); } + SHA_256() : SHA_224_256_BASE(32) { clear (); } }; } diff --git a/src/hash/sha2/sha2_64.cpp b/src/hash/sha2/sha2_64.cpp index 3be559730..809111d5e 100644 --- a/src/hash/sha2/sha2_64.cpp +++ b/src/hash/sha2/sha2_64.cpp @@ -45,7 +45,7 @@ inline u64bit sigma(u64bit X, u32bit rot1, u32bit rot2, u32bit shift) /************************************************* * SHA-{384,512} Compression Function * *************************************************/ -void SHA_64_BASE::hash(const byte input[]) +void SHA_384_512_BASE::hash(const byte input[]) { for(u32bit j = 0; j != 16; ++j) W[j] = load_be<u64bit>(input, j); @@ -147,7 +147,7 @@ void SHA_64_BASE::hash(const byte input[]) /************************************************* * Copy out the digest * *************************************************/ -void SHA_64_BASE::copy_out(byte output[]) +void SHA_384_512_BASE::copy_out(byte output[]) { for(u32bit j = 0; j != OUTPUT_LENGTH; j += 8) store_be(digest[j/8], output + j); @@ -156,7 +156,7 @@ void SHA_64_BASE::copy_out(byte output[]) /************************************************* * Clear memory of sensitive data * *************************************************/ -void SHA_64_BASE::clear() throw() +void SHA_384_512_BASE::clear() throw() { MDx_HashFunction::clear(); W.clear(); @@ -167,7 +167,7 @@ void SHA_64_BASE::clear() throw() *************************************************/ void SHA_384::clear() throw() { - SHA_64_BASE::clear(); + SHA_384_512_BASE::clear(); digest[0] = 0xCBBB9D5DC1059ED8; digest[1] = 0x629A292A367CD507; digest[2] = 0x9159015A3070DD17; @@ -183,7 +183,7 @@ void SHA_384::clear() throw() *************************************************/ void SHA_512::clear() throw() { - SHA_64_BASE::clear(); + SHA_384_512_BASE::clear(); digest[0] = 0x6A09E667F3BCC908; digest[1] = 0xBB67AE8584CAA73B; digest[2] = 0x3C6EF372FE94F82B; diff --git a/src/hash/sha2/sha2_64.h b/src/hash/sha2/sha2_64.h index e590d088d..004f8f165 100644 --- a/src/hash/sha2/sha2_64.h +++ b/src/hash/sha2/sha2_64.h @@ -13,11 +13,11 @@ namespace Botan { /************************************************* * SHA-{384,512} Base * *************************************************/ -class BOTAN_DLL SHA_64_BASE : public MDx_HashFunction +class BOTAN_DLL SHA_384_512_BASE : public MDx_HashFunction { protected: void clear() throw(); - SHA_64_BASE(u32bit out) : MDx_HashFunction(out, 128, true, true, 16) {} + SHA_384_512_BASE(u32bit out) : MDx_HashFunction(out, 128, true, true, 16) {} SecureBuffer<u64bit, 8> digest; private: void hash(const byte[]); @@ -29,25 +29,25 @@ class BOTAN_DLL SHA_64_BASE : public MDx_HashFunction /************************************************* * SHA-384 * *************************************************/ -class BOTAN_DLL SHA_384 : public SHA_64_BASE +class BOTAN_DLL SHA_384 : public SHA_384_512_BASE { public: void clear() throw(); std::string name() const { return "SHA-384"; } HashFunction* clone() const { return new SHA_384; } - SHA_384() : SHA_64_BASE(48) { clear(); } + SHA_384() : SHA_384_512_BASE(48) { clear(); } }; /************************************************* * SHA-512 * *************************************************/ -class BOTAN_DLL SHA_512 : public SHA_64_BASE +class BOTAN_DLL SHA_512 : public SHA_384_512_BASE { public: void clear() throw(); std::string name() const { return "SHA-512"; } HashFunction* clone() const { return new SHA_512; } - SHA_512() : SHA_64_BASE(64) { clear(); } + SHA_512() : SHA_384_512_BASE(64) { clear(); } }; } |