1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
7 #include <fdt_support.h>
9 #include <linux/libfdt.h>
11 #include <u-boot/ecdsa.h>
12 #include <u-boot/rsa.h>
13 #include <u-boot/hash-checksum.h>
15 struct checksum_algo checksum_algos[] = {
18 .checksum_len = SHA1_SUM_LEN,
19 .der_len = SHA1_DER_LEN,
20 .der_prefix = sha1_der_prefix,
21 .calculate_sign = EVP_sha1,
22 .calculate = hash_calculate,
26 .checksum_len = SHA256_SUM_LEN,
27 .der_len = SHA256_DER_LEN,
28 .der_prefix = sha256_der_prefix,
29 .calculate_sign = EVP_sha256,
30 .calculate = hash_calculate,
34 .checksum_len = SHA384_SUM_LEN,
35 .der_len = SHA384_DER_LEN,
36 .der_prefix = sha384_der_prefix,
37 .calculate_sign = EVP_sha384,
38 .calculate = hash_calculate,
42 .checksum_len = SHA512_SUM_LEN,
43 .der_len = SHA512_DER_LEN,
44 .der_prefix = sha512_der_prefix,
45 .calculate_sign = EVP_sha512,
46 .calculate = hash_calculate,
50 struct crypto_algo crypto_algos[] = {
53 .key_len = RSA2048_BYTES,
55 .add_verify_data = rsa_add_verify_data,
60 .key_len = RSA3072_BYTES,
62 .add_verify_data = rsa_add_verify_data,
67 .key_len = RSA4096_BYTES,
69 .add_verify_data = rsa_add_verify_data,
74 .key_len = ECDSA256_BYTES,
76 .add_verify_data = ecdsa_add_verify_data,
77 .verify = ecdsa_verify,
81 struct padding_algo padding_algos[] = {
84 .verify = padding_pkcs_15_verify,
88 .verify = padding_pss_verify,
92 struct checksum_algo *image_get_checksum_algo(const char *full_name)
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 /* Move name to after the comma */
114 name = strchr(full_name, ',');
119 for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
120 if (!strcmp(crypto_algos[i].name, name))
121 return &crypto_algos[i];
127 struct padding_algo *image_get_padding_algo(const char *name)
134 for (i = 0; i < ARRAY_SIZE(padding_algos); i++) {
135 if (!strcmp(padding_algos[i].name, name))
136 return &padding_algos[i];