1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
9 #include <asm/global_data.h>
10 DECLARE_GLOBAL_DATA_PTR;
12 #include <u-boot/ecdsa.h>
13 #include <u-boot/rsa.h>
14 #include <u-boot/hash-checksum.h>
16 #define IMAGE_MAX_HASHED_NODES 100
18 struct checksum_algo checksum_algos[] = {
21 .checksum_len = SHA1_SUM_LEN,
22 .der_len = SHA1_DER_LEN,
23 .der_prefix = sha1_der_prefix,
24 .calculate = hash_calculate,
28 .checksum_len = SHA256_SUM_LEN,
29 .der_len = SHA256_DER_LEN,
30 .der_prefix = sha256_der_prefix,
31 .calculate = hash_calculate,
36 .checksum_len = SHA384_SUM_LEN,
37 .der_len = SHA384_DER_LEN,
38 .der_prefix = sha384_der_prefix,
39 .calculate = hash_calculate,
45 .checksum_len = SHA512_SUM_LEN,
46 .der_len = SHA512_DER_LEN,
47 .der_prefix = sha512_der_prefix,
48 .calculate = hash_calculate,
54 struct padding_algo padding_algos[] = {
57 .verify = padding_pkcs_15_verify,
59 #ifdef CONFIG_FIT_RSASSA_PSS
62 .verify = padding_pss_verify,
64 #endif /* CONFIG_FIT_RSASSA_PSS */
67 struct checksum_algo *image_get_checksum_algo(const char *full_name)
72 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
77 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
78 checksum_algos[i].name += gd->reloc_off;
79 checksum_algos[i].calculate += gd->reloc_off;
84 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
85 name = checksum_algos[i].name;
86 /* Make sure names match and next char is a comma */
87 if (!strncmp(name, full_name, strlen(name)) &&
88 full_name[strlen(name)] == ',')
89 return &checksum_algos[i];
95 struct crypto_algo *image_get_crypto_algo(const char *full_name)
97 struct crypto_algo *crypto, *end;
100 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
104 crypto = ll_entry_start(struct crypto_algo, cryptos);
105 end = ll_entry_end(struct crypto_algo, cryptos);
106 for (; crypto < end; crypto++) {
107 crypto->name += gd->reloc_off;
108 crypto->verify += gd->reloc_off;
113 /* Move name to after the comma */
114 name = strchr(full_name, ',');
119 crypto = ll_entry_start(struct crypto_algo, cryptos);
120 end = ll_entry_end(struct crypto_algo, cryptos);
121 for (; crypto < end; crypto++) {
122 if (!strcmp(crypto->name, name))
130 struct padding_algo *image_get_padding_algo(const char *name)
137 for (i = 0; i < ARRAY_SIZE(padding_algos); i++) {
138 if (!strcmp(padding_algos[i].name, name))
139 return &padding_algos[i];