Add bytes into the hash */
| 245 | |
| 246 | /* Add bytes into the hash */ |
| 247 | void |
| 248 | SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) |
| 249 | { |
| 250 | uint64_t bitlen; |
| 251 | uint32_t r; |
| 252 | const unsigned char *src = in; |
| 253 | |
| 254 | /* Number of bytes left in the buffer from previous updates */ |
| 255 | r = (ctx->count >> 3) & 0x3f; |
| 256 | |
| 257 | /* Convert the length into a number of bits */ |
| 258 | bitlen = len << 3; |
| 259 | |
| 260 | /* Update number of bits */ |
| 261 | ctx->count += bitlen; |
| 262 | |
| 263 | /* Handle the case where we don't need to perform any transforms */ |
| 264 | if (len < 64 - r) { |
| 265 | memcpy(&ctx->buf[r], src, len); |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | /* Finish the current block */ |
| 270 | memcpy(&ctx->buf[r], src, 64 - r); |
| 271 | SHA256_Transform(ctx->state, ctx->buf); |
| 272 | src += 64 - r; |
| 273 | len -= 64 - r; |
| 274 | |
| 275 | /* Perform complete blocks */ |
| 276 | while (len >= 64) { |
| 277 | SHA256_Transform(ctx->state, src); |
| 278 | src += 64; |
| 279 | len -= 64; |
| 280 | } |
| 281 | |
| 282 | /* Copy left over data into buffer */ |
| 283 | memcpy(ctx->buf, src, len); |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * SHA-256 finalization. Pads the input data, exports the hash value, |
no test coverage detected