fix: add support for mbedtls 3.x, migrated from 2.x#3
Open
finger563 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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.cto PSA-based SHA-256 and AES-128 ECB operations when available. - Switches
gen_secret.cto 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.