MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sha256_transform

Function sha256_transform

src/foundation/sha256.c:69–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67#define SIG1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ ((x) >> 10))
68
69static void sha256_transform(cbm_sha256_ctx *c, const uint8_t *data) {
70 /* Scratch comes from the context, not this frame: a 256-byte local here
71 * is fake-stacked by ASan's use-after-return mode on every 64-byte block
72 * (see the note on cbm_sha256_ctx::sched). Identical values, allocated
73 * once per hash instead of once per block. */
74 uint32_t *m = c->sched;
75 for (int i = 0, j = 0; i < 16; i++, j += 4) {
76 m[i] = ((uint32_t)data[j] << 24) | ((uint32_t)data[j + 1] << 16) |
77 ((uint32_t)data[j + 2] << 8) | (uint32_t)data[j + 3];
78 }
79 for (int i = 16; i < 64; i++) {
80 m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
81 }
82
83 uint32_t a = c->state[0], b = c->state[1], cc = c->state[2], d = c->state[3];
84 uint32_t e = c->state[4], f = c->state[5], g = c->state[6], h = c->state[7];
85
86 for (int i = 0; i < 64; i++) {
87 uint32_t t1 = h + EP1(e) + CH(e, f, g) + K[i] + m[i];
88 uint32_t t2 = EP0(a) + MAJ(a, b, cc);
89 h = g;
90 g = f;
91 f = e;
92 e = d + t1;
93 d = cc;
94 cc = b;
95 b = a;
96 a = t1 + t2;
97 }
98
99 c->state[0] += a;
100 c->state[1] += b;
101 c->state[2] += cc;
102 c->state[3] += d;
103 c->state[4] += e;
104 c->state[5] += f;
105 c->state[6] += g;
106 c->state[7] += h;
107}
108
109static void sha256_blocks_portable(cbm_sha256_ctx *c, const uint8_t *data, size_t blocks) {
110 for (; blocks > 0; blocks--, data += SHA256_BLOCK_BYTES) {

Callers 1

sha256_blocks_portableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected