From 86d6312da0263d76749f97eeb9722b35b8e0fefb Mon Sep 17 00:00:00 2001 From: Dakshit Babbar <100972343+DakshitBabbar@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:22:15 +0530 Subject: [PATCH] [mainline update] Populate RSA key attributes in mbedtls context (#1288) * Populate RSA key attributes in mbedtls context * Fix formatting --------- Co-authored-by: Rahul Kar --- .../network_transport/mbedtls_pk_pkcs11.c | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c b/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c index 1cea0e9d77..b352d26aa5 100644 --- a/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c +++ b/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c @@ -1062,24 +1062,22 @@ static CK_RV p11_rsa_ctx_init( mbedtls_pk_context * pk, xResult = CKR_FUNCTION_FAILED; } - /* - * TODO: corePKCS11 does not allow exporting RSA public attributes. - * This function should be updated to properly initialize the - * mbedtls_rsa_context when this is addressed. - */ - - /* CK_ATTRIBUTE pxAttrs[ 2 ] = */ - /* { */ - /* { .type = CKA_MODULUS, .ulValueLen = 0, .pValue = NULL }, */ - /* { .type = CKA_PUBLIC_EXPONENT, .ulValueLen = 0, .pValue = NULL }, */ - /* { .type = CKA_PRIME_1, .ulValueLen = 0, .pValue = NULL }, */ - /* { .type = CKA_PRIME_2, .ulValueLen = 0, .pValue = NULL }, */ - /* { .type = CKA_EXPONENT_1, .ulValueLen = 0, .pValue = NULL }, */ - /* { .type = CKA_EXPONENT_2, .ulValueLen = 0, .pValue = NULL }, */ - /* { .type = CKA_COEFFICIENT, .ulValueLen = 0, .pValue = NULL }, */ - /* }; */ - - ( void ) pxMbedRsaCtx; + CK_ATTRIBUTE pxAttrs[ 8 ] = + { + { .type = CKA_MODULUS, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->N ) }, + { .type = CKA_PUBLIC_EXPONENT, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->E ) }, + { .type = CKA_PRIME_1, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->P ) }, + { .type = CKA_PRIME_2, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->Q ) }, + { .type = CKA_PRIVATE_EXPONENT, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->D ) }, + { .type = CKA_EXPONENT_1, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->DP ) }, + { .type = CKA_EXPONENT_2, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->DQ ) }, + { .type = CKA_COEFFICIENT, .ulValueLen = sizeof( mbedtls_mpi ), .pValue = &( pxMbedRsaCtx->QP ) }, + }; + + xResult = pxFunctionList->C_GetAttributeValue( xSessionHandle, + xPkHandle, + pxAttrs, + sizeof( pxAttrs ) / sizeof( CK_ATTRIBUTE ) ); if( xResult == CKR_OK ) {