1 #ifndef MSP_CRYPTO_SHA2_H_
2 #define MSP_CRYPTO_SHA2_H_
4 #include <msp/core/inttypes.h>
11 class SHA2: public BlockHash<C::BLOCK_SIZE>
15 typedef typename Constants::WordType WordType;
17 typename Constants::WordType buffer[8];
18 UInt64 processed_bytes;
22 SHA2(const char *, unsigned);
23 SHA2(const std::string &);
28 virtual unsigned get_digest_size() const { return Constants::DIGEST_SIZE; }
30 virtual unsigned get_digest(char *, unsigned) const;
33 virtual void process_block(const char *);
37 struct SHA2_256Constants
39 typedef UInt32 WordType;
43 WORD_SIZE = sizeof(WordType),
44 BLOCK_SIZE = 64, // 512 bits
45 DIGEST_SIZE = 32, // 256 bits
50 static const WordType initial[8];
51 static const WordType round_constants[N_ROUNDS];
52 static const unsigned sigma_constants[12];
55 struct SHA2_512Constants
57 typedef UInt64 WordType;
61 WORD_SIZE = sizeof(WordType),
62 BLOCK_SIZE = 128, // 1024 bits
63 DIGEST_SIZE = 64, // 512 bits
68 static const WordType initial[8];
69 static const WordType round_constants[N_ROUNDS];
70 static const unsigned sigma_constants[12];
73 typedef SHA2<SHA2_256Constants> SHA256;
74 typedef SHA2<SHA2_512Constants> SHA512;