Hello Support!
The code as shown in documentation does not work.
uint8_t txt[] = "what do ya want for nothing?" uint8_t key[] = "Jefe" uint8_t hmac[32]; crypto_hmac_ctx_t hmac_status = crypto_hmac_sha256(txt, 28, key, 4, hmac, CRYPTO_HMAC_NO_OPTION, 100); if (hmac_status == -1) { // Failed to acquire the AES/HASH engine within 100 ticks } else { // Everything is fine }
Execution stops on line 64 in crypto_hmac.c at ad_crypto_acquire_aes_hash(timeout).
crypto_hmac_ctx_t crypto_hmac_sha256(const uint8_t *text, size_t text_sz, const uint8_t *key, size_t key_sz, uint8_t *hmac, unsigned int flags, OS_TICK_TIME timeout) { int i; uint8_t k0[CRYPTO_HMAC_SHA256_BLOCK_SZ]; uint8_t h_k0_ipad[CRYPTO_HMAC_SHA256_BLOCK_SZ]; uint8_t *h_k0_opad = NULL; if (ad_crypto_acquire_aes_hash(timeout) != OS_MUTEX_TAKEN) { return -1; } /* Enable engine clock and adapter event handling */ ad_crypto_enable_aes_hash_event();
我找不到任何其他tha代码示例t show the right usage and I ask you to help me. I very much appreciate if you could show me how to calculate a SHA256 resp. HMAC.
I also tried to solve it be some different pre-configs executed by
hw_aes_hash_init(&s); // s : hw_aes_hash_setup
but had no luck so far.
Thank you,
Thomas
Device:
Hi Thomas,
Thanks for your question on our public Bluetooth forums. I have followed the Doxygen SDK files in order to use the crypto_hmac library, but I am not able to reproduce the issue that you mentioned. I’ve tested in both non-BLE (freertos_retarger) and BLE (ble_peripheral) SDK examples. Please make sure that you are following the correct steps. Attached you will find some screenshots for your convenience.
A] HW/SW Setup
- DA1468x Pro-DK with DA14683 daughterboard are used
- DA1468x_DA15xxx_SDK_1.0.14.1081
- ble_peripheral is used which is under projects\dk_apps\features\ble_peripheral SDK path
B] Importing the crypto_hmac library
1.Open the SmartSnippets Studio (SSS) and import the ble_peripheral. I would recommend using a clean SDK install or delete the .metadata from the existing one.
2. Expand the ble_peripheral folder from the “Project Explorer” window and right-click to the ble_peripheral\sdk. Add a new sub-folder under this folder. Refer to B_1.png photo.
3. In the pop-up window expand the advanced option. Please refer to B_2.png. You should add the crypto SDK folder as linked resources.
4. The project tree should be like B_3.png and the crypto driver should be have added.
5. Right-click in the ble_peripheral from the “Project Explorer” window and go to the “Properties”
6. The crypto driver might be set in absolute path location (B_6.png)
7. Change the path location as B_7.png
8. Add the crypto driver in the includes as shown in B_8_i.png, B_8_ii.png and B_8_iii.png
C] SW modifications
1.包括crypto_hmac.h ble_peripheral_task.c
2. In custom_config_qspi.h :
3. In the ble_peripheral_task before the for(;;) loop add the following code snippet.
4. Build the project for DA14683-00-Debug-QSPI configuration.
5. Initiate a debug session and the add a break point into the “Succeeded”
6. The breakpoint should be hit and the crypto_hmac_sha256() should be executed successfully.
Please follow the procedure described and let me know with your feedback.
Thanks, PM_Dialog
Hi PM_Dialog,
You are perfektly right and it works as described and expected. And finally it works in my App. What was wrong?
I do some AES-256 decryption before hmac calculation anddid notcallhw_aes_hash_disable_clock();afterwards. This leads to the crash. After adding this function call everthing works fine.
The only thing I'm not sure is if my parameters setting is right and if the order of hw_aes_hash...() functions is ok too?
Thank you!
Thomas
Hi Thomas,
Glad it is working and thank you for accepting my answer. I saw that you created a new forum thread (link is provided below). I will respond you in the new one.
https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bluetooth-low-energy-%E2%80%93-software/aes-cbc-no-padding
Thanks, PM_Dialog