hc
2023-11-07 f45e756958099c35d6afb746df1d40a1c6302cfc
u-boot/lib/sha256.c
....@@ -15,6 +15,13 @@
1515 #include <watchdog.h>
1616 #include <u-boot/sha256.h>
1717
18
+#include <linux/compiler.h>
19
+
20
+#ifdef USE_HOSTCC
21
+#undef __weak
22
+#define __weak
23
+#endif
24
+
1825 const uint8_t sha256_der_prefix[SHA256_DER_LEN] = {
1926 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
2027 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
....@@ -56,7 +63,7 @@
5663 ctx->state[7] = 0x5BE0CD19;
5764 }
5865
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])
6067 {
6168 uint32_t temp1, temp2;
6269 uint32_t W[64];
....@@ -187,6 +194,18 @@
187194 ctx->state[7] += H;
188195 }
189196
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
+
190209 void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)
191210 {
192211 uint32_t left, fill;
....@@ -205,17 +224,15 @@
205224
206225 if (left && length >= fill) {
207226 memcpy((void *) (ctx->buffer + left), (void *) input, fill);
208
- sha256_process(ctx, ctx->buffer);
227
+ sha256_process(ctx, ctx->buffer, 1);
209228 length -= fill;
210229 input += fill;
211230 left = 0;
212231 }
213232
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;
219236
220237 if (length)
221238 memcpy((void *) (ctx->buffer + left), (void *) input, length);