|
43 | 43 |
|
44 | 44 | #elif defined(MCUBOOT_USE_MBED_TLS) |
45 | 45 |
|
46 | | -#include "mbedtls/rsa.h" |
47 | | -#include "mbedtls/version.h" |
| 46 | +#include "mbedtls/private/rsa.h" |
48 | 47 | #if defined(BOOTUTIL_CRYPTO_RSA_CRYPT_ENABLED) |
49 | | -#if MBEDTLS_VERSION_NUMBER >= 0x03000000 |
50 | 48 | #include "rsa_alt_helpers.h" |
51 | | -#else |
52 | | -#include "mbedtls/rsa_internal.h" |
53 | | -#endif |
54 | 49 | #endif /* BOOTUTIL_CRYPTO_RSA_CRYPT_ENABLED */ |
55 | 50 | #include "mbedtls/asn1.h" |
56 | 51 | #include "bootutil/crypto/common.h" |
@@ -235,9 +230,7 @@ bootutil_rsa_parse_private_key(bootutil_rsa_context *ctx, uint8_t **p, uint8_t * |
235 | 230 | } |
236 | 231 |
|
237 | 232 | /* Non-optional fields. */ |
238 | | - if ( /* version */ |
239 | | - mbedtls_asn1_get_int(p, end, &ctx->MBEDTLS_CONTEXT_MEMBER(ver)) != 0 || |
240 | | - /* public modulus */ |
| 233 | + if ( /* public modulus */ |
241 | 234 | mbedtls_asn1_get_mpi(p, end, &ctx->MBEDTLS_CONTEXT_MEMBER(N)) != 0 || |
242 | 235 | /* public exponent */ |
243 | 236 | mbedtls_asn1_get_mpi(p, end, &ctx->MBEDTLS_CONTEXT_MEMBER(E)) != 0 || |
@@ -288,6 +281,31 @@ bootutil_rsa_parse_private_key(bootutil_rsa_context *ctx, uint8_t **p, uint8_t * |
288 | 281 | #endif /* BOOTUTIL_CRYPTO_RSA_CRYPT_ENABLED */ |
289 | 282 |
|
290 | 283 | #if defined(BOOTUTIL_CRYPTO_RSA_SIGN_ENABLED) |
| 284 | + |
| 285 | +#include <mbedtls/private/error_common.h> |
| 286 | + |
| 287 | +static int mbedtls_rsa_import(mbedtls_rsa_context *ctx, |
| 288 | + const mbedtls_mpi *N, |
| 289 | + const mbedtls_mpi *P, const mbedtls_mpi *Q, |
| 290 | + const mbedtls_mpi *D, const mbedtls_mpi *E) |
| 291 | +{ |
| 292 | + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 293 | + |
| 294 | + if ((N != NULL && (ret = mbedtls_mpi_copy(&ctx->MBEDTLS_CONTEXT_MEMBER(N), N)) != 0) || |
| 295 | + (P != NULL && (ret = mbedtls_mpi_copy(&ctx->MBEDTLS_CONTEXT_MEMBER(P), P)) != 0) || |
| 296 | + (Q != NULL && (ret = mbedtls_mpi_copy(&ctx->MBEDTLS_CONTEXT_MEMBER(Q), Q)) != 0) || |
| 297 | + (D != NULL && (ret = mbedtls_mpi_copy(&ctx->MBEDTLS_CONTEXT_MEMBER(D), D)) != 0) || |
| 298 | + (E != NULL && (ret = mbedtls_mpi_copy(&ctx->MBEDTLS_CONTEXT_MEMBER(E), E)) != 0)) { |
| 299 | + return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); |
| 300 | + } |
| 301 | + |
| 302 | + if (N != NULL) { |
| 303 | + ctx->MBEDTLS_CONTEXT_MEMBER(len) = mbedtls_mpi_size(&ctx->MBEDTLS_CONTEXT_MEMBER(N)); |
| 304 | + } |
| 305 | + |
| 306 | + return 0; |
| 307 | +} |
| 308 | + |
291 | 309 | /* |
292 | 310 | * Parse a RSA public key with format specified in RFC3447 A.1.1 |
293 | 311 | */ |
|
0 commit comments