1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
12 DECLARE_GLOBAL_DATA_PTR
;
13 #endif /* !USE_HOSTCC*/
15 #include <u-boot/rsa.h>
16 #include <u-boot/rsa-checksum.h>
18 #define IMAGE_MAX_HASHED_NODES 100
20 struct checksum_algo checksum_algos
[] = {
23 .checksum_len
= SHA1_SUM_LEN
,
24 .der_len
= SHA1_DER_LEN
,
25 .der_prefix
= sha1_der_prefix
,
27 .calculate_sign
= EVP_sha1
,
29 .calculate
= hash_calculate
,
33 .checksum_len
= SHA256_SUM_LEN
,
34 .der_len
= SHA256_DER_LEN
,
35 .der_prefix
= sha256_der_prefix
,
37 .calculate_sign
= EVP_sha256
,
39 .calculate
= hash_calculate
,
44 struct crypto_algo crypto_algos
[] = {
47 .key_len
= RSA2048_BYTES
,
49 .add_verify_data
= rsa_add_verify_data
,
54 .key_len
= RSA4096_BYTES
,
56 .add_verify_data
= rsa_add_verify_data
,
62 struct padding_algo padding_algos
[] = {
65 .verify
= padding_pkcs_15_verify
,
67 #ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
70 .verify
= padding_pss_verify
,
72 #endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
75 struct checksum_algo
*image_get_checksum_algo(const char *full_name
)
80 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
85 for (i
= 0; i
< ARRAY_SIZE(checksum_algos
); i
++) {
86 checksum_algos
[i
].name
+= gd
->reloc_off
;
88 checksum_algos
[i
].calculate_sign
+= gd
->reloc_off
;
90 checksum_algos
[i
].calculate
+= gd
->reloc_off
;
95 for (i
= 0; i
< ARRAY_SIZE(checksum_algos
); i
++) {
96 name
= checksum_algos
[i
].name
;
97 /* Make sure names match and next char is a comma */
98 if (!strncmp(name
, full_name
, strlen(name
)) &&
99 full_name
[strlen(name
)] == ',')
100 return &checksum_algos
[i
];
106 struct crypto_algo
*image_get_crypto_algo(const char *full_name
)
111 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
116 for (i
= 0; i
< ARRAY_SIZE(crypto_algos
); i
++) {
117 crypto_algos
[i
].name
+= gd
->reloc_off
;
118 crypto_algos
[i
].sign
+= gd
->reloc_off
;
119 crypto_algos
[i
].add_verify_data
+= gd
->reloc_off
;
120 crypto_algos
[i
].verify
+= gd
->reloc_off
;
125 /* Move name to after the comma */
126 name
= strchr(full_name
, ',');
131 for (i
= 0; i
< ARRAY_SIZE(crypto_algos
); i
++) {
132 if (!strcmp(crypto_algos
[i
].name
, name
))
133 return &crypto_algos
[i
];
139 struct padding_algo
*image_get_padding_algo(const char *name
)
146 for (i
= 0; i
< ARRAY_SIZE(padding_algos
); i
++) {
147 if (!strcmp(padding_algos
[i
].name
, name
))
148 return &padding_algos
[i
];