MCPcopy Create free account
hub / github.com/F-Stack/f-stack / SHA512_Update

Function SHA512_Update

freebsd/crypto/sha2/sha512c.c:277–317  ·  view source on GitHub ↗

Add bytes into the hash */

Source from the content-addressed store, hash-verified

275
276/* Add bytes into the hash */
277void
278SHA512_Update(SHA512_CTX * ctx, const void *in, size_t len)
279{
280 uint64_t bitlen[2];
281 uint64_t r;
282 const unsigned char *src = in;
283
284 /* Number of bytes left in the buffer from previous updates */
285 r = (ctx->count[1] >> 3) & 0x7f;
286
287 /* Convert the length into a number of bits */
288 bitlen[1] = ((uint64_t)len) << 3;
289 bitlen[0] = ((uint64_t)len) >> 61;
290
291 /* Update number of bits */
292 if ((ctx->count[1] += bitlen[1]) < bitlen[1])
293 ctx->count[0]++;
294 ctx->count[0] += bitlen[0];
295
296 /* Handle the case where we don't need to perform any transforms */
297 if (len < SHA512_BLOCK_LENGTH - r) {
298 memcpy(&ctx->buf[r], src, len);
299 return;
300 }
301
302 /* Finish the current block */
303 memcpy(&ctx->buf[r], src, SHA512_BLOCK_LENGTH - r);
304 SHA512_Transform(ctx->state, ctx->buf);
305 src += SHA512_BLOCK_LENGTH - r;
306 len -= SHA512_BLOCK_LENGTH - r;
307
308 /* Perform complete blocks */
309 while (len >= SHA512_BLOCK_LENGTH) {
310 SHA512_Transform(ctx->state, src);
311 src += SHA512_BLOCK_LENGTH;
312 len -= SHA512_BLOCK_LENGTH;
313 }
314
315 /* Copy left over data into buffer */
316 memcpy(ctx->buf, src, len);
317}
318
319/*
320 * SHA-512 finalization. Pads the input data, exports the hash value,

Callers 4

SHA512_224_UpdateFunction · 0.70
SHA512_256_UpdateFunction · 0.70
SHA384_UpdateFunction · 0.70
SHA512Update_intFunction · 0.50

Calls 2

SHA512_TransformFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected