]> Git Repo - J-u-boot.git/blame - common/image-sig.c
common: Drop asm/global_data.h from common header
[J-u-boot.git] / common / 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
6#ifdef USE_HOSTCC
7#include "mkimage.h"
4d72caa5 8#include <fdt_support.h>
3e569a6b 9#include <time.h>
4d72caa5 10#include <linux/libfdt.h>
3e569a6b
SG
11#else
12#include <common.h>
f7ae49fc 13#include <log.h>
56518e71 14#include <malloc.h>
401d1c4f 15#include <asm/global_data.h>
56518e71 16DECLARE_GLOBAL_DATA_PTR;
3e569a6b 17#endif /* !USE_HOSTCC*/
3e569a6b 18#include <image.h>
2b9912e6
JH
19#include <u-boot/rsa.h>
20#include <u-boot/rsa-checksum.h>
3e569a6b 21
4d098529
SG
22#define IMAGE_MAX_HASHED_NODES 100
23
646257d1
HS
24struct checksum_algo checksum_algos[] = {
25 {
8ec87df3
MY
26 .name = "sha1",
27 .checksum_len = SHA1_SUM_LEN,
28 .der_len = SHA1_DER_LEN,
29 .der_prefix = sha1_der_prefix,
646257d1 30#if IMAGE_ENABLE_SIGN
8ec87df3 31 .calculate_sign = EVP_sha1,
29a23f9d 32#endif
8ec87df3 33 .calculate = hash_calculate,
646257d1
HS
34 },
35 {
8ec87df3
MY
36 .name = "sha256",
37 .checksum_len = SHA256_SUM_LEN,
38 .der_len = SHA256_DER_LEN,
39 .der_prefix = sha256_der_prefix,
646257d1 40#if IMAGE_ENABLE_SIGN
8ec87df3 41 .calculate_sign = EVP_sha256,
29a23f9d 42#endif
8ec87df3 43 .calculate = hash_calculate,
d16b38f4
RD
44 },
45#ifdef CONFIG_SHA384
46 {
47 .name = "sha384",
48 .checksum_len = SHA384_SUM_LEN,
49 .der_len = SHA384_DER_LEN,
50 .der_prefix = sha384_der_prefix,
51#if IMAGE_ENABLE_SIGN
52 .calculate_sign = EVP_sha384,
53#endif
54 .calculate = hash_calculate,
55 },
56#endif
57#ifdef CONFIG_SHA512
58 {
59 .name = "sha512",
60 .checksum_len = SHA512_SUM_LEN,
61 .der_len = SHA512_DER_LEN,
62 .der_prefix = sha512_der_prefix,
63#if IMAGE_ENABLE_SIGN
64 .calculate_sign = EVP_sha512,
65#endif
66 .calculate = hash_calculate,
67 },
68#endif
0c1d74fd
AD
69
70};
71
72struct crypto_algo crypto_algos[] = {
73 {
8ec87df3
MY
74 .name = "rsa2048",
75 .key_len = RSA2048_BYTES,
76 .sign = rsa_sign,
77 .add_verify_data = rsa_add_verify_data,
78 .verify = rsa_verify,
db1b5f3d
HS
79 },
80 {
8ec87df3
MY
81 .name = "rsa4096",
82 .key_len = RSA4096_BYTES,
83 .sign = rsa_sign,
84 .add_verify_data = rsa_add_verify_data,
85 .verify = rsa_verify,
646257d1 86 }
db1b5f3d 87
646257d1 88};
db1b5f3d 89
20031567
PR
90struct padding_algo padding_algos[] = {
91 {
92 .name = "pkcs-1.5",
93 .verify = padding_pkcs_15_verify,
94 },
061daa0b
PR
95#ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
96 {
97 .name = "pss",
98 .verify = padding_pss_verify,
99 }
100#endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
20031567
PR
101};
102
83dd98e0
AD
103struct checksum_algo *image_get_checksum_algo(const char *full_name)
104{
105 int i;
106 const char *name;
107
1ed8c137
KR
108#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
109 static bool done;
110
111 if (!done) {
112 done = true;
113 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
114 checksum_algos[i].name += gd->reloc_off;
115#if IMAGE_ENABLE_SIGN
116 checksum_algos[i].calculate_sign += gd->reloc_off;
117#endif
118 checksum_algos[i].calculate += gd->reloc_off;
119 }
120 }
121#endif
122
83dd98e0
AD
123 for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
124 name = checksum_algos[i].name;
125 /* Make sure names match and next char is a comma */
126 if (!strncmp(name, full_name, strlen(name)) &&
127 full_name[strlen(name)] == ',')
128 return &checksum_algos[i];
19c402af 129 }
db1b5f3d 130
83dd98e0
AD
131 return NULL;
132}
3e569a6b 133
83dd98e0 134struct crypto_algo *image_get_crypto_algo(const char *full_name)
3e569a6b
SG
135{
136 int i;
83dd98e0
AD
137 const char *name;
138
1ed8c137
KR
139#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
140 static bool done;
141
142 if (!done) {
143 done = true;
144 for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
145 crypto_algos[i].name += gd->reloc_off;
146 crypto_algos[i].sign += gd->reloc_off;
147 crypto_algos[i].add_verify_data += gd->reloc_off;
148 crypto_algos[i].verify += gd->reloc_off;
149 }
150 }
151#endif
152
83dd98e0
AD
153 /* Move name to after the comma */
154 name = strchr(full_name, ',');
155 if (!name)
156 return NULL;
157 name += 1;
3e569a6b 158
83dd98e0
AD
159 for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
160 if (!strcmp(crypto_algos[i].name, name))
161 return &crypto_algos[i];
3e569a6b
SG
162 }
163
164 return NULL;
165}
56518e71 166
20031567
PR
167struct padding_algo *image_get_padding_algo(const char *name)
168{
169 int i;
170
171 if (!name)
172 return NULL;
173
174 for (i = 0; i < ARRAY_SIZE(padding_algos); i++) {
175 if (!strcmp(padding_algos[i].name, name))
176 return &padding_algos[i];
177 }
178
179 return NULL;
180}
This page took 0.377687 seconds and 4 git commands to generate.