]>
Commit | Line | Data |
---|---|---|
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 | 7 | #include <fdtdec.h> |
646257d1 | 8 | #include <asm/byteorder.h> |
1221ce45 | 9 | #include <linux/errno.h> |
646257d1 | 10 | #include <asm/unaligned.h> |
b37b46f0 | 11 | #include <hash.h> |
29a23f9d HS |
12 | #else |
13 | #include "fdt_host.h" | |
b37b46f0 | 14 | #endif |
0bcb28df AG |
15 | #include <hash.h> |
16 | #include <image.h> | |
646257d1 | 17 | |
b37b46f0 | 18 | int hash_calculate(const char *name, |
13c133b9 | 19 | const struct image_region *region, |
b37b46f0 | 20 | int region_count, uint8_t *checksum) |
646257d1 | 21 | { |
b37b46f0 RG |
22 | struct hash_algo *algo; |
23 | int ret = 0; | |
24 | void *ctx; | |
eb48efce HS |
25 | int i; |
26 | ||
27 | if (region_count < 1) | |
28 | return -EINVAL; | |
646257d1 | 29 | |
b37b46f0 RG |
30 | ret = hash_progressive_lookup_algo(name, &algo); |
31 | if (ret) | |
32 | return ret; | |
646257d1 | 33 | |
b37b46f0 RG |
34 | ret = algo->hash_init(algo, &ctx); |
35 | if (ret) | |
36 | return ret; | |
37 | ||
38 | for (i = 0; i < region_count - 1; i++) { | |
39 | ret = algo->hash_update(algo, ctx, region[i].data, | |
40 | region[i].size, 0); | |
41 | if (ret) | |
42 | return ret; | |
43 | } | |
44 | ||
45 | ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1); | |
46 | if (ret) | |
47 | return ret; | |
48 | ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size); | |
49 | if (ret) | |
50 | return ret; | |
646257d1 | 51 | |
b37b46f0 | 52 | return 0; |
646257d1 | 53 | } |