aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--checks/validate.dat5
-rw-r--r--doc/log.txt1
-rw-r--r--src/core/libstate/def_alg.cpp5
-rw-r--r--src/hash/sha2/info.txt10
-rw-r--r--src/hash/sha2/sha256.h33
-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.h57
-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
9 files changed, 103 insertions, 47 deletions
diff --git a/checks/validate.dat b/checks/validate.dat
index ba76359f8..fa2475266 100644
--- a/checks/validate.dat
+++ b/checks/validate.dat
@@ -30770,6 +30770,11 @@ A9F8DBB064EDC425B263DF4573EB6E3CADD080D9EF7BCCA048F60E163448DD6531B6B9F8CDB6\
105C88:\
8395ABC1B17BA7BF947145EB1DF1A2050C8E78C3
+[SHA-224]
+:D14A028C2A3A2BC9476102BB288234C415A2B01F828EA62AC5B3E42F
+
+61:ABD37534C7D9A2EFB9465DE931CD7055FFDB8879563AE98078D6D6D5
+
[SHA-256]
:E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
diff --git a/doc/log.txt b/doc/log.txt
index 98f949f22..5a7f0d03d 100644
--- a/doc/log.txt
+++ b/doc/log.txt
@@ -1,6 +1,7 @@
* 1.7.16, ????-??-??
- Split ECDSA and ECKAEG into distinct modules
+ - Added SHA-224
* 1.7.15, 2008-10-07
- Add GF(p) arithmetic from InSiTo
diff --git a/src/core/libstate/def_alg.cpp b/src/core/libstate/def_alg.cpp
index 0445550f7..7199b06bd 100644
--- a/src/core/libstate/def_alg.cpp
+++ b/src/core/libstate/def_alg.cpp
@@ -190,8 +190,8 @@
#endif
#if defined(BOTAN_HAS_SHA2)
- #include <botan/sha256.h>
- #include <botan/sha_64.h>
+ #include <botan/sha2_32.h>
+ #include <botan/sha2_64.h>
#endif
#if defined(BOTAN_HAS_TIGER)
@@ -504,6 +504,7 @@ Default_Engine::find_hash(const std::string& algo_spec) const
#endif
#if defined(BOTAN_HAS_SHA2)
+ HANDLE_TYPE_NO_ARGS("SHA-224", SHA_224);
HANDLE_TYPE_NO_ARGS("SHA-256", SHA_256);
HANDLE_TYPE_NO_ARGS("SHA-384", SHA_384);
HANDLE_TYPE_NO_ARGS("SHA-512", SHA_512);
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