1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
8 #include <fdt_support.h>
10 #include <linux/libfdt.h>
14 DECLARE_GLOBAL_DATA_PTR;
15 #endif /* !USE_HOSTCC*/
17 #include <u-boot/rsa.h>
18 #include <u-boot/rsa-checksum.h>
20 #define IMAGE_MAX_HASHED_NODES 100
22 struct checksum_algo checksum_algos[] = {
25 .checksum_len = SHA1_SUM_LEN,
26 .der_len = SHA1_DER_LEN,
27 .der_prefix = sha1_der_prefix,
29 .calculate_sign = EVP_sha1,
31 .calculate = hash_calculate,
35 .checksum_len = SHA256_SUM_LEN,
36 .der_len = SHA256_DER_LEN,
37 .der_prefix = sha256_der_prefix,
39 .calculate_sign = EVP_sha256,
41 .calculate = hash_calculate,
46 struct crypto_algo crypto_algos[] = {
49 .key_len = RSA2048_BYTES,
51 .add_verify_data = rsa_add_verify_data,
56 .key_len = RSA4096_BYTES,
58 .add_verify_data = rsa_add_verify_data,
64 struct padding_algo padding_algos[] = {
67 .verify = padding_pkcs_15_verify,
69 #ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
72 .verify = padding_pss_verify,
74 #endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
77 struct checksum_algo *image_get_checksum_algo(const char *full_name)
82 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
87 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
88 checksum_algos[i].name += gd->reloc_off;
90 checksum_algos[i].calculate_sign += gd->reloc_off;
92 checksum_algos[i].calculate += gd->reloc_off;
97 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
98 name = checksum_algos[i].name;
99 /* Make sure names match and next char is a comma */
100 if (!strncmp(name, full_name, strlen(name)) &&
101 full_name[strlen(name)] == ',')
102 return &checksum_algos[i];
108 struct crypto_algo *image_get_crypto_algo(const char *full_name)
113 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
118 for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
119 crypto_algos[i].name += gd->reloc_off;
120 crypto_algos[i].sign += gd->reloc_off;
121 crypto_algos[i].add_verify_data += gd->reloc_off;
122 crypto_algos[i].verify += gd->reloc_off;
127 /* Move name to after the comma */
128 name = strchr(full_name, ',');
133 for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
134 if (!strcmp(crypto_algos[i].name, name))
135 return &crypto_algos[i];
141 struct padding_algo *image_get_padding_algo(const char *name)
148 for (i = 0; i < ARRAY_SIZE(padding_algos); i++) {
149 if (!strcmp(padding_algos[i].name, name))
150 return &padding_algos[i];