MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / Transform

Method Transform

LibLemon/src/sha.cpp:12–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12void SHA256::Transform(const uint8_t* data){
13 uint32_t w[64];
14
15 for(int i = 0; i < 16; i++){
16 w[i] = __builtin_bswap32(reinterpret_cast<const uint32_t*>(data)[i]); // data is big endian so convert to little endian
17 } // Copy chunk (512 bits/64 bytes) into first 16 bytes of w
18
19 for(int i = 16; i < 64; i++){
20 uint32_t s0 = rotateRight<uint32_t>(w[i - 15], 7) ^ rotateRight<uint32_t>(w[i - 15], 18) ^ (w[i - 15] >> 3);
21 uint32_t s1 = rotateRight<uint32_t>(w[i - 2], 17) ^ rotateRight<uint32_t>(w[i - 2], 19) ^ (w[i - 2] >> 10);
22
23 w[i] = w[i - 16] + s0 + w[i - 7] + s1;
24 }
25
26 uint32_t t[8];
27 for(int i = 0; i < 8; i++){
28 t[i] = hash[i];
29 }
30
31 for(int i = 0; i < 64; i++){
32 uint32_t s1 = rotateRight<uint32_t>(t[4], 6) ^ rotateRight<uint32_t>(t[4], 11) ^ rotateRight<uint32_t>(t[4], 25);
33 uint32_t s0 = rotateRight<uint32_t>(t[0], 2) ^ rotateRight<uint32_t>(t[0], 13) ^ rotateRight<uint32_t>(t[0], 22);
34 uint32_t temp1 = t[7] + s1 + SHA2_CHOOSE(t[4], t[5], t[6]) + constants[i] + w[i];
35 uint32_t temp2 = s0 + SHA2_MAJOR(t[0], t[1], t[2]);
36
37 t[7] = t[6];
38 t[6] = t[5];
39 t[5] = t[4];
40 t[4] = t[3] + temp1;
41 t[3] = t[2];
42 t[2] = t[1];
43 t[1] = t[0];
44 t[0] = temp1 + temp2;
45 }
46
47 for(unsigned i = 0; i < SHA256_HASH_SIZE / sizeof(uint32_t); i++){
48 hash[i] += t[i];
49 }
50}
51
52void SHA256::Update(const void* _data, size_t count){
53 const uint8_t* data = static_cast<const uint8_t*>(_data);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected