mirror of
https://github.com/u-boot/u-boot.git
synced 2024-11-23 20:24:26 +08:00
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>
This commit is contained in:
parent
c316ee674f
commit
8201b8066a
26
lib/sha1.c
26
lib/sha1.c
@ -25,6 +25,8 @@
|
|||||||
#include <watchdog.h>
|
#include <watchdog.h>
|
||||||
#include <u-boot/sha1.h>
|
#include <u-boot/sha1.h>
|
||||||
|
|
||||||
|
#include <linux/compiler_attributes.h>
|
||||||
|
|
||||||
const uint8_t sha1_der_prefix[SHA1_DER_LEN] = {
|
const uint8_t sha1_der_prefix[SHA1_DER_LEN] = {
|
||||||
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e,
|
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e,
|
||||||
0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14
|
0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14
|
||||||
@ -65,7 +67,7 @@ void sha1_starts (sha1_context * ctx)
|
|||||||
ctx->state[4] = 0xC3D2E1F0;
|
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;
|
unsigned long temp, W[16], A, B, C, D, E;
|
||||||
|
|
||||||
@ -219,6 +221,18 @@ static void sha1_process(sha1_context *ctx, const unsigned char data[64])
|
|||||||
ctx->state[4] += E;
|
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
|
* SHA-1 process buffer
|
||||||
*/
|
*/
|
||||||
@ -242,17 +256,15 @@ void sha1_update(sha1_context *ctx, const unsigned char *input,
|
|||||||
|
|
||||||
if (left && ilen >= fill) {
|
if (left && ilen >= fill) {
|
||||||
memcpy ((void *) (ctx->buffer + left), (void *) input, fill);
|
memcpy ((void *) (ctx->buffer + left), (void *) input, fill);
|
||||||
sha1_process (ctx, ctx->buffer);
|
sha1_process(ctx, ctx->buffer, 1);
|
||||||
input += fill;
|
input += fill;
|
||||||
ilen -= fill;
|
ilen -= fill;
|
||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ilen >= 64) {
|
sha1_process(ctx, input, ilen / 64);
|
||||||
sha1_process (ctx, input);
|
input += ilen / 64 * 64;
|
||||||
input += 64;
|
ilen = ilen % 64;
|
||||||
ilen -= 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ilen > 0) {
|
if (ilen > 0) {
|
||||||
memcpy ((void *) (ctx->buffer + left), (void *) input, ilen);
|
memcpy ((void *) (ctx->buffer + left), (void *) input, ilen);
|
||||||
|
Loading…
Reference in New Issue
Block a user