]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
3e569a6b SG |
2 | /* |
3 | * Copyright (c) 2013, Google Inc. | |
3e569a6b SG |
4 | */ |
5 | ||
f7ae49fc | 6 | #include <log.h> |
56518e71 | 7 | #include <malloc.h> |
401d1c4f | 8 | #include <asm/global_data.h> |
56518e71 | 9 | DECLARE_GLOBAL_DATA_PTR; |
3e569a6b | 10 | #include <image.h> |
c5a68d29 | 11 | #include <relocate.h> |
ed6c9e0b | 12 | #include <u-boot/ecdsa.h> |
2b9912e6 | 13 | #include <u-boot/rsa.h> |
0bcb28df | 14 | #include <u-boot/hash-checksum.h> |
3e569a6b | 15 | |
4d098529 SG |
16 | #define IMAGE_MAX_HASHED_NODES 100 |
17 | ||
646257d1 | 18 | struct checksum_algo checksum_algos[] = { |
14e110a1 | 19 | #if CONFIG_IS_ENABLED(SHA1) |
646257d1 | 20 | { |
8ec87df3 MY |
21 | .name = "sha1", |
22 | .checksum_len = SHA1_SUM_LEN, | |
23 | .der_len = SHA1_DER_LEN, | |
24 | .der_prefix = sha1_der_prefix, | |
8ec87df3 | 25 | .calculate = hash_calculate, |
646257d1 | 26 | }, |
14e110a1 SA |
27 | #endif |
28 | #if CONFIG_IS_ENABLED(SHA256) | |
646257d1 | 29 | { |
8ec87df3 MY |
30 | .name = "sha256", |
31 | .checksum_len = SHA256_SUM_LEN, | |
32 | .der_len = SHA256_DER_LEN, | |
33 | .der_prefix = sha256_der_prefix, | |
8ec87df3 | 34 | .calculate = hash_calculate, |
d16b38f4 | 35 | }, |
14e110a1 SA |
36 | #endif |
37 | #if CONFIG_IS_ENABLED(SHA384) | |
d16b38f4 RD |
38 | { |
39 | .name = "sha384", | |
40 | .checksum_len = SHA384_SUM_LEN, | |
41 | .der_len = SHA384_DER_LEN, | |
42 | .der_prefix = sha384_der_prefix, | |
d16b38f4 RD |
43 | .calculate = hash_calculate, |
44 | }, | |
45 | #endif | |
14e110a1 | 46 | #if CONFIG_IS_ENABLED(SHA512) |
d16b38f4 RD |
47 | { |
48 | .name = "sha512", | |
49 | .checksum_len = SHA512_SUM_LEN, | |
50 | .der_len = SHA512_DER_LEN, | |
51 | .der_prefix = sha512_der_prefix, | |
d16b38f4 RD |
52 | .calculate = hash_calculate, |
53 | }, | |
54 | #endif | |
0c1d74fd AD |
55 | |
56 | }; | |
57 | ||
83dd98e0 AD |
58 | struct checksum_algo *image_get_checksum_algo(const char *full_name) |
59 | { | |
60 | int i; | |
61 | const char *name; | |
62 | ||
63 | for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) { | |
64 | name = checksum_algos[i].name; | |
65 | /* Make sure names match and next char is a comma */ | |
66 | if (!strncmp(name, full_name, strlen(name)) && | |
67 | full_name[strlen(name)] == ',') | |
68 | return &checksum_algos[i]; | |
19c402af | 69 | } |
db1b5f3d | 70 | |
83dd98e0 AD |
71 | return NULL; |
72 | } | |
3e569a6b | 73 | |
83dd98e0 | 74 | struct crypto_algo *image_get_crypto_algo(const char *full_name) |
3e569a6b | 75 | { |
0980164b | 76 | struct crypto_algo *crypto, *end; |
83dd98e0 AD |
77 | const char *name; |
78 | ||
79 | /* Move name to after the comma */ | |
80 | name = strchr(full_name, ','); | |
81 | if (!name) | |
82 | return NULL; | |
83 | name += 1; | |
3e569a6b | 84 | |
0980164b AG |
85 | crypto = ll_entry_start(struct crypto_algo, cryptos); |
86 | end = ll_entry_end(struct crypto_algo, cryptos); | |
87 | for (; crypto < end; crypto++) { | |
88 | if (!strcmp(crypto->name, name)) | |
89 | return crypto; | |
90 | } | |
91 | ||
92 | /* Not found */ | |
3e569a6b SG |
93 | return NULL; |
94 | } | |
56518e71 | 95 | |
20031567 PR |
96 | struct padding_algo *image_get_padding_algo(const char *name) |
97 | { | |
de41f0ee | 98 | struct padding_algo *padding, *end; |
20031567 PR |
99 | |
100 | if (!name) | |
101 | return NULL; | |
102 | ||
de41f0ee AG |
103 | padding = ll_entry_start(struct padding_algo, paddings); |
104 | end = ll_entry_end(struct padding_algo, paddings); | |
105 | for (; padding < end; padding++) { | |
106 | if (!strcmp(padding->name, name)) | |
107 | return padding; | |
20031567 PR |
108 | } |
109 | ||
110 | return NULL; | |
111 | } |