This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
在035工程上添加mbedtls 2.16.0后调用
void aes_cbc_encrypt(const unsigned char *plaintext, size_t plaintext_len, unsigned char *ciphertext, size_t *ciphertext_len, const unsigned char key[16]) { unsigned char iv[IV_SIZE] = {0}; mbedtls_aes_context aes; mbedtls_aes_init(&aes); // 1. 设置加密密钥 mbedtls_aes_setkey_enc(&aes, key, 128); // 2. PKCS7填充 size_t padded_len = ((plaintext_len + 15) / 16) * 16; unsigned char padded[padded_len]; memcpy(padded, plaintext, plaintext_len); memset(padded + plaintext_len, padded_len - plaintext_len, padded_len - plaintext_len); // 3. 加密 mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_ENCRYPT, padded_len, iv, padded, ciphertext); *ciphertext_len = padded_len; mbedtls_aes_free(&aes); } unsigned char MiYao[] = {0xE1, 0xFF, 0xCA, 0xF2, 0x5F, 0xA4, 0x2A, 0x92, 0x47, 0x02, 0x9C, 0xAD, 0x10, 0x34,0x30}; // 秘钥 unsigned char A[] = {0x02}; // 带加密数据 unsigned char *ciphertext = NULL; size_t ciphertext_len = 0; void Aes_Test(void) { aes_cbc_encrypt(A,(size_t)1,ciphertext,&ciphertext_len,MiYao); } //在主循环中调用一次Aes_Test主循环寻中调佣 void vMain_Loop(void) { //局部变量定义 static Uint16 u16S12V_count =0;//12V急停开关量计数 static Uint16 u16TempTest = 0;// Uint32 u32PFCpowerMIN =0; if(u16TempTest == 0) { u16TempTest = 1; Aes_Test(); } }
1已尝试添加mbedtls库在2.16.0版本可以在不调用库的时候不报错,调用报错ebss
void aes_cbc_encrypt(const unsigned char *plaintext, size_t plaintext_len, unsigned char *ciphertext, size_t *ciphertext_len, const unsigned char key[16]) { unsigned char iv[IV_SIZE] = {0}; mbedtls_aes_context aes; mbedtls_aes_init(&aes); // 1. 设置加密密钥 mbedtls_aes_setkey_enc(&aes, key, 128); // 2. PKCS7填充 size_t padded_len = ((plaintext_len + 15) / 16) * 16; unsigned char padded[padded_len]; memcpy(padded, plaintext, plaintext_len); memset(padded + plaintext_len, padded_len - plaintext_len, padded_len - plaintext_len); // 3. 加密 mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_ENCRYPT, padded_len, iv, padded, ciphertext); *ciphertext_len = padded_len; mbedtls_aes_free(&aes); } unsigned char MiYao[] = {0xE1, 0xFF, 0xCA, 0xF2, 0x5F, 0xA4, 0x2A, 0x92, 0x47, 0x02, 0x9C, 0xAD, 0x10, 0x34,0x30}; // 秘钥 unsigned char A[] = {0x02}; // 带加密数据 unsigned char *ciphertext = NULL; size_t ciphertext_len = 0; void Aes_Test(void) { aes_cbc_encrypt(A,(size_t)1,ciphertext,&ciphertext_len,MiYao); } void vMain_Loop(void) { //局部变量定义 static Uint16 u16S12V_count =0;//12V急停开关量计数 static Uint16 u16TempTest = 0;// Uint32 u32PFCpowerMIN =0; if(u16TempTest == 0) { u16TempTest = 1; Aes_Test(); }
您好,
1 c2000系列芯片没有集成MbedTLS的示例。
2 TMS320F28035不支持,请参考Understanding Security Features for C2000 Real-Time Control MCUs (Rev. E)