1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
8 #include <asm/global_data.h>
9 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[] = {
19 #if CONFIG_IS_ENABLED(SHA1)
22 .checksum_len = SHA1_SUM_LEN,
23 .der_len = SHA1_DER_LEN,
24 .der_prefix = sha1_der_prefix,
25 .calculate = hash_calculate,
28 #if CONFIG_IS_ENABLED(SHA256)
31 .checksum_len = SHA256_SUM_LEN,
32 .der_len = SHA256_DER_LEN,
33 .der_prefix = sha256_der_prefix,
34 .calculate = hash_calculate,
37 #if CONFIG_IS_ENABLED(SHA384)
40 .checksum_len = SHA384_SUM_LEN,
41 .der_len = SHA384_DER_LEN,
42 .der_prefix = sha384_der_prefix,
43 .calculate = hash_calculate,
46 #if CONFIG_IS_ENABLED(SHA512)
49 .checksum_len = SHA512_SUM_LEN,
50 .der_len = SHA512_DER_LEN,
51 .der_prefix = sha512_der_prefix,
52 .calculate = hash_calculate,
58 struct checksum_algo *image_get_checksum_algo(const char *full_name)
63 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
64 name = checksum_algos[i].name;
65 /* Make sure names match and next char is a comma */
66 if (!strncmp(name, full_name, strlen(name)) &&
67 full_name[strlen(name)] == ',')
68 return &checksum_algos[i];
74 struct crypto_algo *image_get_crypto_algo(const char *full_name)
76 struct crypto_algo *crypto, *end;
79 /* Move name to after the comma */
80 name = strchr(full_name, ',');
85 crypto = ll_entry_start(struct crypto_algo, cryptos);
86 end = ll_entry_end(struct crypto_algo, cryptos);
87 for (; crypto < end; crypto++) {
88 if (!strcmp(crypto->name, name))
96 struct padding_algo *image_get_padding_algo(const char *name)
98 struct padding_algo *padding, *end;
103 padding = ll_entry_start(struct padding_algo, paddings);
104 end = ll_entry_end(struct padding_algo, paddings);
105 for (; padding < end; padding++) {
106 if (!strcmp(padding->name, name))