wolfssl: Support AES_ECB
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019 Sean Parkinson, wolfSSL Inc.
|
* Copyright (C) 2019 Sean Parkinson, wolfSSL Inc.
|
||||||
|
* Copyright (C) 2021 Andreas Steffen, strongSec GmbH
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -47,7 +48,7 @@ struct private_wolfssl_crypter_t {
|
|||||||
* wolfSSL cipher
|
* wolfSSL cipher
|
||||||
*/
|
*/
|
||||||
union {
|
union {
|
||||||
#if !defined(NO_AES) && (!defined(NO_AES_CBC) || defined(WOLFSSL_AES_COUNTER))
|
#if !defined(NO_AES) && (!defined(NO_AES_CBC) || defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_COUNTER))
|
||||||
Aes aes;
|
Aes aes;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CAMELLIA
|
#ifdef HAVE_CAMELLIA
|
||||||
@@ -128,6 +129,18 @@ METHOD(crypter_t, decrypt, bool,
|
|||||||
success = (ret == 0);
|
success = (ret == 0);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
|
||||||
|
case ENCR_AES_ECB:
|
||||||
|
ret = wc_AesSetKey(&this->cipher.aes, this->key.ptr, this->key.len,
|
||||||
|
iv.ptr, AES_DECRYPTION);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
ret = wc_AesEcbDecrypt(&this->cipher.aes, out, data.ptr,
|
||||||
|
data.len);
|
||||||
|
}
|
||||||
|
success = (ret == 0);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
||||||
case ENCR_AES_CTR:
|
case ENCR_AES_CTR:
|
||||||
if (out == data.ptr)
|
if (out == data.ptr)
|
||||||
@@ -248,6 +261,18 @@ METHOD(crypter_t, encrypt, bool,
|
|||||||
success = (ret == 0);
|
success = (ret == 0);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
|
||||||
|
case ENCR_AES_ECB:
|
||||||
|
ret = wc_AesSetKey(&this->cipher.aes, this->key.ptr, this->key.len,
|
||||||
|
iv.ptr, AES_ENCRYPTION);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
ret = wc_AesEcbEncrypt(&this->cipher.aes, out, data.ptr,
|
||||||
|
data.len);
|
||||||
|
}
|
||||||
|
success = (ret == 0);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
||||||
case ENCR_AES_CTR:
|
case ENCR_AES_CTR:
|
||||||
if (out == data.ptr)
|
if (out == data.ptr)
|
||||||
@@ -365,6 +390,11 @@ METHOD(crypter_t, destroy, void,
|
|||||||
wc_AesFree(&this->cipher.aes);
|
wc_AesFree(&this->cipher.aes);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
|
||||||
|
case ENCR_AES_ECB:
|
||||||
|
wc_AesFree(&this->cipher.aes);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
||||||
case ENCR_AES_CTR:
|
case ENCR_AES_CTR:
|
||||||
wc_AesFree(&this->cipher.aes);
|
wc_AesFree(&this->cipher.aes);
|
||||||
@@ -418,6 +448,24 @@ wolfssl_crypter_t *wolfssl_crypter_create(encryption_algorithm_t algo,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
|
||||||
|
case ENCR_AES_ECB:
|
||||||
|
switch (key_size)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
key_size = 16;
|
||||||
|
/* fall-through */
|
||||||
|
case 16:
|
||||||
|
case 24:
|
||||||
|
case 32:
|
||||||
|
block_size = AES_BLOCK_SIZE;
|
||||||
|
iv_size = AES_IV_SIZE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
||||||
case ENCR_AES_CTR:
|
case ENCR_AES_CTR:
|
||||||
switch (key_size)
|
switch (key_size)
|
||||||
@@ -504,6 +552,11 @@ wolfssl_crypter_t *wolfssl_crypter_create(encryption_algorithm_t algo,
|
|||||||
ret = wc_AesInit(&this->cipher.aes, NULL, INVALID_DEVID);
|
ret = wc_AesInit(&this->cipher.aes, NULL, INVALID_DEVID);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
|
||||||
|
case ENCR_AES_ECB:
|
||||||
|
ret = wc_AesInit(&this->cipher.aes, NULL, INVALID_DEVID);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
|
||||||
case ENCR_AES_CTR:
|
case ENCR_AES_CTR:
|
||||||
ret = wc_AesInit(&this->cipher.aes, NULL, INVALID_DEVID);
|
ret = wc_AesInit(&this->cipher.aes, NULL, INVALID_DEVID);
|
||||||
|
|||||||
@@ -80,6 +80,11 @@ METHOD(plugin_t, get_features, int,
|
|||||||
PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 24),
|
PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 24),
|
||||||
PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 32),
|
PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 32),
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
|
||||||
|
PLUGIN_PROVIDE(CRYPTER, ENCR_AES_ECB, 16),
|
||||||
|
PLUGIN_PROVIDE(CRYPTER, ENCR_AES_ECB, 24),
|
||||||
|
PLUGIN_PROVIDE(CRYPTER, ENCR_AES_ECB, 32),
|
||||||
|
#endif
|
||||||
#ifdef HAVE_CAMELLIA
|
#ifdef HAVE_CAMELLIA
|
||||||
PLUGIN_PROVIDE(CRYPTER, ENCR_CAMELLIA_CBC, 16),
|
PLUGIN_PROVIDE(CRYPTER, ENCR_CAMELLIA_CBC, 16),
|
||||||
PLUGIN_PROVIDE(CRYPTER, ENCR_CAMELLIA_CBC, 24),
|
PLUGIN_PROVIDE(CRYPTER, ENCR_CAMELLIA_CBC, 24),
|
||||||
|
|||||||
Reference in New Issue
Block a user