From 0bcb28dfb946b32ed7550fc4c24c5dcea6718554 Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Fri, 19 Feb 2021 12:45:10 -0600 Subject: lib: Rename rsa-checksum.c to hash-checksum.c rsa-checksum.c sontains the hash_calculate() implementations. Despite the "rsa-" file prefix, this function is useful for other algorithms. To prevent confusion, move this file to lib/, and rename it to hash-checksum.c, to give it a more "generic" feel. Signed-off-by: Alexandru Gagniuc Reviewed-by: Simon Glass --- lib/Makefile | 1 + lib/crypto/pkcs7_verify.c | 2 +- lib/crypto/x509_public_key.c | 2 +- lib/hash-checksum.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ lib/rsa/Makefile | 2 +- lib/rsa/rsa-checksum.c | 51 ------------------------------------------- 6 files changed, 56 insertions(+), 54 deletions(-) create mode 100644 lib/hash-checksum.c delete mode 100644 lib/rsa/rsa-checksum.c (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index c42d4e1233..6825671955 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -61,6 +61,7 @@ endif obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/ obj-$(CONFIG_$(SPL_)MD5) += md5.o obj-$(CONFIG_$(SPL_)RSA) += rsa/ +obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o obj-$(CONFIG_SHA1) += sha1.o obj-$(CONFIG_SHA256) += sha256.o obj-$(CONFIG_SHA512_ALGO) += sha512.o diff --git a/lib/crypto/pkcs7_verify.c b/lib/crypto/pkcs7_verify.c index 58683ef614..82c5c745d4 100644 --- a/lib/crypto/pkcs7_verify.c +++ b/lib/crypto/pkcs7_verify.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #else diff --git a/lib/crypto/x509_public_key.c b/lib/crypto/x509_public_key.c index 91810a8640..d557ab27ae 100644 --- a/lib/crypto/x509_public_key.c +++ b/lib/crypto/x509_public_key.c @@ -19,7 +19,7 @@ #include #ifdef __UBOOT__ #include -#include +#include #else #include #include diff --git a/lib/hash-checksum.c b/lib/hash-checksum.c new file mode 100644 index 0000000000..d732ecc38f --- /dev/null +++ b/lib/hash-checksum.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2013, Andreas Oetken. + */ + +#ifndef USE_HOSTCC +#include +#include +#include +#include +#include +#include +#else +#include "fdt_host.h" +#endif +#include +#include + +int hash_calculate(const char *name, + const struct image_region region[], + int region_count, uint8_t *checksum) +{ + struct hash_algo *algo; + int ret = 0; + void *ctx; + uint32_t i; + i = 0; + + ret = hash_progressive_lookup_algo(name, &algo); + if (ret) + return ret; + + ret = algo->hash_init(algo, &ctx); + if (ret) + return ret; + + for (i = 0; i < region_count - 1; i++) { + ret = algo->hash_update(algo, ctx, region[i].data, + region[i].size, 0); + if (ret) + return ret; + } + + ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1); + if (ret) + return ret; + ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size); + if (ret) + return ret; + + return 0; +} diff --git a/lib/rsa/Makefile b/lib/rsa/Makefile index 8b75d41f04..c9ac72c1e2 100644 --- a/lib/rsa/Makefile +++ b/lib/rsa/Makefile @@ -5,6 +5,6 @@ # (C) Copyright 2000-2007 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. -obj-$(CONFIG_$(SPL_TPL_)RSA_VERIFY) += rsa-verify.o rsa-checksum.o +obj-$(CONFIG_$(SPL_TPL_)RSA_VERIFY) += rsa-verify.o obj-$(CONFIG_$(SPL_TPL_)RSA_VERIFY_WITH_PKEY) += rsa-keyprop.o obj-$(CONFIG_RSA_SOFTWARE_EXP) += rsa-mod-exp.o diff --git a/lib/rsa/rsa-checksum.c b/lib/rsa/rsa-checksum.c deleted file mode 100644 index e60debb7df..0000000000 --- a/lib/rsa/rsa-checksum.c +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2013, Andreas Oetken. - */ - -#ifndef USE_HOSTCC -#include -#include -#include -#include -#include -#include -#else -#include "fdt_host.h" -#endif -#include - -int hash_calculate(const char *name, - const struct image_region region[], - int region_count, uint8_t *checksum) -{ - struct hash_algo *algo; - int ret = 0; - void *ctx; - uint32_t i; - i = 0; - - ret = hash_progressive_lookup_algo(name, &algo); - if (ret) - return ret; - - ret = algo->hash_init(algo, &ctx); - if (ret) - return ret; - - for (i = 0; i < region_count - 1; i++) { - ret = algo->hash_update(algo, ctx, region[i].data, - region[i].size, 0); - if (ret) - return ret; - } - - ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1); - if (ret) - return ret; - ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size); - if (ret) - return ret; - - return 0; -} -- cgit v1.2.3