aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/aes
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-10-26 20:31:30 -0400
committerJack Lloyd <[email protected]>2017-10-26 22:26:15 -0400
commite6d45052efedfe49e99adb6318aaf56e0a9e8d7b (patch)
treec6c3ccd3cff3d04285940bf1d518c809e0653947 /src/lib/block/aes
parent315b002ecf00f6b6bb0f0d5200d1f39a83527e8f (diff)
Add checks that keyed algorithms are actually keyed before use
Previously calling update or encrypt without calling set_key first would result in invalid outputs or else crashing.
Diffstat (limited to 'src/lib/block/aes')
-rw-r--r--src/lib/block/aes/aes.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp
index 8a82ad942..9c375c362 100644
--- a/src/lib/block/aes/aes.cpp
+++ b/src/lib/block/aes/aes.cpp
@@ -452,6 +452,8 @@ size_t AES_256::parallelism() const { return aes_parallelism(); }
void AES_128::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
+ verify_key_set(m_EK.empty() == false);
+
#if defined(BOTAN_HAS_AES_NI)
if(CPUID::has_aes_ni())
{
@@ -478,6 +480,8 @@ void AES_128::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
void AES_128::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
+ verify_key_set(m_DK.empty() == false);
+
#if defined(BOTAN_HAS_AES_NI)
if(CPUID::has_aes_ni())
{
@@ -531,6 +535,8 @@ void AES_128::clear()
void AES_192::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
+ verify_key_set(m_EK.empty() == false);
+
#if defined(BOTAN_HAS_AES_NI)
if(CPUID::has_aes_ni())
{
@@ -557,6 +563,8 @@ void AES_192::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
void AES_192::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
+ verify_key_set(m_DK.empty() == false);
+
#if defined(BOTAN_HAS_AES_NI)
if(CPUID::has_aes_ni())
{
@@ -610,6 +618,8 @@ void AES_192::clear()
void AES_256::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
+ verify_key_set(m_EK.empty() == false);
+
#if defined(BOTAN_HAS_AES_NI)
if(CPUID::has_aes_ni())
{
@@ -636,6 +646,8 @@ void AES_256::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
void AES_256::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
+ verify_key_set(m_DK.empty() == false);
+
#if defined(BOTAN_HAS_AES_NI)
if(CPUID::has_aes_ni())
{