]> git.ipfire.org Git - thirdparty/u-boot.git/blame - lib/rsa/rsa-checksum.c
Merge https://source.denx.de/u-boot/custodians/u-boot-sh
[thirdparty/u-boot.git] / lib / rsa / rsa-checksum.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
646257d1
HS
2/*
3 * Copyright (c) 2013, Andreas Oetken.
646257d1
HS
4 */
5
29a23f9d 6#ifndef USE_HOSTCC
646257d1
HS
7#include <common.h>
8#include <fdtdec.h>
646257d1 9#include <asm/byteorder.h>
1221ce45 10#include <linux/errno.h>
646257d1 11#include <asm/unaligned.h>
b37b46f0 12#include <hash.h>
29a23f9d
HS
13#else
14#include "fdt_host.h"
b37b46f0
RG
15#endif
16#include <u-boot/rsa.h>
646257d1 17
b37b46f0
RG
18int hash_calculate(const char *name,
19 const struct image_region region[],
20 int region_count, uint8_t *checksum)
646257d1 21{
b37b46f0
RG
22 struct hash_algo *algo;
23 int ret = 0;
24 void *ctx;
646257d1
HS
25 uint32_t i;
26 i = 0;
27
b37b46f0
RG
28 ret = hash_progressive_lookup_algo(name, &algo);
29 if (ret)
30 return ret;
646257d1 31
b37b46f0
RG
32 ret = algo->hash_init(algo, &ctx);
33 if (ret)
34 return ret;
35
36 for (i = 0; i < region_count - 1; i++) {
37 ret = algo->hash_update(algo, ctx, region[i].data,
38 region[i].size, 0);
39 if (ret)
40 return ret;
41 }
42
43 ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1);
44 if (ret)
45 return ret;
46 ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size);
47 if (ret)
48 return ret;
646257d1 49
b37b46f0 50 return 0;
646257d1 51}