1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
8 #include <fdt_support.h>
10 #include <linux/libfdt.h>
15 DECLARE_GLOBAL_DATA_PTR;
16 #endif /* !USE_HOSTCC*/
18 #include <u-boot/rsa.h>
19 #include <u-boot/rsa-checksum.h>
21 #define IMAGE_MAX_HASHED_NODES 100
23 struct checksum_algo checksum_algos[] = {
26 .checksum_len = SHA1_SUM_LEN,
27 .der_len = SHA1_DER_LEN,
28 .der_prefix = sha1_der_prefix,
30 .calculate_sign = EVP_sha1,
32 .calculate = hash_calculate,
36 .checksum_len = SHA256_SUM_LEN,
37 .der_len = SHA256_DER_LEN,
38 .der_prefix = sha256_der_prefix,
40 .calculate_sign = EVP_sha256,
42 .calculate = hash_calculate,
47 .checksum_len = SHA384_SUM_LEN,
48 .der_len = SHA384_DER_LEN,
49 .der_prefix = sha384_der_prefix,
51 .calculate_sign = EVP_sha384,
53 .calculate = hash_calculate,
59 .checksum_len = SHA512_SUM_LEN,
60 .der_len = SHA512_DER_LEN,
61 .der_prefix = sha512_der_prefix,
63 .calculate_sign = EVP_sha512,
65 .calculate = hash_calculate,
71 struct crypto_algo crypto_algos[] = {
74 .key_len = RSA2048_BYTES,
76 .add_verify_data = rsa_add_verify_data,
81 .key_len = RSA4096_BYTES,
83 .add_verify_data = rsa_add_verify_data,
89 struct padding_algo padding_algos[] = {
92 .verify = padding_pkcs_15_verify,
94 #ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
97 .verify = padding_pss_verify,
99 #endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
102 struct checksum_algo *image_get_checksum_algo(const char *full_name)
107 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
112 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
113 checksum_algos[i].name += gd->reloc_off;
114 #if IMAGE_ENABLE_SIGN
115 checksum_algos[i].calculate_sign += gd->reloc_off;
117 checksum_algos[i].calculate += gd->reloc_off;
122 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
123 name = checksum_algos[i].name;
124 /* Make sure names match and next char is a comma */
125 if (!strncmp(name, full_name, strlen(name)) &&
126 full_name[strlen(name)] == ',')
127 return &checksum_algos[i];
133 struct crypto_algo *image_get_crypto_algo(const char *full_name)
138 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
143 for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
144 crypto_algos[i].name += gd->reloc_off;
145 crypto_algos[i].sign += gd->reloc_off;
146 crypto_algos[i].add_verify_data += gd->reloc_off;
147 crypto_algos[i].verify += gd->reloc_off;
152 /* Move name to after the comma */
153 name = strchr(full_name, ',');
158 for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
159 if (!strcmp(crypto_algos[i].name, name))
160 return &crypto_algos[i];
166 struct padding_algo *image_get_padding_algo(const char *name)
173 for (i = 0; i < ARRAY_SIZE(padding_algos); i++) {
174 if (!strcmp(padding_algos[i].name, name))
175 return &padding_algos[i];