|
34 | 34 | #include "cc310_glue.h" |
35 | 35 | #define NUM_ECC_BYTES (4*8) |
36 | 36 | #endif |
| 37 | +#ifdef MCUBOOT_USE_NRF_EXTERNAL_CRYPTO |
| 38 | +#include "bl_crypto.h" |
| 39 | +#define NUM_ECC_BYTES (4*8) |
| 40 | +#endif |
| 41 | + |
37 | 42 | #include "bootutil_priv.h" |
38 | 43 |
|
39 | 44 | /* |
@@ -183,6 +188,7 @@ bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, size_t slen, |
183 | 188 | } |
184 | 189 | } |
185 | 190 | #endif /* MCUBOOT_USE_TINYCRYPT */ |
| 191 | + |
186 | 192 | #ifdef MCUBOOT_USE_CC310 |
187 | 193 | int |
188 | 194 | bootutil_verify_sig(uint8_t *hash, |
@@ -227,4 +233,50 @@ bootutil_verify_sig(uint8_t *hash, |
227 | 233 | return rc; |
228 | 234 | } |
229 | 235 | #endif /* MCUBOOT_USE_CC310 */ |
| 236 | + |
| 237 | +#ifdef MCUBOOT_USE_NRF_EXTERNAL_CRYPTO |
| 238 | +int |
| 239 | +bootutil_verify_sig(uint8_t *hash, |
| 240 | + uint32_t hlen, |
| 241 | + uint8_t *sig, |
| 242 | + size_t slen, |
| 243 | + uint8_t key_id) |
| 244 | +{ |
| 245 | + int rc; |
| 246 | + uint8_t *pubkey; |
| 247 | + uint8_t *end; |
| 248 | + uint8_t signature[2 * NUM_ECC_BYTES]; |
| 249 | + |
| 250 | + pubkey = (uint8_t *)bootutil_keys[key_id].key; |
| 251 | + end = pubkey + *bootutil_keys[key_id].len; |
| 252 | + |
| 253 | + rc = bootutil_import_key(&pubkey, end); |
| 254 | + if (rc) { |
| 255 | + return -1; |
| 256 | + } |
| 257 | + |
| 258 | + /* Decode signature */ |
| 259 | + rc = bootutil_decode_sig(signature, sig, sig + slen); |
| 260 | + if (rc) { |
| 261 | + return -1; |
| 262 | + } |
| 263 | + |
| 264 | + /* |
| 265 | + * This is simplified, as the hash length is also 32 bytes. |
| 266 | + */ |
| 267 | + if (hlen != NUM_ECC_BYTES) { |
| 268 | + return -1; |
| 269 | + } |
| 270 | + |
| 271 | + /* Initialize and verify in one go */ |
| 272 | + rc = bl_secp256r1_validate(hash, hlen, pubkey, signature); |
| 273 | + |
| 274 | + if(rc != 0 /*CRYS_OK*/){ |
| 275 | + return -2; |
| 276 | + } |
| 277 | + |
| 278 | + return rc; |
| 279 | +} |
| 280 | +#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */ |
| 281 | + |
230 | 282 | #endif /* MCUBOOT_SIGN_EC256 */ |
0 commit comments