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