MCPcopy Create free account
hub / github.com/ddnet/ddnet / sha_compress

Function sha_compress

src/base/hash_libtomcrypt.cpp:64–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62static u32 Gamma1(u32 x) { return Rot(x, 17) ^ Rot(x, 19) ^ Sh(x, 10); }
63
64static void sha_compress(sha256_state *md, const unsigned char *buf)
65{
66 u32 S[8], W[64], t;
67 int i;
68
69 // Copy state into S
70 for(i = 0; i < 8; i++)
71 S[i] = md->state[i];
72
73 // Copy the state into 512-bits into W[0..15]
74 for(i = 0; i < 16; i++)
75 W[i] = load32(buf + (4 * i));
76
77 // Fill W[16..63]
78 for(i = 16; i < 64; i++)
79 W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
80
81// Compress
82#define RND(a, b, c, d, e, f, g, h, i) \
83 do \
84 { \
85 u32 t0 = (h) + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
86 u32 t1 = Sigma0(a) + Maj(a, b, c); \
87 (d) += t0; \
88 (h) = t0 + t1; \
89 } while(0)
90
91 for(i = 0; i < 64; ++i)
92 {
93 RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
94 t = S[7];
95 S[7] = S[6];
96 S[6] = S[5];
97 S[5] = S[4];
98 S[4] = S[3];
99 S[3] = S[2];
100 S[2] = S[1];
101 S[1] = S[0];
102 S[0] = t;
103 }
104
105 // Feedback
106 for(i = 0; i < 8; i++)
107 md->state[i] = md->state[i] + S[i];
108}
109
110// Public interface
111

Callers 2

sha_processFunction · 0.85
sha_doneFunction · 0.85

Calls 3

load32Function · 0.85
Gamma1Function · 0.85
Gamma0Function · 0.85

Tested by

no test coverage detected