]> git.ipfire.org Git - thirdparty/u-boot.git/blame - boot/image-sig.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / boot / image-sig.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
3e569a6b
SG
2/*
3 * Copyright (c) 2013, Google Inc.
3e569a6b
SG
4 */
5
d678a59d 6#include <common.h>
f7ae49fc 7#include <log.h>
56518e71 8#include <malloc.h>
401d1c4f 9#include <asm/global_data.h>
56518e71 10DECLARE_GLOBAL_DATA_PTR;
3e569a6b 11#include <image.h>
c5a68d29 12#include <relocate.h>
ed6c9e0b 13#include <u-boot/ecdsa.h>
2b9912e6 14#include <u-boot/rsa.h>
0bcb28df 15#include <u-boot/hash-checksum.h>
3e569a6b 16
4d098529
SG
17#define IMAGE_MAX_HASHED_NODES 100
18
646257d1 19struct checksum_algo checksum_algos[] = {
14e110a1 20#if CONFIG_IS_ENABLED(SHA1)
646257d1 21 {
8ec87df3
MY
22 .name = "sha1",
23 .checksum_len = SHA1_SUM_LEN,
24 .der_len = SHA1_DER_LEN,
25 .der_prefix = sha1_der_prefix,
8ec87df3 26 .calculate = hash_calculate,
646257d1 27 },
14e110a1
SA
28#endif
29#if CONFIG_IS_ENABLED(SHA256)
646257d1 30 {
8ec87df3
MY
31 .name = "sha256",
32 .checksum_len = SHA256_SUM_LEN,
33 .der_len = SHA256_DER_LEN,
34 .der_prefix = sha256_der_prefix,
8ec87df3 35 .calculate = hash_calculate,
d16b38f4 36 },
14e110a1
SA
37#endif
38#if CONFIG_IS_ENABLED(SHA384)
d16b38f4
RD
39 {
40 .name = "sha384",
41 .checksum_len = SHA384_SUM_LEN,
42 .der_len = SHA384_DER_LEN,
43 .der_prefix = sha384_der_prefix,
d16b38f4
RD
44 .calculate = hash_calculate,
45 },
46#endif
14e110a1 47#if CONFIG_IS_ENABLED(SHA512)
d16b38f4
RD
48 {
49 .name = "sha512",
50 .checksum_len = SHA512_SUM_LEN,
51 .der_len = SHA512_DER_LEN,
52 .der_prefix = sha512_der_prefix,
d16b38f4
RD
53 .calculate = hash_calculate,
54 },
55#endif
0c1d74fd
AD
56
57};
58
83dd98e0
AD
59struct checksum_algo *image_get_checksum_algo(const char *full_name)
60{
61 int i;
62 const char *name;
63
64 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
65 name = checksum_algos[i].name;
66 /* Make sure names match and next char is a comma */
67 if (!strncmp(name, full_name, strlen(name)) &&
68 full_name[strlen(name)] == ',')
69 return &checksum_algos[i];
19c402af 70 }
db1b5f3d 71
83dd98e0
AD
72 return NULL;
73}
3e569a6b 74
83dd98e0 75struct crypto_algo *image_get_crypto_algo(const char *full_name)
3e569a6b 76{
0980164b 77 struct crypto_algo *crypto, *end;
83dd98e0
AD
78 const char *name;
79
80 /* Move name to after the comma */
81 name = strchr(full_name, ',');
82 if (!name)
83 return NULL;
84 name += 1;
3e569a6b 85
0980164b
AG
86 crypto = ll_entry_start(struct crypto_algo, cryptos);
87 end = ll_entry_end(struct crypto_algo, cryptos);
88 for (; crypto < end; crypto++) {
89 if (!strcmp(crypto->name, name))
90 return crypto;
91 }
92
93 /* Not found */
3e569a6b
SG
94 return NULL;
95}
56518e71 96
20031567
PR
97struct padding_algo *image_get_padding_algo(const char *name)
98{
de41f0ee 99 struct padding_algo *padding, *end;
20031567
PR
100
101 if (!name)
102 return NULL;
103
de41f0ee
AG
104 padding = ll_entry_start(struct padding_algo, paddings);
105 end = ll_entry_end(struct padding_algo, paddings);
106 for (; padding < end; padding++) {
107 if (!strcmp(padding->name, name))
108 return padding;
20031567
PR
109 }
110
111 return NULL;
112}