Repository navigation
mbedtls: call psa_crypto_init() in the AES-GCM and HMAC init paths - #826
Conversation
|
@pabuhler PTAL |
pabuhler
left a comment
There was a problem hiding this comment.
As you state this code is not really needed at present as there is no public API that needs these extra inits.
I think it is ok to add it but am not sure if the test is needed, it creates overhead for something that will get caught if any public API is ever added.
Also the test only really tests one of the invocations, would need to run it twice once for HMAC and once for GCM.
I would suggest removing it or else fixing it, if you fix then please include top of file comments similar to other files in the repo.
Only the AES-ICM backend initialized PSA. AES-GCM and HMAC relied on it having run first, which srtp_init() guarantees by self-testing AES-ICM before them. Using either type without srtp_init() made the key import fail: AES-GCM init returned srtp_err_status_init_fail and HMAC init srtp_err_status_auth_fail. Call psa_crypto_init() in both, as AES-ICM does. It is idempotent. 2_x_dev already does this (cisco#813).
2a048ed to
c490c45
Compare
@pabuhler Thanks, agreed. I removed the test, so the PR now only adds the two psa_crypto_init() calls. I updated the description to match. |
In the mbedTLS (PSA) backend, only
srtp_aes_icm_mbedtls_context_init()callspsa_crypto_init().srtp_aes_gcm_mbedtls_context_init()andsrtp_hmac_mbedtls_init()rely on it having run already.Through the public API that always holds:
srtp_init()self-tests AES-ICM before AES-GCM and HMAC, and that self-test initializes PSA. Using either type withoutsrtp_init()(for example from a test harness or a custom crypto kernel setup) fails, because the key import runs before PSA is initialized:srtp_err_status_init_fail.srtp_err_status_auth_fail.This calls
psa_crypto_init()in both, at the same point and with the same error handling as AES-ICM. It is idempotent, so thesrtp_init()path is unchanged. This bringsmainin line with2_x_dev, whose mbedTLS 4 / PSA path (#813) already calls it in all three backends.Testing: with a test harness that initialized both types without
srtp_init(), both inits failed without the fix and passed with it, on mbedTLS 4.1.0. After review that harness is no longer part of this PR, since no public API reaches these paths withoutsrtp_init(). With the fix, all ctest tests pass on mbedTLS 4.1.0 (ENABLE_WARNINGS_AS_ERRORS=ON) and on 3.6.3, and all meson tests pass on 4.1.0.