22
22
#include "bootutil/crypto/aes_kw.h"
23
23
#endif
24
24
25
+ #if !defined(MCUBOOT_USE_PSA_CRYPTO )
25
26
#if defined(MCUBOOT_ENCRYPT_EC256 )
26
27
#include "bootutil/crypto/ecdh_p256.h"
27
28
#endif
28
29
29
- #if !defined(MCUBOOT_USE_PSA_CRYPTO )
30
30
#if defined(MCUBOOT_ENCRYPT_X25519 )
31
31
#include "bootutil/crypto/ecdh_x25519.h"
32
32
#endif
@@ -50,7 +50,7 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
50
50
#include "bootutil_priv.h"
51
51
52
52
/* NOUP Fixme: */
53
- #if !defined(CONFIG_BOOT_ED25519_PSA )
53
+ #if !defined(CONFIG_BOOT_ED25519_PSA ) && !defined( CONFIG_BOOT_ECDSA_PSA )
54
54
#if defined(MCUBOOT_ENCRYPT_EC256 ) || defined(MCUBOOT_ENCRYPT_X25519 )
55
55
#if defined(_compare )
56
56
static inline int bootutil_constant_time_compare (const uint8_t * a , const uint8_t * b , size_t size )
@@ -105,65 +105,64 @@ static const uint8_t ec_secp256r1_oid[] = MBEDTLS_OID_EC_GRP_SECP256R1;
105
105
* curve keypair. See RFC5208 and RFC5915.
106
106
*/
107
107
static int
108
- parse_ec256_enckey (uint8_t * * p , uint8_t * end , uint8_t * private_key )
108
+ parse_priv_enckey (uint8_t * * p , uint8_t * end , uint8_t * private_key )
109
109
{
110
- int rc ;
111
110
size_t len ;
112
111
int version ;
113
112
mbedtls_asn1_buf alg ;
114
113
mbedtls_asn1_buf param ;
115
114
116
- if (( rc = mbedtls_asn1_get_tag (p , end , & len ,
117
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) {
115
+ if (mbedtls_asn1_get_tag (p , end , & len ,
116
+ MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) != 0 ) {
118
117
return -1 ;
119
118
}
120
119
121
120
if (* p + len != end ) {
122
- return -2 ;
121
+ return -1 ;
123
122
}
124
123
125
124
version = 0 ;
126
125
if (mbedtls_asn1_get_int (p , end , & version ) || version != 0 ) {
127
- return -3 ;
126
+ return -1 ;
128
127
}
129
128
130
- if (( rc = mbedtls_asn1_get_alg (p , end , & alg , & param ) ) != 0 ) {
131
- return -5 ;
129
+ if (mbedtls_asn1_get_alg (p , end , & alg , & param ) != 0 ) {
130
+ return -1 ;
132
131
}
133
132
134
133
if (alg .ASN1_CONTEXT_MEMBER (len ) != sizeof (ec_pubkey_oid ) - 1 ||
135
134
memcmp (alg .ASN1_CONTEXT_MEMBER (p ), ec_pubkey_oid , sizeof (ec_pubkey_oid ) - 1 )) {
136
- return -6 ;
135
+ return -1 ;
137
136
}
138
137
if (param .ASN1_CONTEXT_MEMBER (len ) != sizeof (ec_secp256r1_oid ) - 1 ||
139
138
memcmp (param .ASN1_CONTEXT_MEMBER (p ), ec_secp256r1_oid , sizeof (ec_secp256r1_oid ) - 1 )) {
140
- return -7 ;
139
+ return -1 ;
141
140
}
142
141
143
- if (( rc = mbedtls_asn1_get_tag (p , end , & len , MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) {
144
- return -8 ;
142
+ if (mbedtls_asn1_get_tag (p , end , & len , MBEDTLS_ASN1_OCTET_STRING ) != 0 ) {
143
+ return -1 ;
145
144
}
146
145
147
146
/* RFC5915 - ECPrivateKey */
148
147
149
- if (( rc = mbedtls_asn1_get_tag (p , end , & len ,
150
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) {
151
- return -9 ;
148
+ if (mbedtls_asn1_get_tag (p , end , & len ,
149
+ MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) != 0 ) {
150
+ return -1 ;
152
151
}
153
152
154
153
version = 0 ;
155
154
if (mbedtls_asn1_get_int (p , end , & version ) || version != 1 ) {
156
- return -10 ;
155
+ return -1 ;
157
156
}
158
157
159
158
/* privateKey */
160
159
161
- if (( rc = mbedtls_asn1_get_tag (p , end , & len , MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) {
162
- return -11 ;
160
+ if (mbedtls_asn1_get_tag (p , end , & len , MBEDTLS_ASN1_OCTET_STRING ) != 0 ) {
161
+ return -1 ;
163
162
}
164
163
165
164
if (len != NUM_ECC_BYTES ) {
166
- return -12 ;
165
+ return -1 ;
167
166
}
168
167
169
168
memcpy (private_key , * p , len );
@@ -180,7 +179,7 @@ static const uint8_t ec_pubkey_oid[] = MBEDTLS_OID_ISO_IDENTIFIED_ORG \
180
179
MBEDTLS_OID_ORG_GOV X25519_OID ;
181
180
182
181
static int
183
- parse_x25519_enckey (uint8_t * * p , uint8_t * end , uint8_t * private_key )
182
+ parse_priv_enckey (uint8_t * * p , uint8_t * end , uint8_t * private_key )
184
183
{
185
184
size_t len ;
186
185
int version ;
@@ -193,33 +192,33 @@ parse_x25519_enckey(uint8_t **p, uint8_t *end, uint8_t *private_key)
193
192
}
194
193
195
194
if (* p + len != end ) {
196
- return -2 ;
195
+ return -1 ;
197
196
}
198
197
199
198
version = 0 ;
200
199
if (mbedtls_asn1_get_int (p , end , & version ) || version != 0 ) {
201
- return -3 ;
200
+ return -1 ;
202
201
}
203
202
204
203
if (mbedtls_asn1_get_alg (p , end , & alg , & param ) != 0 ) {
205
- return -4 ;
204
+ return -1 ;
206
205
}
207
206
208
207
if (alg .ASN1_CONTEXT_MEMBER (len ) != sizeof (ec_pubkey_oid ) - 1 ||
209
208
memcmp (alg .ASN1_CONTEXT_MEMBER (p ), ec_pubkey_oid , sizeof (ec_pubkey_oid ) - 1 )) {
210
- return -5 ;
209
+ return -1 ;
211
210
}
212
211
213
212
if (mbedtls_asn1_get_tag (p , end , & len , MBEDTLS_ASN1_OCTET_STRING ) != 0 ) {
214
- return -6 ;
213
+ return -1 ;
215
214
}
216
215
217
216
if (mbedtls_asn1_get_tag (p , end , & len , MBEDTLS_ASN1_OCTET_STRING ) != 0 ) {
218
- return -7 ;
217
+ return -1 ;
219
218
}
220
219
221
220
if (len != EC_PRIVK_LEN ) {
222
- return -8 ;
221
+ return -1 ;
223
222
}
224
223
225
224
memcpy (private_key , * p , EC_PRIVK_LEN );
@@ -455,8 +454,9 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
455
454
* Load the stored EC256 decryption private key
456
455
*/
457
456
458
- rc = parse_ec256_enckey (& cp , cpend , private_key );
457
+ rc = parse_priv_enckey (& cp , cpend , private_key );
459
458
if (rc ) {
459
+ BOOT_LOG_ERR ("Failed to parse ASN1 private key" );
460
460
return rc ;
461
461
}
462
462
@@ -482,8 +482,9 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
482
482
* Load the stored X25519 decryption private key
483
483
*/
484
484
485
- rc = parse_x25519_enckey (& cp , cpend , private_key );
485
+ rc = parse_priv_enckey (& cp , cpend , private_key );
486
486
if (rc ) {
487
+ BOOT_LOG_ERR ("Failed to parse ASN1 private key" );
487
488
return rc ;
488
489
}
489
490
@@ -580,7 +581,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
580
581
581
582
return rc ;
582
583
}
583
- #endif /* CONFIG_BOOT_ED25519_PSA */
584
+ #endif /* CONFIG_BOOT_ED25519_PSA && CONFIG_BOOT_ECDSA_PSA */
584
585
585
586
/*
586
587
* Load encryption key.
0 commit comments