hc
2023-11-20 520ec20d74dfd87f62fd58b921b7209d6daed94a
u-boot/lib/sha1.c
....@@ -26,6 +26,15 @@
2626 #include <watchdog.h>
2727 #include <u-boot/sha1.h>
2828
29
+#include <linux/compiler.h>
30
+
31
+#ifdef USE_HOSTCC
32
+#undef __weak
33
+#define __weak
34
+#undef __maybe_unused
35
+#define __maybe_unused
36
+#endif
37
+
2938 const uint8_t sha1_der_prefix[SHA1_DER_LEN] = {
3039 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e,
3140 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14
....@@ -66,7 +75,7 @@
6675 ctx->state[4] = 0xC3D2E1F0;
6776 }
6877
69
-static void sha1_process(sha1_context *ctx, const unsigned char data[64])
78
+static void __maybe_unused sha1_process_one(sha1_context *ctx, const unsigned char data[64])
7079 {
7180 unsigned long temp, W[16], A, B, C, D, E;
7281
....@@ -220,6 +229,18 @@
220229 ctx->state[4] += E;
221230 }
222231
232
+__weak void sha1_process(sha1_context *ctx, const unsigned char *data,
233
+ unsigned int blocks)
234
+{
235
+ if (!blocks)
236
+ return;
237
+
238
+ while (blocks--) {
239
+ sha1_process_one(ctx, data);
240
+ data += 64;
241
+ }
242
+}
243
+
223244 /*
224245 * SHA-1 process buffer
225246 */
....@@ -243,17 +264,15 @@
243264
244265 if (left && ilen >= fill) {
245266 memcpy ((void *) (ctx->buffer + left), (void *) input, fill);
246
- sha1_process (ctx, ctx->buffer);
267
+ sha1_process(ctx, ctx->buffer, 1);
247268 input += fill;
248269 ilen -= fill;
249270 left = 0;
250271 }
251272
252
- while (ilen >= 64) {
253
- sha1_process (ctx, input);
254
- input += 64;
255
- ilen -= 64;
256
- }
273
+ sha1_process(ctx, input, ilen / 64);
274
+ input += ilen / 64 * 64;
275
+ ilen = ilen % 64;
257276
258277 if (ilen > 0) {
259278 memcpy ((void *) (ctx->buffer + left), (void *) input, ilen);