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

Function sha_done

src/base/hash_libtomcrypt.cpp:158–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158static void sha_done(sha256_state *md, void *out)
159{
160 int i;
161
162 // Increase the length of the message
163 md->length += md->curlen * 8;
164
165 // Append the '1' bit
166 md->buf[md->curlen++] = (unsigned char)0x80;
167
168 // If the length is currently above 56 bytes we append zeros then compress.
169 // Then we can fall back to padding zeros and length encoding like normal.
170 if(md->curlen > 56)
171 {
172 while(md->curlen < 64)
173 md->buf[md->curlen++] = 0;
174 sha_compress(md, md->buf);
175 md->curlen = 0;
176 }
177
178 // Pad up to 56 bytes of zeroes
179 while(md->curlen < 56)
180 md->buf[md->curlen++] = 0;
181
182 // Store length
183 store64(md->length, md->buf + 56);
184 sha_compress(md, md->buf);
185
186 // Copy output
187 for(i = 0; i < 8; i++)
188 store32(md->state[i], (unsigned char *)out + (4 * i));
189}
190
191void sha256_init(SHA256_CTX *ctxt)
192{

Callers 1

sha256_finishFunction · 0.85

Calls 3

sha_compressFunction · 0.85
store64Function · 0.85
store32Function · 0.85

Tested by

no test coverage detected