Skip to main content

crypto_hmac_sha256不工作

1年前

crypto_hmac_sha256不工作

Posted by托马斯Donhauser0 points 3回复
0旋转

Hello Support!

如文档所示的代码不起作用。

uint8_t txt [] =“你什么都不想要什么?”UINT8_T键[] =“杰杰”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){//未能在100 ticks中获取AES /哈希引擎} else {//一切都很好}

执行停止在Crypto_hmac.c上的第64行停止在AD_CRYPTO_ACQUIER_AES_HASH(超时)。

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();

我找不到显示正确使用的其他代码样本,我请你帮助我。如果你能告诉我如何计算SHA256,我非常欣赏。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.

谢谢,

托马斯

accepted answer!

1年前

PM_DIALOG.

Hi Thomas,

感谢您对我们的公共蓝牙论坛的问题。我遵循doxygen sdk文件才能使用crypto_hmac库,但我无法重现你提到的问题。我在非BLE(Freertos_Retarger)和BLE(BLE_PERITELAL)SDK示例中测试。请确保您遵循正确的步骤。附有您的方便您会找到一些屏幕截图。

a] HW / SW设置

- 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.打开SmartSnippets Studio(SSS)并导入BLE_PERITERAL。我建议使用Clean SDK安装或从现有的SDK中删除.metadata。

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.在弹出窗口中,展开“高级”选项。请参阅b_2.png。您应该将Crypto SDK文件夹添加为链接资源。

4. The project tree should be like B_3.png and the crypto driver should be have added.

5.从“Project Explorer”窗口中右键单击BLE_PERITELAL并转到“属性”

6.可以在绝对路径位置(b_6.png)中设置Crypto驱动程序

7. Change the path location as B_7.png

8.在包含的包含中添加Crypto驱动程序,如b_8_i.png,b_8_ii.png和b_8_iii.png所示

C] SW modifications

1.将crypto_hmac.h添加到ble_peripheral_task.c中

#include“crypto_hmac.h”

2.在custom_config_qspi.h中:

#define dg_configuse_hw_aes_hash(1)

3.在for(;;)循环之前在ble_peripheral_task中添加以下代码片段。

UINT8_T TXT [] =“你什么都不想要什么?”;uint8_t键[] =“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(“失败”);} else {printf(“成功”);}

4.为DA14683-00-Debug-QSPI配置构建项目。

5.启动调试会话,并将断点添加到“成功”中

6. The breakpoint should be hit and the crypto_hmac_sha256() should be executed successfully.

请按照所描述的程序进行操作,并通过您的反馈让我知道。

谢谢,PM_DIALOG.

附件 尺寸
crypto.zip. 379.21 KB.

1年前

托马斯Donhauser 0 points

Hi PM_Dialog,

You are perfektly right and it works as described and expected. And finally it works in my App. What was wrong?

我在HMAC计算之前做了一些AES-256解密没有称呼hw_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?

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"); }

Thank you!

托马斯

1年前

PM_DIALOG.

Hi Thomas,

很高兴它正在工作,谢谢你接受我的答案。我看到你创建了一个新的论坛线程(链接下面提供)。我会在新的回复你。

https://support.dialog-semicondiondiondum/forums/post/dialog-smartbond-bluetooth-low-energy -%ee2%80%93-software/aes-cbc-no-padding.

谢谢,PM_DIALOG.