| .. | .. |
|---|
| 15 | 15 | #include <watchdog.h> |
|---|
| 16 | 16 | #include <u-boot/sha256.h> |
|---|
| 17 | 17 | |
|---|
| 18 | +#include <linux/compiler.h> |
|---|
| 19 | + |
|---|
| 20 | +#ifdef USE_HOSTCC |
|---|
| 21 | +#undef __weak |
|---|
| 22 | +#define __weak |
|---|
| 23 | +#endif |
|---|
| 24 | + |
|---|
| 18 | 25 | const uint8_t sha256_der_prefix[SHA256_DER_LEN] = { |
|---|
| 19 | 26 | 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, |
|---|
| 20 | 27 | 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, |
|---|
| .. | .. |
|---|
| 56 | 63 | ctx->state[7] = 0x5BE0CD19; |
|---|
| 57 | 64 | } |
|---|
| 58 | 65 | |
|---|
| 59 | | -static void sha256_process(sha256_context *ctx, const uint8_t data[64]) |
|---|
| 66 | +static void sha256_process_one(sha256_context *ctx, const uint8_t data[64]) |
|---|
| 60 | 67 | { |
|---|
| 61 | 68 | uint32_t temp1, temp2; |
|---|
| 62 | 69 | uint32_t W[64]; |
|---|
| .. | .. |
|---|
| 187 | 194 | ctx->state[7] += H; |
|---|
| 188 | 195 | } |
|---|
| 189 | 196 | |
|---|
| 197 | +__weak void sha256_process(sha256_context *ctx, const unsigned char *data, |
|---|
| 198 | + unsigned int blocks) |
|---|
| 199 | +{ |
|---|
| 200 | + if (!blocks) |
|---|
| 201 | + return; |
|---|
| 202 | + |
|---|
| 203 | + while (blocks--) { |
|---|
| 204 | + sha256_process_one(ctx, data); |
|---|
| 205 | + data += 64; |
|---|
| 206 | + } |
|---|
| 207 | +} |
|---|
| 208 | + |
|---|
| 190 | 209 | void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length) |
|---|
| 191 | 210 | { |
|---|
| 192 | 211 | uint32_t left, fill; |
|---|
| .. | .. |
|---|
| 205 | 224 | |
|---|
| 206 | 225 | if (left && length >= fill) { |
|---|
| 207 | 226 | memcpy((void *) (ctx->buffer + left), (void *) input, fill); |
|---|
| 208 | | - sha256_process(ctx, ctx->buffer); |
|---|
| 227 | + sha256_process(ctx, ctx->buffer, 1); |
|---|
| 209 | 228 | length -= fill; |
|---|
| 210 | 229 | input += fill; |
|---|
| 211 | 230 | left = 0; |
|---|
| 212 | 231 | } |
|---|
| 213 | 232 | |
|---|
| 214 | | - while (length >= 64) { |
|---|
| 215 | | - sha256_process(ctx, input); |
|---|
| 216 | | - length -= 64; |
|---|
| 217 | | - input += 64; |
|---|
| 218 | | - } |
|---|
| 233 | + sha256_process(ctx, input, length / 64); |
|---|
| 234 | + input += length / 64 * 64; |
|---|
| 235 | + length = length % 64; |
|---|
| 219 | 236 | |
|---|
| 220 | 237 | if (length) |
|---|
| 221 | 238 | memcpy((void *) (ctx->buffer + left), (void *) input, length); |
|---|