CH582 CH592 CH573 BLE AES硬件加密算法应用

WCH BLE系列芯片自带AES128算法,使用前必须开启BLE功能。

接口函数

/**
 * @brief   Encrypt data
 *
 * @param   key - key
 * @param   plaintextData - original data
 * @param   encryptData - encrypted data
 *
 * @return  Command Status.
 */
extern bStatus_t LL_Encrypt( uint8_t *key, uint8_t *plaintextData, uint8_t *encryptData );

/**
 * @brief   Decrypt data
 *
 * @param   key - key
 * @param   plaintextData - original data
 * @param   decryptData - decrypted data
 *
 * @return  Command Status.
 */
extern bStatus_t LL_Decrypt( uint8_t *key, uint8_t *plaintextData, uint8_t *decryptData );

使用(16字节加密)

    uint8_t key[16] = {0X00,0X11,0X22,0X33,0X44,0X55,0X66,0X77,0X88,0X99,0XAA,0XBB,0XCC,0XDD,0XEE,0XFF};
    //?需要加密的数据(保证16个字节,不够的自己填充)
    uint8_t source_buf[16]={0X00,0X01,0X02,0X03,0X04,0X05,0X06,0X07,0X08,0X09,0X0A,0X0B,0X0C,0X0D,0X0E,0X0F};
    uint8_t enc_buf[16];
    uint8_t en_buf[16];


    LL_Encrypt(key,source_buf,enc_buf);
    PRINT(" LL_Encrypt:\n");
    for(state=0;state<16;state++)
    {
        PRINT(" %x  ", enc_buf[state]);
    }
    PRINT(" \n ");

    LL_Decrypt(key,enc_buf,en_buf);
    PRINT(" LL_Decrypt:\n");
    for(state=0;state<16;state++)
    {
        PRINT(" %x  ", en_buf[state]);
    }
    PRINT(" \n ");

 

posted @ 2024-09-24 09:42  debugdabiaoge  阅读(40)  评论(0编辑  收藏  举报