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

Function cbm_sha256_final

src/foundation/sha256.c:88–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void cbm_sha256_final(cbm_sha256_ctx *c, uint8_t out[CBM_SHA256_DIGEST_LEN]) {
89 c->bitlen += (uint64_t)c->buflen * 8;
90
91 size_t i = c->buflen;
92 c->buf[i++] = 0x80; /* append the '1' bit + zero padding */
93 if (i > 56) {
94 while (i < 64) {
95 c->buf[i++] = 0;
96 }
97 sha256_transform(c, c->buf);
98 i = 0;
99 }
100 while (i < 56) {
101 c->buf[i++] = 0;
102 }
103 /* append the 64-bit big-endian message length */
104 for (int j = 0; j < 8; j++) {
105 c->buf[56 + j] = (uint8_t)(c->bitlen >> (56 - 8 * j));
106 }
107 sha256_transform(c, c->buf);
108
109 for (int j = 0; j < 8; j++) {
110 out[j * 4] = (uint8_t)(c->state[j] >> 24);
111 out[j * 4 + 1] = (uint8_t)(c->state[j] >> 16);
112 out[j * 4 + 2] = (uint8_t)(c->state[j] >> 8);
113 out[j * 4 + 3] = (uint8_t)(c->state[j]);
114 }
115}
116
117void cbm_sha256_hex(const void *data, size_t len, char out[CBM_SHA256_HEX_LEN + 1]) {
118 uint8_t digest[CBM_SHA256_DIGEST_LEN];

Calls 1

sha256_transformFunction · 0.85

Tested by

no test coverage detected