int mbedtls_aes_setkey_dec(
    mbedtls_aes_context* ctx,
    const unsigned char* key,
    unsigned int keyLength
)
1.0、参考
1.1、此函数的作用

设置解密key

1.2、参数说明

mbedtls_aes_context* ctx必须调用mbedtls_aes_init(&ctx)进行初始化。

const unsigned char* key是用于解密的密钥

unsigned int keyLengthconst unsigned char* key的长度,单位是bit。 该值只能是1281922563个之一。

1.3、返回值说明

0表示成功。

MBEDTLS_ERR_AES_INVALID_KEY_LENGTH表示传入的keyLength不符合要求。

1.4、使用示例
#include <stdio.h>
#include <string.h>
#include "aes.h"

int main() {
    const char* key = "abcdefghijklmnop";
    size_t keyLength = strlen(key);

    mbedtls_aes_context aes;

    if (1 == mbedtls_aes_init(&aes)) {
        perror("init failed.");
        return 1;
    }

    int resultCode = mbedtls_aes_setkey_dec(&aes, (unsigned char*)key, keyLength<< 3);
    if (0 == resultCode) {
        printf("success\n");
    } else {
        printf("error\n");
    }
    return 0;
}