1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
9 #include <asm/global_data.h>
10 DECLARE_GLOBAL_DATA_PTR;
13 #include <u-boot/ecdsa.h>
14 #include <u-boot/rsa.h>
15 #include <u-boot/hash-checksum.h>
17 #define IMAGE_MAX_HASHED_NODES 100
19 struct checksum_algo checksum_algos[] = {
22 .checksum_len = SHA1_SUM_LEN,
23 .der_len = SHA1_DER_LEN,
24 .der_prefix = sha1_der_prefix,
25 .calculate = hash_calculate,
29 .checksum_len = SHA256_SUM_LEN,
30 .der_len = SHA256_DER_LEN,
31 .der_prefix = sha256_der_prefix,
32 .calculate = hash_calculate,
37 .checksum_len = SHA384_SUM_LEN,
38 .der_len = SHA384_DER_LEN,
39 .der_prefix = sha384_der_prefix,
40 .calculate = hash_calculate,
46 .checksum_len = SHA512_SUM_LEN,
47 .der_len = SHA512_DER_LEN,
48 .der_prefix = sha512_der_prefix,
49 .calculate = hash_calculate,
55 struct checksum_algo *image_get_checksum_algo(const char *full_name)
60 if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
65 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
66 struct checksum_algo *algo = &checksum_algos[i];
68 MANUAL_RELOC(algo->name);
69 MANUAL_RELOC(algo->calculate);
74 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
75 name = checksum_algos[i].name;
76 /* Make sure names match and next char is a comma */
77 if (!strncmp(name, full_name, strlen(name)) &&
78 full_name[strlen(name)] == ',')
79 return &checksum_algos[i];
85 struct crypto_algo *image_get_crypto_algo(const char *full_name)
87 struct crypto_algo *crypto, *end;
90 if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
95 crypto = ll_entry_start(struct crypto_algo, cryptos);
96 end = ll_entry_end(struct crypto_algo, cryptos);
97 for (; crypto < end; crypto++) {
98 MANUAL_RELOC(crypto->name);
99 MANUAL_RELOC(crypto->verify);
104 /* Move name to after the comma */
105 name = strchr(full_name, ',');
110 crypto = ll_entry_start(struct crypto_algo, cryptos);
111 end = ll_entry_end(struct crypto_algo, cryptos);
112 for (; crypto < end; crypto++) {
113 if (!strcmp(crypto->name, name))
121 struct padding_algo *image_get_padding_algo(const char *name)
123 struct padding_algo *padding, *end;
128 padding = ll_entry_start(struct padding_algo, paddings);
129 end = ll_entry_end(struct padding_algo, paddings);
130 for (; padding < end; padding++) {
131 if (!strcmp(padding->name, name))