EHS
SHA256.h
Go to the documentation of this file.
1#pragma once
2#include "Types.h"
3
4namespace ehs
5{
6 class SHA256
7 {
8 private:
9 static UInt_32 ROTR(UInt_32 x, UInt_32 n);
10
11 static UInt_32 CH(UInt_32 x, UInt_32 y, UInt_32 z);
12
13 static UInt_32 MAJ(UInt_32 x, UInt_32 y, UInt_32 z);
14
15 static UInt_32 EP0(UInt_32 x);
16
17 static UInt_32 EP1(UInt_32 x);
18
19 static UInt_32 SIG0(UInt_32 x);
20
21 static UInt_32 SIG1(UInt_32 x);
22
23 static constexpr UInt_32 k[64] = {
24 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
25 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
26 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
27 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
28 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
29 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
30 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
31 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
32 };
33
34 UInt_32 state[8];
35 UInt_64 bitLen;
36 Byte data[64];
37 UInt_64 dataLen;
38
39 public:
40 SHA256();
41
42 SHA256(SHA256 &&other) noexcept;
43
44 SHA256(const SHA256 &other);
45
46 SHA256 &operator=(SHA256 &&other) noexcept;
47
48 SHA256 &operator=(const SHA256 &other);
49
50 void Update(const Byte *data, UInt_64 len);
51
52 void Final(Byte hash[32]);
53
54 void Hash(const Byte *data, UInt_64 len, Byte hash[32]);
55
56 private:
57 void Transform(const Byte data[64]);
58 };
59}
Definition: SHA256.h:7
void Hash(const Byte *data, UInt_64 len, Byte hash[32])
Definition: SHA256.cpp:161
void Final(Byte hash[32])
Definition: SHA256.cpp:117
SHA256()
Definition: SHA256.cpp:42
void Update(const Byte *data, UInt_64 len)
Definition: SHA256.cpp:102
SHA256 & operator=(SHA256 &&other) noexcept
Definition: SHA256.cpp:71
Definition: Anchor.h:6
unsigned int UInt_32
Definition: Types.h:49
unsigned char Byte
Definition: Types.h:39