summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Poulain <loic.poulain@linaro.org>2022-06-01 20:26:27 +0200
committerJianhong Chen <chenjh@rock-chips.com>2023-05-17 10:47:31 +0800
commit87e494a1b4b10b2144fb1d62f0a848caabcfb69b (patch)
tree666c7e012c9eb3327417eb29c9eb8e4c87993aa5
parentfbc03ba7beeb1620e5ccb689f2f51a2e08f1c180 (diff)
UPSTREAM: lib: sha1: Add support for hardware specific sha1_process
Mark sha1_process as weak to allow hardware specific implementation. Add parameter to support for multiple blocks processing. Signed-off-by: Loic Poulain <loic.poulain@linaro.org> Signed-off-by: Joseph Chen <chenjh@rock-chips.com> Change-Id: Ie845aea4a7610e4e7c11b3f6f48aa49bf7efdab4 (cherry picked from commit 8201b8066a898c1ae72af45dbda8950410ee4743)
-rw-r--r--lib/sha1.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/sha1.c b/lib/sha1.c
index f54bb5be98..399607a2f3 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -26,6 +26,15 @@
#include <watchdog.h>
#include <u-boot/sha1.h>
+#include <linux/compiler.h>
+
+#ifdef USE_HOSTCC
+#undef __weak
+#define __weak
+#undef __maybe_unused
+#define __maybe_unused
+#endif
+
const uint8_t sha1_der_prefix[SHA1_DER_LEN] = {
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e,
0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14
@@ -66,7 +75,7 @@ void sha1_starts (sha1_context * ctx)
ctx->state[4] = 0xC3D2E1F0;
}
-static void sha1_process(sha1_context *ctx, const unsigned char data[64])
+static void __maybe_unused sha1_process_one(sha1_context *ctx, const unsigned char data[64])
{
unsigned long temp, W[16], A, B, C, D, E;
@@ -220,6 +229,18 @@ static void sha1_process(sha1_context *ctx, const unsigned char data[64])
ctx->state[4] += E;
}
+__weak void sha1_process(sha1_context *ctx, const unsigned char *data,
+ unsigned int blocks)
+{
+ if (!blocks)
+ return;
+
+ while (blocks--) {
+ sha1_process_one(ctx, data);
+ data += 64;
+ }
+}
+
/*
* SHA-1 process buffer
*/
@@ -243,17 +264,15 @@ void sha1_update(sha1_context *ctx, const unsigned char *input,
if (left && ilen >= fill) {
memcpy ((void *) (ctx->buffer + left), (void *) input, fill);
- sha1_process (ctx, ctx->buffer);
+ sha1_process(ctx, ctx->buffer, 1);
input += fill;
ilen -= fill;
left = 0;
}
- while (ilen >= 64) {
- sha1_process (ctx, input);
- input += 64;
- ilen -= 64;
- }
+ sha1_process(ctx, input, ilen / 64);
+ input += ilen / 64 * 64;
+ ilen = ilen % 64;
if (ilen > 0) {
memcpy ((void *) (ctx->buffer + left), (void *) input, ilen);