diff options
Diffstat (limited to 'src/hash')
-rw-r--r-- | src/hash/sha2/info.txt | 10 | ||||
-rw-r--r-- | src/hash/sha2/sha256.h | 33 | ||||
-rw-r--r-- | src/hash/sha2/sha2_32.cpp (renamed from src/hash/sha2/sha256.cpp) | 37 | ||||
-rw-r--r-- | src/hash/sha2/sha2_32.h | 57 | ||||
-rw-r--r-- | src/hash/sha2/sha2_64.cpp (renamed from src/hash/sha2/sha_64.cpp) | 2 | ||||
-rw-r--r-- | src/hash/sha2/sha2_64.h (renamed from src/hash/sha2/sha_64.h) | 0 |
6 files changed, 94 insertions, 45 deletions
diff --git a/src/hash/sha2/info.txt b/src/hash/sha2/info.txt index 71df4510b..9b92ff385 100644 --- a/src/hash/sha2/info.txt +++ b/src/hash/sha2/info.txt @@ -1,14 +1,14 @@ -realname "SHA-2 (256, 384, 512)" +realname "SHA-2 (224, 256, 384, 512)" define SHA2 load_on auto <add> -sha256.cpp -sha256.h -sha_64.cpp -sha_64.h +sha2_32.cpp +sha2_32.h +sha2_64.cpp +sha2_64.h </add> <requires> diff --git a/src/hash/sha2/sha256.h b/src/hash/sha2/sha256.h deleted file mode 100644 index cdbe02822..000000000 --- a/src/hash/sha2/sha256.h +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************* -* SHA-256 Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_SHA_256_H__ -#define BOTAN_SHA_256_H__ - -#include <botan/mdx_hash.h> - -namespace Botan { - -/************************************************* -* SHA-256 * -*************************************************/ -class BOTAN_DLL SHA_256 : public MDx_HashFunction - { - public: - void clear() throw(); - std::string name() const { return "SHA-256"; } - HashFunction* clone() const { return new SHA_256; } - SHA_256() : MDx_HashFunction(32, 64, true, true) { clear(); } - private: - void hash(const byte[]); - void copy_out(byte[]); - - SecureBuffer<u32bit, 64> W; - SecureBuffer<u32bit, 8> digest; - }; - -} - -#endif diff --git a/src/hash/sha2/sha256.cpp b/src/hash/sha2/sha2_32.cpp index 6031d177f..f6e124470 100644 --- a/src/hash/sha2/sha256.cpp +++ b/src/hash/sha2/sha2_32.cpp @@ -1,9 +1,10 @@ /************************************************* -* SHA-256 Source File * -* (C) 1999-2007 Jack Lloyd * +* SHA-{224,256} Source File * +* (C) 1999-2008 Jack Lloyd * +* 2007 FlexSecure GmbH * *************************************************/ -#include <botan/sha256.h> +#include <botan/sha2_32.h> #include <botan/loadstor.h> #include <botan/bit_ops.h> @@ -45,7 +46,7 @@ inline void F1(u32bit A, u32bit B, u32bit C, u32bit& D, /************************************************* * SHA-256 Compression Function * *************************************************/ -void SHA_256::hash(const byte input[]) +void SHA_224256_BASE::hash(const byte input[]) { for(u32bit j = 0; j != 16; ++j) W[j] = load_be<u32bit>(input, j); @@ -98,7 +99,7 @@ void SHA_256::hash(const byte input[]) /************************************************* * Copy out the digest * *************************************************/ -void SHA_256::copy_out(byte output[]) +void SHA_224256_BASE::copy_out(byte output[]) { for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) store_be(digest[j/4], output + j); @@ -107,10 +108,34 @@ void SHA_256::copy_out(byte output[]) /************************************************* * Clear memory of sensitive data * *************************************************/ -void SHA_256::clear() throw() +void SHA_224256_BASE::clear() throw() { MDx_HashFunction::clear(); W.clear(); + } + +/************************************************* +* Clear memory of sensitive data * +*************************************************/ +void SHA_224::clear() throw() + { + SHA_224256_BASE::clear(); + digest[0] = 0xc1059ed8; + digest[1] = 0x367cd507; + digest[2] = 0x3070dd17; + digest[3] = 0xf70e5939; + digest[4] = 0xffc00b31; + digest[5] = 0x68581511; + digest[6] = 0x64f98fa7; + digest[7] = 0xbefa4fa4; + } + +/************************************************* +* Clear memory of sensitive data * +*************************************************/ +void SHA_256::clear() throw() + { + SHA_224256_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 new file mode 100644 index 000000000..a767b3d10 --- /dev/null +++ b/src/hash/sha2/sha2_32.h @@ -0,0 +1,57 @@ +/************************************************* +* SHA-{224,256} Header File * +* (C) 1999-2008 Jack Lloyd * +* 2007 FlexSecure GmbH * +*************************************************/ + +#ifndef BOTAN_SHA_256_H__ +#define BOTAN_SHA_256_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/************************************************* +* SHA-{224,256} Base * +*************************************************/ +class BOTAN_DLL SHA_224256_BASE : public MDx_HashFunction + { + protected: + void clear() throw(); + SHA_224256_BASE(u32bit out) : + MDx_HashFunction(out, 64, true, true) { clear(); } + + SecureBuffer<u32bit, 64> W; + SecureBuffer<u32bit, 8> digest; + private: + void hash(const byte[]); + void copy_out(byte[]); + }; + +/************************************************* +* SHA-224 * +*************************************************/ +class BOTAN_DLL SHA_224 : public SHA_224256_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-256 * +*************************************************/ +class BOTAN_DLL SHA_256 : public SHA_224256_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 (); } + }; + +} + +#endif diff --git a/src/hash/sha2/sha_64.cpp b/src/hash/sha2/sha2_64.cpp index 7f4a28fec..3be559730 100644 --- a/src/hash/sha2/sha_64.cpp +++ b/src/hash/sha2/sha2_64.cpp @@ -3,7 +3,7 @@ * (C) 1999-2007 Jack Lloyd * *************************************************/ -#include <botan/sha_64.h> +#include <botan/sha2_64.h> #include <botan/loadstor.h> #include <botan/bit_ops.h> diff --git a/src/hash/sha2/sha_64.h b/src/hash/sha2/sha2_64.h index e590d088d..e590d088d 100644 --- a/src/hash/sha2/sha_64.h +++ b/src/hash/sha2/sha2_64.h |