This is simply the 'update' with the padding block. * The padding block is 0x01 || 0x00* || 0x80. First 0x01 and last 0x80 * bytes are always present, but they can be the same byte. */
| 305 | * bytes are always present, but they can be the same byte. |
| 306 | */ |
| 307 | static void |
| 308 | sha3_Update(void *priv, void const *bufIn, size_t len) |
| 309 | { |
| 310 | sha3_context *ctx = (sha3_context *) priv; |
| 311 | unsigned int old_tail = (8 - ctx->byteIndex) & 7; |
| 312 | size_t words; |
| 313 | unsigned int tail; |
| 314 | size_t i; |
| 315 | const uint8_t *buf = bufIn; |
| 316 | |
| 317 | if (len < old_tail) { |
| 318 | while (len--) |
| 319 | ctx->saved |= (uint64_t) (*(buf++)) << |
| 320 | ((ctx->byteIndex++) * 8); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | if (old_tail) { |
| 325 | len -= old_tail; |
| 326 | while (old_tail--) |
| 327 | ctx->saved |= (uint64_t) (*(buf++)) << |
| 328 | ((ctx->byteIndex++) * 8); |
| 329 | |
| 330 | ctx->s[ctx->wordIndex] ^= ctx->saved; |
| 331 | ctx->byteIndex = 0; |
| 332 | ctx->saved = 0; |
| 333 | if (++ctx->wordIndex == |
| 334 | (SHA3_KECCAK_SPONGE_WORDS - ctx->capacityWords)) { |
| 335 | keccakf(ctx->s); |
| 336 | ctx->wordIndex = 0; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | words = len / sizeof(uint64_t); |
| 341 | tail = len - words * sizeof(uint64_t); |
| 342 | |
| 343 | for (i = 0; i < words; i++, buf += sizeof(uint64_t)) { |
| 344 | const uint64_t t = (uint64_t) (buf[0]) | |
| 345 | ((uint64_t) (buf[1]) << 8 * 1) | |
| 346 | ((uint64_t) (buf[2]) << 8 * 2) | |
| 347 | ((uint64_t) (buf[3]) << 8 * 3) | |
| 348 | ((uint64_t) (buf[4]) << 8 * 4) | |
| 349 | ((uint64_t) (buf[5]) << 8 * 5) | |
| 350 | ((uint64_t) (buf[6]) << 8 * 6) | |
| 351 | ((uint64_t) (buf[7]) << 8 * 7); |
| 352 | ctx->s[ctx->wordIndex] ^= t; |
| 353 | if (++ctx->wordIndex == |
| 354 | (SHA3_KECCAK_SPONGE_WORDS - ctx->capacityWords)) { |
| 355 | keccakf(ctx->s); |
| 356 | ctx->wordIndex = 0; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | while (tail--) |
| 361 | ctx->saved |= (uint64_t) (*(buf++)) << ((ctx->byteIndex++) * 8); |
| 362 | } |
| 363 | |
| 364 | int partial_hash_sha3_224(uint8_t *data_in, uint8_t *data_out) |
no test coverage detected