crypto_hmac_sha256 not working

了解更多FAQsTutorials

4 posts / 0 new
Last post
托马斯唐豪瑟
Offline
Last seen:1个月2周前
加入:2019-10-20 10:45
crypto_hmac_sha256 not working

你好支持!

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标志,os_tick_time超时){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(超时)!= os_mutex_taken){return -1;} / *启用引擎时钟和适配器事件处理* / 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.

我也试图解决它是由某些不同的预先执行的

hw_aes_hash_init(&s); // s : hw_aes_hash_setup

但到目前为止没有运气。

Thank you,

Thomas

设备:
PM_Dialog
Offline
Last seen:10小时4分钟前
Staff
加入:2018-02-08 11:03
托马斯,

托马斯,

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

- 使用带DA14683子板的DA1468X Pro-DK

- da1468x_da15xxx_sdk_1.0.14.1081

- 使用BLE_PERITITAL,该项目\ DK_APPS \特征\ BLE_PERICATELAL SDK路径

b]导入Crypto_hmac库

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.从“Project Explorer”窗口中展开BLE_Peripheral文件夹,然后右键单击到BLE_PERITELAL \ SDK。在此文件夹下添加一个新子文件夹。请参阅b_1.png照片。

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.项目树应该像b_3.png,应该添加加密驱动程序。

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.将路径位置更改为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修改

1. Include the crypto_hmac.h into ble_peripheral_task.c

#include "crypto_hmac.h"

2. In custom_config_qspi.h :

#define dg_configUSE_HW_AES_HASH (1)

3. In the ble_peripheral_task before the for(;;) loop add the following code snippet.

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) { printf("Failed"); } else { printf("Succeeded"); }

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.应命中断点,应成功执行Crypto_hmac_sha256()。

Please follow the procedure described and let me know with your feedback.

Thanks, PM_Dialog

Attachment:
托马斯唐豪瑟
Offline
Last seen:1个月2周前
加入:2019-10-20 10:45
嗨pm_dialog,

嗨pm_dialog,

您是完美的权利,它的工作方式如上所述和预期。最后它在我的应用程序中工作。哪里错了?

I do some AES-256 decryption before hmac calculation anddid notcallhw_aes_hash_disable_clock();然后。这导致了崩溃。添加此函数后,调用Everthing工作正常。

我唯一不确定的是,如果我的参数设置是对的,如果hw_aes_hash ...()函数的顺序也可以吗?

s.mode = HW_AES_CBC; s.aesKeySize = HW_AES_256; s.aesKeyExpand = HW_AES_DO_NOT_PERFORM_KEY_EXPANSION; s.aesKeys = (uint32)&aesKey; s.aesIvCtrblk_0_31 = 0x01020304; s.aesIvCtrblk_32_63 = 0x05060708; s.aesIvCtrblk_64_95 = 0x090A0B0C; s.aesIvCtrblk_96_127 = 0x0D0E0FA1; s.aesWriteBackAll = true; s.moreDataToCome = false; s.sourceAddress = 0; s.destinationAddress = 0; s.dataSize = 0; s.enableInterrupt = false; s.callback = 0; uint8_t e2[] = { 0x26,0x9d,0xf3,0x2b,0x94,0xe9,0xcd,0xde, 0x7a,0xd2,0x6f,0xe8,0x7a,0x7e,0x8d,0xa8, 0x1f,0xe1,0xca,0xb7,0xbf,0xa7,0x4f,0xc7, 0x17,0xf3,0xd4,0x2f,0xbb,0xe6,0xc3,0xc7, 0x39,0x7a,0x92,0xfe,0x54,0x98,0xc7,0xf8, 0x2f,0x13,0x93,0x15,0x3a,0x43,0xb0,0x3e }; s.aesDirection = HW_AES_DECRYPT; s.sourceAddress = (uint32)&e2; s.destinationAddress = (uint32)&d; s.dataSize = 32; hw_aes_hash_init(&s); hw_aes_hash_start(); while(hw_aes_hash_is_active()){}; hw_aes_hash_disable_clock(); // *************** HMAC on SHA256 ***************** uint8_t txt[] = "what do ya want for nothing?"; uint8_t key[] = "Jefe"; uint8_t hma2c[32]; memset(hma2c,0,sizeof(hma2c)); crypto_hmac_ctx_t hmac_status = crypto_hmac_sha256(txt, 28, key, 4, hma2c, CRYPTO_HMAC_NO_OPTION, 100); if (hmac_status == -1) { printf("Failed"); } else { printf("Succeeded"); }

谢谢!

Thomas

PM_Dialog
Offline
Last seen:10小时4分钟前
Staff
加入:2018-02-08 11:03
托马斯,

托马斯,

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