Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of operations in mbedtls_pkcs5_pbkdf2_hmac does not release pico's SHA256 hardware lock #2103

Open
nilswiersma opened this issue Nov 27, 2024 · 2 comments

Comments

@nilswiersma
Copy link

The current way that the SHA256 hardware engine and the mbedtls implementation of mbedtls_pkcs5_pbkdf2_hmac interact with each other results in the situation where that function never releases the SHA256 engine lock. Below I included a trace of how functions are called in pico_mbedtls.c and in mbedtls' pkcs5.c.

You can see that it ends with a call to mbedtls_md_hmac_reset which claims the lock, but then it is never released. I would submit a pull request to address this, but I am not sure if it this a problem of mbedtls, or the link to the pico's SHA256 engine?

Iterations: '3'
Password: 'password' (length 8)
Salt: 686d6163dea2f2bf251b2275
KDF START

mbedtls_pkcs5_pbkdf2_hmac
mbedtls_md_hmac_starts
mbedtls_sha256_starts_ret
pico_sha256_lock
mbedtls_sha256_update_ret
mbedtls_md_hmac_update1
mbedtls_sha256_update_ret
mbedtls_md_hmac_update2
mbedtls_sha256_update_ret
mbedtls_md_hmac_finish1
mbedtls_sha256_finish_ret
pico_sha256_unlock
mbedtls_sha256_starts_ret
pico_sha256_lock
mbedtls_sha256_update_ret
mbedtls_sha256_update_ret
mbedtls_sha256_finish_ret
pico_sha256_unlock
mbedtls_md_hmac_reset1
mbedtls_sha256_starts_ret
pico_sha256_lock
mbedtls_sha256_update_ret
mbedtls_md_hmac_updater3
mbedtls_sha256_update_ret
mbedtls_md_hmac_finish2
mbedtls_sha256_finish_ret
pico_sha256_unlock
mbedtls_sha256_starts_ret
pico_sha256_lock
mbedtls_sha256_update_ret
mbedtls_sha256_update_ret
mbedtls_sha256_finish_ret
pico_sha256_unlock
mbedtls_md_hmac_reset2
mbedtls_sha256_starts_ret
pico_sha256_lock
mbedtls_sha256_update_ret
mbedtls_md_hmac_updater3
mbedtls_sha256_update_ret
mbedtls_md_hmac_finish2
mbedtls_sha256_finish_ret
pico_sha256_unlock
mbedtls_sha256_starts_ret
pico_sha256_lock
mbedtls_sha256_update_ret
mbedtls_sha256_update_ret
mbedtls_sha256_finish_ret
pico_sha256_unlock
mbedtls_md_hmac_reset2
mbedtls_sha256_starts_ret
pico_sha256_lock
mbedtls_sha256_update_ret

KDF took 111ms
@peterharperuk
Copy link
Contributor

It does look a bit like mbedtls_sha256_free should release the lock if needed. Is that your fix? PR would be welcome.

@nilswiersma
Copy link
Author

At the moment my fix is something hacky in the application that uses this library. Your suggestion sounds great, thanks! I will work on a PR.

nilswiersma pushed a commit to nilswiersma/pico-sdk that referenced this issue Nov 27, 2024
…y. Requires making pico_sha256_unlock include-able. Fixes raspberrypi#2103.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants