Skip to content

fix: add support for mbedtls 3.x, migrated from 2.x#3

Open
finger563 wants to merge 2 commits into
espp-mainfrom
fix/mbedtls
Open

fix: add support for mbedtls 3.x, migrated from 2.x#3
finger563 wants to merge 2 commits into
espp-mainfrom
fix/mbedtls

Conversation

@finger563

Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings May 23, 2026 03:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the embedded mbedTLS-backed crypto implementation to support mbedTLS 3.x by introducing a PSA Crypto–based implementation path for SHA-256, AES-128 ECB, and secp256r1 ECDH shared-secret generation.

Changes:

  • Auto-detects availability of PSA Crypto headers and switches mbedtls.c to PSA-based SHA-256 and AES-128 ECB operations when available.
  • Switches gen_secret.c to PSA-based secp256r1 ECDH shared secret generation when PSA is available.
  • Keeps the existing mbedTLS 2.x-style implementations as a fallback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
embedded/common/source/mbedtls/mbedtls.c Adds PSA Crypto-backed SHA-256 and AES-128 ECB implementations with a fallback to mbedTLS APIs.
embedded/common/source/mbedtls/gen_secret.c Adds PSA Crypto-backed secp256r1 ECDH shared-secret generation with a fallback to mbedTLS APIs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +40 to +45
#if defined(__has_include)
#if __has_include(<psa/crypto.h>)
#define NEARBY_PLATFORM_USE_PSA_CRYPTO 1
#endif
#endif

Comment on lines +79 to +81
return psa_hash_update(&sha256_op, (const uint8_t*)data, length) == PSA_SUCCESS
? kNearbyStatusOK
: kNearbyStatusError;
Comment on lines +64 to +69
static nearby_platform_status nearby_platform_InitCrypto() {
return psa_crypto_init() == PSA_SUCCESS ? kNearbyStatusOK : kNearbyStatusError;
}

nearby_platform_status nearby_platform_Sha256Start() {
if (nearby_platform_InitCrypto() != kNearbyStatusOK) {
Comment on lines +34 to +43
#if defined(__has_include)
#if __has_include(<psa/crypto.h>)
#define NEARBY_PLATFORM_USE_PSA_CRYPTO 1
#endif
#endif

#if defined(NEARBY_PLATFORM_USE_PSA_CRYPTO)
#include <psa/crypto.h>
#include <string.h>
#else
Comment on lines +60 to +66
static nearby_platform_status nearby_platform_InitCrypto() {
return psa_crypto_init() == PSA_SUCCESS ? kNearbyStatusOK : kNearbyStatusError;
}

nearby_platform_status nearby_platform_GenSec256r1Secret(
const uint8_t remote_party_public_key[64], uint8_t shared_secret[32]) {
if (nearby_platform_InitCrypto() != kNearbyStatusOK) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants