Esempio n. 1
0
WOLFSSL_API int  wc_AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
                              int dir)
{
    if(!wolfSSL_TI_CCMInit())return 1 ;
    if ((aes == NULL) || (key == NULL) || (iv == NULL))
        return BAD_FUNC_ARG;
    if(!((dir == AES_ENCRYPTION) || (dir == AES_DECRYPTION)))
        return BAD_FUNC_ARG;

    switch(len) {
        case 16:
            aes->keylen = AES_CFG_KEY_SIZE_128BIT ;
            break ;
        case 24:
            aes->keylen = AES_CFG_KEY_SIZE_192BIT ;
            break ;
        case 32:
            aes->keylen = AES_CFG_KEY_SIZE_256BIT ;
            break ;
        default:
            return BAD_FUNC_ARG;
    }

    XMEMCPY(aes->key, key, len) ;
#ifdef WOLFSSL_AES_COUNTER
    aes->left = 0;
#endif /* WOLFSSL_AES_COUNTER */
    return AesSetIV(aes, iv);
}
Esempio n. 2
0
/* AES Iv Set, sometimes added later */
int CRYPT_AES_IvSet(CRYPT_AES_CTX* aes, const unsigned char* iv)
{
    if (aes == NULL || iv == NULL)
        return BAD_FUNC_ARG;

    return AesSetIV((Aes*)aes, iv);
}