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/hash-checksum.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/hash-checksum.c (limited to 'lib/hash-checksum.c') diff --git a/lib/hash-checksum.c b/lib/hash-checksum.c new file mode 100644 index 00000000000..d732ecc38fd --- /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; +} -- cgit v1.2.3