Skip to content

Commit f77b564

Browse files
committed
optional: SHA2-224 seed values
1 parent 70cc937 commit f77b564

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sha256.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// //////////////////////////////////////////////////////////
22
// sha256.cpp
3-
// Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
3+
// Copyright (c) 2014,2015,2021 Stephan Brumme. All rights reserved.
44
// see http://create.stephan-brumme.com/disclaimer.html
55
//
66

@@ -11,6 +11,8 @@
1111
#include <endian.h>
1212
#endif
1313

14+
//#define SHA2_224_SEED_VECTOR
15+
1416

1517
/// same as reset()
1618
SHA256::SHA256()
@@ -26,6 +28,8 @@ void SHA256::reset()
2628
m_bufferSize = 0;
2729

2830
// according to RFC 1321
31+
// "These words were obtained by taking the first thirty-two bits of the
32+
// fractional parts of the square roots of the first eight prime numbers"
2933
m_hash[0] = 0x6a09e667;
3034
m_hash[1] = 0xbb67ae85;
3135
m_hash[2] = 0x3c6ef372;
@@ -34,6 +38,19 @@ void SHA256::reset()
3438
m_hash[5] = 0x9b05688c;
3539
m_hash[6] = 0x1f83d9ab;
3640
m_hash[7] = 0x5be0cd19;
41+
42+
#ifdef SHA2_224_SEED_VECTOR
43+
// if you want SHA2-224 instead then use these seeds
44+
// and throw away the last 32 bits of getHash
45+
m_hash[0] = 0xc1059ed8;
46+
m_hash[1] = 0x367cd507;
47+
m_hash[2] = 0x3070dd17;
48+
m_hash[3] = 0xf70e5939;
49+
m_hash[4] = 0xffc00b31;
50+
m_hash[5] = 0x68581511;
51+
m_hash[6] = 0x64f98fa7;
52+
m_hash[7] = 0xbefa4fa4;
53+
#endif
3754
}
3855

3956

0 commit comments

Comments
 (0)