Commit b111f98f authored by Sherry Zhang's avatar Sherry Zhang Committed by Dávid Vincze
Browse files

boot: Add the support of MBEDTLS version 3.0.0



Signed-off-by: default avatarSherry Zhang <sherry.zhang2@arm.com>
Change-Id: Idd7ce989fe259e9003732e80beaf3dccdedd3050
parent 50b06aea
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright (c) 2021 Arm Limited
 */

#ifndef __BOOTUTIL_CRYPTO_COMMON_H__
#define __BOOTUTIL_CRYPTO_COMMON_H__

/* TODO May need to update this in a future 3.x version of Mbed TLS.
 * Extract a member of the mbedtls context structure.
 */
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
#define MBEDTLS_CONTEXT_MEMBER(X) MBEDTLS_PRIVATE(X)
#else
#define MBEDTLS_CONTEXT_MEMBER(X) X
#endif

#endif /* __BOOTUTIL_CRYPTO_COMMON_H__ */
 No newline at end of file
+13 −1
Original line number Diff line number Diff line
@@ -70,6 +70,10 @@ static inline int bootutil_ecdh_p256_shared_secret(bootutil_ecdh_p256_context *c
#if defined(MCUBOOT_USE_MBED_TLS)
#define NUM_ECC_BYTES 32

#if MBEDTLS_VERSION_NUMBER >= 0x03000000
static int fake_rng(void *p_rng, unsigned char *output, size_t len);
#endif

typedef struct bootutil_ecdh_p256_context {
    mbedtls_ecp_group grp;
    mbedtls_ecp_point P;
@@ -122,13 +126,21 @@ static inline int bootutil_ecdh_p256_shared_secret(bootutil_ecdh_p256_context *c

    mbedtls_mpi_read_binary(&ctx->d, sk, NUM_ECC_BYTES);

#if MBEDTLS_VERSION_NUMBER >= 0x03000000
    rc = mbedtls_ecdh_compute_shared(&ctx->grp,
                                     &ctx->z,
                                     &ctx->P,
                                     &ctx->d,
                                     fake_rng,
                                     NULL);
#else
    rc = mbedtls_ecdh_compute_shared(&ctx->grp,
                                     &ctx->z,
                                     &ctx->P,
                                     &ctx->d,
                                     NULL,
                                     NULL);

#endif
    mbedtls_mpi_write_binary(&ctx->z, z, NUM_ECC_BYTES);

    return rc;
+4 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@

#if defined(MCUBOOT_USE_MBED_TLS)
    #include <mbedtls/ecdsa.h>
    #include "bootutil/crypto/common.h"
    #define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8)
#endif

@@ -132,17 +133,17 @@ static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx,
    (void)sig;
    (void)hash;

    rc = mbedtls_ecp_group_load(&ctx->grp, MBEDTLS_ECP_DP_SECP256R1);
    rc = mbedtls_ecp_group_load(&ctx->MBEDTLS_CONTEXT_MEMBER(grp), MBEDTLS_ECP_DP_SECP256R1);
    if (rc) {
        return -1;
    }

    rc = mbedtls_ecp_point_read_binary(&ctx->grp, &ctx->Q, pk, pk_len);
    rc = mbedtls_ecp_point_read_binary(&ctx->MBEDTLS_CONTEXT_MEMBER(grp), &ctx->MBEDTLS_CONTEXT_MEMBER(Q), pk, pk_len);
    if (rc) {
        return -1;
    }

    rc = mbedtls_ecp_check_pubkey(&ctx->grp, &ctx->Q);
    rc = mbedtls_ecp_check_pubkey(&ctx->MBEDTLS_CONTEXT_MEMBER(grp), &ctx->MBEDTLS_CONTEXT_MEMBER(Q));
    if (rc) {
        return -1;
    }
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
    #include <stddef.h>
    #include <mbedtls/cmac.h>
    #include <mbedtls/md.h>
    #include <mbedtls/md_internal.h>
#endif /* MCUBOOT_USE_MBED_TLS */

#if defined(MCUBOOT_USE_TINYCRYPT)
+5 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
 *
 * Copyright (c) 2017-2019 Linaro LTD
 * Copyright (c) 2017-2019 JUUL Labs
 * Copyright (c) 2021 Arm Limited
 */

/*
@@ -27,6 +28,10 @@

#if defined(MCUBOOT_USE_MBED_TLS)
    #include <mbedtls/sha256.h>
    #include <mbedtls/version.h>
    #if MBEDTLS_VERSION_NUMBER >= 0x03000000
        #include <mbedtls/compat-2.x.h>
    #endif
    #define BOOTUTIL_CRYPTO_SHA256_BLOCK_SIZE (64)
    #define BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE (32)
#endif /* MCUBOOT_USE_MBED_TLS */
Loading