From b852d222b4de535a6dbebca95b9f1caffcbae349 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Sat, 16 Jan 2016 08:44:35 +1000 Subject: [PATCH] Reduce the object state size of AES --- doc/crypto.dox | 32 ++++++++++++++++---------------- libraries/Crypto/AES.h | 4 ---- libraries/Crypto/AESCommon.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/doc/crypto.dox b/doc/crypto.dox index d4214d14..97da849f 100644 --- a/doc/crypto.dox +++ b/doc/crypto.dox @@ -71,9 +71,9 @@ Ardunino Mega 2560 running at 16 MHz are similar: - - - + + + @@ -86,10 +86,10 @@ Ardunino Mega 2560 running at 16 MHz are similar: - - - - + + + + @@ -128,9 +128,9 @@ All figures are for the Arduino Due running at 84 MHz:
Encryption AlgorithmEncryption (per byte)Decryption (per byte)Key SetupState Size (bytes)
AES128 (ECB mode)36.90us66.48us160.00us213
AES192 (ECB mode)44.20us80.35us166.54us245
AES256 (ECB mode)51.50us94.22us227.97us277
AES128 (ECB mode)33.28us63.18us160.00us181
AES192 (ECB mode)39.94us76.48us166.54us213
AES256 (ECB mode)46.61us89.78us227.97us245
ChaCha (20 rounds)14.87us14.88us43.74us132
ChaCha (12 rounds)10.38us10.38us43.74us132
ChaCha (8 rounds)8.13us8.14us43.74us132
AEAD AlgorithmEncryption (per byte)Decryption (per byte)Key SetupState Size (bytes)
ChaChaPoly41.23us41.23us902.55us255
GCM<AES128>186.47us186.42us1388.43us316
GCM<AES192>194.17us193.72us1628.67us348
GCM<AES256>201.47us201.02us1923.78us380
EAX<AES128>78.37us78.37us1445.15us300
GCM<AES128>183.25us182.80us1272.73us284
GCM<AES192>189.92us189.47us1492.60us316
GCM<AES256>196.59us196.13us1767.33us348
EAX<AES128>71.14us71.14us1329.44us268
EAX<Speck> (128-bit key)26.01us26.01us735.46us362
EAX<SpeckLowMemory> (128-bit key)75.08us75.07us1243.66us122
- - - + + + @@ -143,12 +143,12 @@ All figures are for the Arduino Due running at 84 MHz: - - - - - - + + + + + + diff --git a/libraries/Crypto/AES.h b/libraries/Crypto/AES.h index b46b2117..9db65897 100644 --- a/libraries/Crypto/AES.h +++ b/libraries/Crypto/AES.h @@ -47,10 +47,6 @@ protected: void keyScheduleCore(uint8_t *output, const uint8_t *input, uint8_t iteration); void applySbox(uint8_t *output, const uint8_t *input); /** @endcond */ - -private: - uint8_t state1[16]; - uint8_t state2[16]; }; class AES128 : public AESCommon diff --git a/libraries/Crypto/AESCommon.cpp b/libraries/Crypto/AESCommon.cpp index 02a946ba..98fe0511 100644 --- a/libraries/Crypto/AESCommon.cpp +++ b/libraries/Crypto/AESCommon.cpp @@ -133,8 +133,6 @@ AESCommon::AESCommon() */ AESCommon::~AESCommon() { - clean(state1); - clean(state2); } /** @@ -268,6 +266,8 @@ void AESCommon::encryptBlock(uint8_t *output, const uint8_t *input) const uint8_t *roundKey = schedule; uint8_t posn; uint8_t round; + uint8_t state1[16]; + uint8_t state2[16]; // Copy the input into the state and XOR with the first round key. for (posn = 0; posn < 16; ++posn) @@ -297,6 +297,8 @@ void AESCommon::decryptBlock(uint8_t *output, const uint8_t *input) const uint8_t *roundKey = schedule + rounds * 16; uint8_t round; uint8_t posn; + uint8_t state1[16]; + uint8_t state2[16]; // Copy the input into the state and reverse the final round. for (posn = 0; posn < 16; ++posn) @@ -324,8 +326,6 @@ void AESCommon::decryptBlock(uint8_t *output, const uint8_t *input) void AESCommon::clear() { clean(schedule, (rounds + 1) * 16); - clean(state1); - clean(state2); } /** @cond */
Encryption AlgorithmEncryption (per byte)Decryption (per byte)Key SetupState Size (bytes)
AES128 (ECB mode)6.65us11.00us35.15us220
AES192 (ECB mode)8.02us13.31us36.59us252
AES256 (ECB mode)9.39us15.6350.19us284
AES128 (ECB mode)5.71us10.41us34.73us188
AES192 (ECB mode)6.87us12.57us36.51us220
AES256 (ECB mode)8.04us14.7249.96us252
ChaCha (20 rounds)0.87us0.88us4.96us136
ChaCha (12 rounds)0.70us0.71us4.96us136
ChaCha (8 rounds)0.62us0.62us4.96us136
AEAD AlgorithmEncryption (per byte)Decryption (per byte)Key SetupState Size (bytes)
ChaChaPoly1.66us1.66us45.02us280
GCM<AES128>11.01us10.92us247.90us344
GCM<AES192>12.40us12.31us294.07us376
GCM<AES256>13.73us13.64us347.40us408
EAX<AES128>14.17us14.17us266.56us312
EAX<Speck> (128-bit key)2.65us2.65us79.38us384
EAX<SpeckLowMemory> (128-bit key)6.40us6.39us108.25us122
GCM<AES128>10.29us10.29us223.82us312
GCM<AES192>11.50us11.51us265.62us344
GCM<AES256>12.67us12.67us313.06us376
EAX<AES128>12.29us12.29us236.47us280
EAX<Speck> (128-bit key)2.65us2.65us79.46us384
EAX<SpeckLowMemory> (128-bit key)6.29us6.29us106.60us144
Hash AlgorithmHashing (per byte)Finalization State Size (bytes)
SHA10.94us62.55us 112