ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Cryptographic Library

Supported Algorithms

All cryptographic algorithms have been optimized for 8-bit Arduino platforms like the Uno. Memory usage is also reduced, particularly for SHA1, SHA256, and SHA512 which save 256, 192, and 512 bytes respectively over traditional implementations. For all algorithms, static sbox tables and the like are placed into program memory to further reduce data memory usage.

ChaCha with 20 rounds and 256-bit keys is the recommended symmetric encryption algorithm because it is twice as fast as AES128, constant-time, and much more secure. AES128, AES192, and AES256 are provided for use in applications where compatibility with other systems is desirable.

BLAKE2s and BLAKE2b are variations on the ChaCha stream cipher, designed for hashing, with 256-bit and 512-bit hash outputs respectively. They are intended as high performance replacements for SHA256 and SHA512 for when speed is critical but exact bit-compatibility of hash values is not.

Examples and other topics

Performance

Performance on AVR

All figures are for the Arduino Uno running at 16 MHz. Figures for the Ardunino Mega 2560 running at 16 MHz are similar:

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
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
Hash AlgorithmHashing (per byte)FinalizationState Size (bytes)
SHA121.90us1423.28us95
SHA25643.85us2841.04us107
SHA512122.82us15953.42us211
SHA3_256121.69us16486.33us405
SHA3_512229.12us16502.34us405
BLAKE2s18.54us1200.06us171
BLAKE2b50.70us6515.87us339
Authentication AlgorithmHashing (per byte)FinalizationKey SetupState Size (bytes)
SHA1 (HMAC mode)21.90us4296.33us1420.24us95
SHA256 (HMAC mode)43.85us8552.61us2836.49us107
BLAKE2s (HMAC mode)18.54us3649.98us1214.81us171
Poly130526.29us486.15us17.26us87
GHASH148.14us17.09us21.87us33
Public Key OperationTime (per operation)Comment
Curve25519::eval()3119msRaw curve evaluation
Curve25519::dh1()3121msFirst half of Diffie-Hellman key agreement
Curve25519::dh2()3120msSecond half of Diffie-Hellman key agreement
Ed25519::sign()5688msDigital signature generation
Ed25519::verify()9030msDigital signature verification
Ed25519::derivePublicKey()5642msDerive a public key from a private key

Where a cipher supports more than one key size (such as ChaCha), the values are typically almost identical for 128-bit and 256-bit keys so only the maximum is shown above.

Performance on ARM

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)6.65us11.00us35.15us220
AES192 (ECB mode)8.02us13.31us36.59us252
AES256 (ECB mode)9.39us15.6350.19us284
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
Hash AlgorithmHashing (per byte)FinalizationState Size (bytes)
SHA10.94us62.55us112
SHA2561.15us76.60us120
SHA5122.87us370.37us224
SHA3_2565.36us697.65us424
SHA3_5129.89us697.81us424
BLAKE2s0.76us50.88us184
BLAKE2b1.33us170.93us352
Authentication AlgorithmHashing (per byte)FinalizationKey SetupState Size (bytes)
SHA1 (HMAC mode)0.94us193.92us65.09us112
SHA256 (HMAC mode)1.15us238.98us80.44us120
BLAKE2s (HMAC mode)0.76us165.64us59.92us184
Poly13050.85us19.25us2.35us96
GHASH4.37us1.50us4.37us36
Public Key OperationTime (per operation)Comment
Curve25519::eval()103msRaw curve evaluation
Curve25519::dh1()103msFirst half of Diffie-Hellman key agreement
Curve25519::dh2()104msSecond half of Diffie-Hellman key agreement
Ed25519::sign()195msDigital signature generation
Ed25519::verify()306msDigital signature verification
Ed25519::derivePublicKey()194msDerive a public key from a private key