|
49 | 49 | #include <openthread/platform/trel.h> |
50 | 50 | #include <openthread/platform/udp.h> |
51 | 51 |
|
| 52 | +#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) |
| 53 | +#include <psa/crypto.h> |
| 54 | +#endif |
| 55 | + |
52 | 56 | using namespace ot; |
53 | 57 |
|
54 | 58 | bool operator<(const otExtAddress &aLeft, const otExtAddress &aRight) |
@@ -480,6 +484,38 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) |
480 | 484 | return error; |
481 | 485 | } |
482 | 486 |
|
| 487 | +#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
| 488 | +/** |
| 489 | + * When OpenThread is compiled with the PSA Crypto backend using Mbed TLS 3.x, there is no |
| 490 | + * API to configure a dedicated non-default entropy source. It is documented that a future version of |
| 491 | + * Mbed TLS (likely 4.x) will include a PSA interface for configuring entropy sources. |
| 492 | + * |
| 493 | + * For now, we need to define the external RNG. Since the implementation of `otPlatEntropyGet` already |
| 494 | + * uses CSPRNG, we will call it here as well. |
| 495 | + */ |
| 496 | +extern "C" psa_status_t mbedtls_psa_external_get_random(mbedtls_psa_external_random_context_t *context, |
| 497 | + uint8_t *output, |
| 498 | + size_t output_size, |
| 499 | + size_t *output_length) |
| 500 | +{ |
| 501 | + OT_UNUSED_VARIABLE(context); |
| 502 | + |
| 503 | + otError error; |
| 504 | + psa_status_t status = PSA_ERROR_GENERIC_ERROR; |
| 505 | + |
| 506 | + error = otPlatEntropyGet(output, (uint16_t)output_size); |
| 507 | + if (error == OT_ERROR_NONE) |
| 508 | + { |
| 509 | + *output_length = output_size; |
| 510 | + status = PSA_SUCCESS; |
| 511 | + } |
| 512 | + |
| 513 | + return status; |
| 514 | +} |
| 515 | +#endif |
| 516 | + |
| 517 | +// otError otPlatCryptoExportKey(otCryptoKeyRef, uint8_t *, size_t, size_t *) { return OT_ERROR_NONE; } |
| 518 | + |
483 | 519 | void otPlatDiagSetOutputCallback(otInstance *, otPlatDiagOutputCallback, void *) {} |
484 | 520 |
|
485 | 521 | void otPlatDiagModeSet(bool) {} |
|
0 commit comments