Exemple #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);
}
static int hashInit(wolfssl_TI_Hash *hash) {
    if(!wolfSSL_TI_CCMInit())return 1 ;
    hash->used = 0 ;
    hash->msg  = 0 ;
    hash->len  = 0 ;
    return 0 ;
}
static int  DesSetKey(Des* des, const byte* key, const byte* iv,int dir, int tri)
{
    if(!wolfSSL_TI_CCMInit())return 1 ;
    if ((des == NULL) || (key == NULL) || (iv == NULL))
        return BAD_FUNC_ARG;
    if(!((dir == DES_ENCRYPTION) || (dir == DES_DECRYPTION)))
        return BAD_FUNC_ARG;
    
    XMEMCPY(des->key, key, tri == DES_CFG_SINGLE ? DES_KEYLEN : DES3_KEYLEN) ;
    return DesSetIV(des, iv, tri);
}