Add padding and terminating bit-count. */
| 197 | |
| 198 | /* Add padding and terminating bit-count. */ |
| 199 | static void |
| 200 | SHA256_Pad(SHA256_CTX * ctx) |
| 201 | { |
| 202 | size_t r; |
| 203 | |
| 204 | /* Figure out how many bytes we have buffered. */ |
| 205 | r = (ctx->count >> 3) & 0x3f; |
| 206 | |
| 207 | /* Pad to 56 mod 64, transforming if we finish a block en route. */ |
| 208 | if (r < 56) { |
| 209 | /* Pad to 56 mod 64. */ |
| 210 | memcpy(&ctx->buf[r], PAD, 56 - r); |
| 211 | } else { |
| 212 | /* Finish the current block and mix. */ |
| 213 | memcpy(&ctx->buf[r], PAD, 64 - r); |
| 214 | SHA256_Transform(ctx->state, ctx->buf); |
| 215 | |
| 216 | /* The start of the final block is all zeroes. */ |
| 217 | memset(&ctx->buf[0], 0, 56); |
| 218 | } |
| 219 | |
| 220 | /* Add the terminating bit-count. */ |
| 221 | be64enc(&ctx->buf[56], ctx->count); |
| 222 | |
| 223 | /* Mix in the final block. */ |
| 224 | SHA256_Transform(ctx->state, ctx->buf); |
| 225 | } |
| 226 | |
| 227 | /* SHA-256 initialization. Begins a SHA-256 operation. */ |
| 228 | void |
no test coverage detected