aboutsummaryrefslogtreecommitdiffstats
path: root/src/hash/sha2
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash/sha2')
-rw-r--r--src/hash/sha2/info.txt11
-rw-r--r--src/hash/sha2/sha2_32.cpp50
-rw-r--r--src/hash/sha2/sha2_32.h6
-rw-r--r--src/hash/sha2/sha2_64.cpp28
-rw-r--r--src/hash/sha2/sha2_64.h6
5 files changed, 57 insertions, 44 deletions
diff --git a/src/hash/sha2/info.txt b/src/hash/sha2/info.txt
index 9b92ff385..e12f2b694 100644
--- a/src/hash/sha2/info.txt
+++ b/src/hash/sha2/info.txt
@@ -1,16 +1,5 @@
-realname "SHA-2 (224, 256, 384, 512)"
-
define SHA2
-load_on auto
-
-<add>
-sha2_32.cpp
-sha2_32.h
-sha2_64.cpp
-sha2_64.h
-</add>
-
<requires>
mdx_hash
</requires>
diff --git a/src/hash/sha2/sha2_32.cpp b/src/hash/sha2/sha2_32.cpp
index 9da2ec23f..7068dd63f 100644
--- a/src/hash/sha2/sha2_32.cpp
+++ b/src/hash/sha2/sha2_32.cpp
@@ -56,13 +56,27 @@ void SHA_224_256_BASE::compress_n(const byte input[], u32bit blocks)
for(u32bit i = 0; i != blocks; ++i)
{
- for(u32bit j = 0; j != 16; ++j)
- W[j] = load_be<u32bit>(input, j);
- input += HASH_BLOCK_SIZE;
-
- 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];
+ load_be(W.begin(), input, 16);
+
+ for(u32bit j = 16; j != 64; j += 8)
+ {
+ W[j ] = sigma(W[j- 2], 17, 19, 10) + W[j-7] +
+ sigma(W[j-15], 7, 18, 3) + W[j-16];
+ W[j+1] = sigma(W[j- 1], 17, 19, 10) + W[j-6] +
+ sigma(W[j-14], 7, 18, 3) + W[j-15];
+ W[j+2] = sigma(W[j ], 17, 19, 10) + W[j-5] +
+ sigma(W[j-13], 7, 18, 3) + W[j-14];
+ W[j+3] = sigma(W[j+ 1], 17, 19, 10) + W[j-4] +
+ sigma(W[j-12], 7, 18, 3) + W[j-13];
+ W[j+4] = sigma(W[j+ 2], 17, 19, 10) + W[j-3] +
+ sigma(W[j-11], 7, 18, 3) + W[j-12];
+ W[j+5] = sigma(W[j+ 3], 17, 19, 10) + W[j-2] +
+ sigma(W[j-10], 7, 18, 3) + W[j-11];
+ W[j+6] = sigma(W[j+ 4], 17, 19, 10) + W[j-1] +
+ sigma(W[j- 9], 7, 18, 3) + W[j-10];
+ W[j+7] = sigma(W[j+ 5], 17, 19, 10) + W[j ] +
+ sigma(W[j- 8], 7, 18, 3) + W[j- 9];
+ }
F1(A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98);
F1(H, A, B, C, D, E, F, G, W[ 1], 0x71374491);
@@ -137,6 +151,8 @@ void SHA_224_256_BASE::compress_n(const byte input[], u32bit blocks)
F = (digest[5] += F);
G = (digest[6] += G);
H = (digest[7] += H);
+
+ input += HASH_BLOCK_SIZE;
}
}
@@ -152,7 +168,7 @@ void SHA_224_256_BASE::copy_out(byte output[])
/*
* Clear memory of sensitive data
*/
-void SHA_224_256_BASE::clear() throw()
+void SHA_224_256_BASE::clear()
{
MDx_HashFunction::clear();
W.clear();
@@ -161,23 +177,23 @@ void SHA_224_256_BASE::clear() throw()
/*
* Clear memory of sensitive data
*/
-void SHA_224::clear() throw()
+void SHA_224::clear()
{
SHA_224_256_BASE::clear();
- digest[0] = 0xc1059ed8;
- digest[1] = 0x367cd507;
- digest[2] = 0x3070dd17;
- digest[3] = 0xf70e5939;
- digest[4] = 0xffc00b31;
+ digest[0] = 0xC1059ED8;
+ digest[1] = 0x367CD507;
+ digest[2] = 0x3070DD17;
+ digest[3] = 0xF70E5939;
+ digest[4] = 0xFFC00B31;
digest[5] = 0x68581511;
- digest[6] = 0x64f98fa7;
- digest[7] = 0xbefa4fa4;
+ digest[6] = 0x64F98FA7;
+ digest[7] = 0xBEFA4FA4;
}
/*
* Clear memory of sensitive data
*/
-void SHA_256::clear() throw()
+void SHA_256::clear()
{
SHA_224_256_BASE::clear();
digest[0] = 0x6A09E667;
diff --git a/src/hash/sha2/sha2_32.h b/src/hash/sha2/sha2_32.h
index 05083d19d..313eec676 100644
--- a/src/hash/sha2/sha2_32.h
+++ b/src/hash/sha2/sha2_32.h
@@ -19,7 +19,7 @@ namespace Botan {
class BOTAN_DLL SHA_224_256_BASE : public MDx_HashFunction
{
protected:
- void clear() throw();
+ void clear();
SHA_224_256_BASE(u32bit out) :
MDx_HashFunction(out, 64, true, true) { clear(); }
@@ -36,7 +36,7 @@ class BOTAN_DLL SHA_224_256_BASE : public MDx_HashFunction
class BOTAN_DLL SHA_224 : public SHA_224_256_BASE
{
public:
- void clear() throw();
+ void clear();
std::string name() const { return "SHA-224"; }
HashFunction* clone() const { return new SHA_224; }
SHA_224() : SHA_224_256_BASE(28) { clear(); }
@@ -48,7 +48,7 @@ class BOTAN_DLL SHA_224 : public SHA_224_256_BASE
class BOTAN_DLL SHA_256 : public SHA_224_256_BASE
{
public:
- void clear() throw();
+ void clear();
std::string name() const { return "SHA-256"; }
HashFunction* clone() const { return new SHA_256; }
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 e9b4c2e5a..3e7c0e228 100644
--- a/src/hash/sha2/sha2_64.cpp
+++ b/src/hash/sha2/sha2_64.cpp
@@ -55,13 +55,19 @@ void SHA_384_512_BASE::compress_n(const byte input[], u32bit blocks)
for(u32bit i = 0; i != blocks; ++i)
{
- for(u32bit j = 0; j != 16; ++j)
- W[j] = load_be<u64bit>(input, j);
- input += HASH_BLOCK_SIZE;
-
- for(u32bit j = 16; j != 80; ++j)
- W[j] = sigma(W[j- 2], 19, 61, 6) + W[j- 7] +
- sigma(W[j-15], 1, 8, 7) + W[j-16];
+ load_be(W.begin(), input, 16);
+
+ for(u32bit j = 16; j != 80; j += 8)
+ {
+ W[j ] = sigma(W[j-2], 19, 61, 6) + W[j-7] + sigma(W[j-15], 1, 8, 7) + W[j-16];
+ W[j+1] = sigma(W[j-1], 19, 61, 6) + W[j-6] + sigma(W[j-14], 1, 8, 7) + W[j-15];
+ W[j+2] = sigma(W[j ], 19, 61, 6) + W[j-5] + sigma(W[j-13], 1, 8, 7) + W[j-14];
+ W[j+3] = sigma(W[j+1], 19, 61, 6) + W[j-4] + sigma(W[j-12], 1, 8, 7) + W[j-13];
+ W[j+4] = sigma(W[j+2], 19, 61, 6) + W[j-3] + sigma(W[j-11], 1, 8, 7) + W[j-12];
+ W[j+5] = sigma(W[j+3], 19, 61, 6) + W[j-2] + sigma(W[j-10], 1, 8, 7) + W[j-11];
+ W[j+6] = sigma(W[j+4], 19, 61, 6) + W[j-1] + sigma(W[j- 9], 1, 8, 7) + W[j-10];
+ W[j+7] = sigma(W[j+5], 19, 61, 6) + W[j ] + sigma(W[j- 8], 1, 8, 7) + W[j- 9];
+ }
F1(A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98D728AE22);
F1(H, A, B, C, D, E, F, G, W[ 1], 0x7137449123EF65CD);
@@ -152,6 +158,8 @@ void SHA_384_512_BASE::compress_n(const byte input[], u32bit blocks)
F = (digest[5] += F);
G = (digest[6] += G);
H = (digest[7] += H);
+
+ input += HASH_BLOCK_SIZE;
}
}
@@ -167,7 +175,7 @@ void SHA_384_512_BASE::copy_out(byte output[])
/*
* Clear memory of sensitive data
*/
-void SHA_384_512_BASE::clear() throw()
+void SHA_384_512_BASE::clear()
{
MDx_HashFunction::clear();
W.clear();
@@ -176,7 +184,7 @@ void SHA_384_512_BASE::clear() throw()
/*
* Clear memory of sensitive data
*/
-void SHA_384::clear() throw()
+void SHA_384::clear()
{
SHA_384_512_BASE::clear();
digest[0] = 0xCBBB9D5DC1059ED8;
@@ -192,7 +200,7 @@ void SHA_384::clear() throw()
/*
* Clear memory of sensitive data
*/
-void SHA_512::clear() throw()
+void SHA_512::clear()
{
SHA_384_512_BASE::clear();
digest[0] = 0x6A09E667F3BCC908;
diff --git a/src/hash/sha2/sha2_64.h b/src/hash/sha2/sha2_64.h
index dcc6dc83b..8e4d171f8 100644
--- a/src/hash/sha2/sha2_64.h
+++ b/src/hash/sha2/sha2_64.h
@@ -18,7 +18,7 @@ namespace Botan {
class BOTAN_DLL SHA_384_512_BASE : public MDx_HashFunction
{
protected:
- void clear() throw();
+ void clear();
SHA_384_512_BASE(u32bit out) :
MDx_HashFunction(out, 128, true, true, 16) {}
@@ -37,7 +37,7 @@ class BOTAN_DLL SHA_384_512_BASE : public MDx_HashFunction
class BOTAN_DLL SHA_384 : public SHA_384_512_BASE
{
public:
- void clear() throw();
+ void clear();
std::string name() const { return "SHA-384"; }
HashFunction* clone() const { return new SHA_384; }
SHA_384() : SHA_384_512_BASE(48) { clear(); }
@@ -49,7 +49,7 @@ class BOTAN_DLL SHA_384 : public SHA_384_512_BASE
class BOTAN_DLL SHA_512 : public SHA_384_512_BASE
{
public:
- void clear() throw();
+ void clear();
std::string name() const { return "SHA-512"; }
HashFunction* clone() const { return new SHA_512; }
SHA_512() : SHA_384_512_BASE(64) { clear(); }