Topic: non-blocking usage, e.g. with WOLFSSL_SP_ARM_CORTEX_M_ASM
We are attempting to integrate WolfSSL on our automotive product using an NXP S32K344 CPU (Arm Cortex M7). This CPU has hardware support for some cryptographic functions, but we are not using these (yet).
It is important for our application that no call to the WolfSSL library blocks for too long. We therefore want to use as much as possible of the asynchronous features. Another restriction of our setup is that we use static memory allocation.
First we perform the following initialization steps:
- call wolfSSL_init();
- call wolfSSL_CTX_load_static_memory() to configure memory and initialize a WolfSSL context.
- call wolfSSL_CTX_load_verify_buffer_ex() to load a self-signed CA certificate (filetype ASN1)
Then we want to verify a certificate against the CA that has just been loaded. Ideally this could be done by using wolfSSL_CertManagerVerifyBuffer, but that doesn't work since it does not internally handle the WC_PENDING_E return value as a special case. Therefore, we do the following steps instead:
- call wc_InitDecodedCert to initialize a DecodedCert instance "decoded_certificate" containing our certificate.
- set "decoded_certificate.sigCtx.devId" to the value 0.
- call wc_ParseCert, expect return value WC_PENDING_E
- call wolfAsync_EventInit to initialize "decoded_certificate.sigCtx.asyncDev->event"
Then repeatedly call wolfAsync_EventPoll on "decoded_certificate.sigCtx.asyncDev->event".
(1) Is this the intended usage of the API? It appears unlogical that we need to access the fields of "decoded_certificate.sigCtx" directly, but I can not find a way to use asynchronous ECC computations without doing this.
Despite making the ECC computations asynchronous the call to wc_ParseCert is still too slow for us. This is potentially caused by the repeated computation of SHA256 hashes. We can install a callback handler using option WOLF_CRYPTO_CB, but as far as we can see it is not allowed for the hash function callback to return WC_PENDING_E.
(2) Is it correct that any hash function callback provided through "wc_CryptoCb_RegisterDevice" must be blocking?
(3) It appears like we could improve the performance a lot by using the WOLFSSL_SP_ARM_CORTEX_M_ASM option. However, the non-blocking implementation is not available. Concretely, we are missing the definition of struct sp_256_ecc_mulmod_8_ctx and the function sp_256_ecc_mulmod_8_nb (wolfcrypt + wolfasynccrypt v5.6.6).