Add an array of bytes to be consumed by an ongoing SHA-256 evaluation. * Returns false if the counter overflows. * * Precondition: NULL != ctx; * if 0 < len then unsigned char arr[len]; */
| 221 | * if 0 < len then unsigned char arr[len]; |
| 222 | */ |
| 223 | static inline bool sha256_uchars(sha256_context* ctx, const unsigned char* arr, size_t len) { |
| 224 | size_t delta = 64 - ctx->counter % 64; |
| 225 | unsigned char *block = ctx->block + ctx->counter % 64; |
| 226 | ctx->overflow = ctx->overflow || sha256_max_counter - ctx->counter <= len; |
| 227 | ctx->counter += len; |
| 228 | |
| 229 | while (delta <= len) { |
| 230 | memcpy(block, arr, delta); |
| 231 | arr += delta; |
| 232 | len -= delta; |
| 233 | sha256_compression_uchar(ctx->output, ctx->block); |
| 234 | block = ctx->block; |
| 235 | delta = 64; |
| 236 | } |
| 237 | |
| 238 | if (len) memcpy(block, arr, len); |
| 239 | return !ctx->overflow; |
| 240 | } |
| 241 | |
| 242 | /* Add one byte to be consumed by an ongoing SHA-256 evaluation. |
| 243 | * |
no test coverage detected