lib: sha256: move common function to sha256_common.c
The function sha256_csum_wd is defined in lib/sha256.c and in lib/mbedtls/sha256.c. To avoid duplicating this function (and future function), we move this function to the file lib/sha256_common.c Reviewed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
This commit is contained in:
committed by
Simon Glass
parent
f299962a5a
commit
c13ac547d2
@@ -81,6 +81,7 @@ obj-$(CONFIG_BLAKE2) += blake2/blake2b.o
|
||||
|
||||
obj-$(CONFIG_$(PHASE_)MD5_LEGACY) += md5.o
|
||||
obj-$(CONFIG_$(PHASE_)SHA1_LEGACY) += sha1.o
|
||||
obj-$(CONFIG_$(PHASE_)SHA256) += sha256_common.o
|
||||
obj-$(CONFIG_$(PHASE_)SHA256_LEGACY) += sha256.o
|
||||
obj-$(CONFIG_$(PHASE_)SHA512_LEGACY) += sha512.o
|
||||
|
||||
|
||||
@@ -33,30 +33,3 @@ void sha256_finish(sha256_context *ctx, uint8_t digest[SHA256_SUM_LEN])
|
||||
mbedtls_sha256_finish(ctx, digest);
|
||||
mbedtls_sha256_free(ctx);
|
||||
}
|
||||
|
||||
void sha256_csum_wd(const unsigned char *input, unsigned int ilen,
|
||||
unsigned char *output, unsigned int chunk_sz)
|
||||
{
|
||||
sha256_context ctx;
|
||||
|
||||
sha256_starts(&ctx);
|
||||
|
||||
if (IS_ENABLED(CONFIG_HW_WATCHDOG) || IS_ENABLED(CONFIG_WATCHDOG)) {
|
||||
const unsigned char *curr = input;
|
||||
const unsigned char *end = input + ilen;
|
||||
int chunk;
|
||||
|
||||
while (curr < end) {
|
||||
chunk = end - curr;
|
||||
if (chunk > chunk_sz)
|
||||
chunk = chunk_sz;
|
||||
sha256_update(&ctx, curr, chunk);
|
||||
curr += chunk;
|
||||
schedule();
|
||||
}
|
||||
} else {
|
||||
sha256_update(&ctx, input, ilen);
|
||||
}
|
||||
|
||||
sha256_finish(&ctx, output);
|
||||
}
|
||||
|
||||
34
lib/sha256.c
34
lib/sha256.c
@@ -264,37 +264,3 @@ void sha256_finish(sha256_context * ctx, uint8_t digest[32])
|
||||
PUT_UINT32_BE(ctx->state[6], digest, 24);
|
||||
PUT_UINT32_BE(ctx->state[7], digest, 28);
|
||||
}
|
||||
|
||||
/*
|
||||
* Output = SHA-256( input buffer ). Trigger the watchdog every 'chunk_sz'
|
||||
* bytes of input processed.
|
||||
*/
|
||||
void sha256_csum_wd(const unsigned char *input, unsigned int ilen,
|
||||
unsigned char *output, unsigned int chunk_sz)
|
||||
{
|
||||
sha256_context ctx;
|
||||
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
||||
const unsigned char *end;
|
||||
unsigned char *curr;
|
||||
int chunk;
|
||||
#endif
|
||||
|
||||
sha256_starts(&ctx);
|
||||
|
||||
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
||||
curr = (unsigned char *)input;
|
||||
end = input + ilen;
|
||||
while (curr < end) {
|
||||
chunk = end - curr;
|
||||
if (chunk > chunk_sz)
|
||||
chunk = chunk_sz;
|
||||
sha256_update(&ctx, curr, chunk);
|
||||
curr += chunk;
|
||||
schedule();
|
||||
}
|
||||
#else
|
||||
sha256_update(&ctx, input, ilen);
|
||||
#endif
|
||||
|
||||
sha256_finish(&ctx, output);
|
||||
}
|
||||
|
||||
50
lib/sha256_common.c
Normal file
50
lib/sha256_common.c
Normal file
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* FIPS-180-2 compliant SHA-256 implementation
|
||||
*
|
||||
* Copyright (C) 2001-2003 Christophe Devine
|
||||
*/
|
||||
|
||||
#ifndef USE_HOSTCC
|
||||
#include <u-boot/schedule.h>
|
||||
#endif /* USE_HOSTCC */
|
||||
#include <string.h>
|
||||
#include <u-boot/sha256.h>
|
||||
|
||||
#include <linux/compiler_attributes.h>
|
||||
|
||||
/*
|
||||
* Output = SHA-256( input buffer ). Trigger the watchdog every 'chunk_sz'
|
||||
* bytes of input processed.
|
||||
*/
|
||||
void sha256_csum_wd(const unsigned char *input, unsigned int ilen,
|
||||
unsigned char *output, unsigned int chunk_sz)
|
||||
{
|
||||
sha256_context ctx;
|
||||
#if !defined(USE_HOSTCC) && \
|
||||
(defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG))
|
||||
const unsigned char *end;
|
||||
unsigned char *curr;
|
||||
int chunk;
|
||||
#endif
|
||||
|
||||
sha256_starts(&ctx);
|
||||
|
||||
#if !defined(USE_HOSTCC) && \
|
||||
(defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG))
|
||||
curr = (unsigned char *)input;
|
||||
end = input + ilen;
|
||||
while (curr < end) {
|
||||
chunk = end - curr;
|
||||
if (chunk > chunk_sz)
|
||||
chunk = chunk_sz;
|
||||
sha256_update(&ctx, curr, chunk);
|
||||
curr += chunk;
|
||||
schedule();
|
||||
}
|
||||
#else
|
||||
sha256_update(&ctx, input, ilen);
|
||||
#endif
|
||||
|
||||
sha256_finish(&ctx, output);
|
||||
}
|
||||
@@ -138,6 +138,7 @@ dumpimage-mkimage-objs := aisimage.o \
|
||||
generated/lib/hash-checksum.o \
|
||||
generated/lib/sha1.o \
|
||||
generated/lib/sha256.o \
|
||||
generated/lib/sha256_common.o \
|
||||
generated/lib/sha512.o \
|
||||
generated/common/hash.o \
|
||||
ublimage.o \
|
||||
|
||||
Reference in New Issue
Block a user