Go Down

Topic: new AES library (Read 15 times) previous topic - next topic

MarkT

I've written an AES (Advanced Encryption Standard) library for Arduino.  It supports 128, 192 and 256 bit key sizes.  Code space overhead is about 4KB I think, each instance requires 240 bytes RAM for subkeys.  Fairly tightly coded and checked against official test vectors for ECB mode.  Also CBC mode supported.

Its derived from Brian Gladman's implementation for byte-oriented processors but signficantly modified.  See the README and examples.

Functions:
Code: [Select]

  byte set_key (byte key[], int keylen) ;
  void clean () ;  // delete key schedule after use
  void copy_n_bytes (byte * dest, byte * src, byte n) ;

  byte encrypt (byte plain [N_BLOCK], byte cipher [N_BLOCK]) ;
  byte cbc_encrypt (byte * plain, byte * cipher, int n_block, byte iv [N_BLOCK]) ;

  byte decrypt (byte cipher [N_BLOCK], byte plain [N_BLOCK]) ;
  byte cbc_decrypt (byte * cipher, byte * plain, int n_block, byte iv [N_BLOCK]) ;


Lives here: http://utter.chaos.org.uk:/~markt/AES-library.zip

Feedback welcome.
[ I won't respond to messages, use the forum please ]

robtillaart

Nice work, not tested it (if i only had time ...),

have you tried it in communication (serial/ethernet/SD/...) yet? especially with other device PC/Mac/pinguin
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

MarkT

Its tested against many of the test-vectors (key varying, plaintext varying, Monte Carlo), which is the only contract it needs to fulfil...  I've some speed/timing information now:

128 bit, key setup 0.37ms
128 bit, ECB, encryption  0.58ms / block (27.5kB/s)
128 bit, ECB, decryption  0.77ms / block (20.5kB/s)

192 bit, key setup 0.41ms
192 bit, ECB, encryption  0.71ms / block (22.5kB/s)
192 bit, ECB, decryption  0.92ms / block (17.5kB/s)

256 bit, key setup 0.52ms
256 bit, ECB, encryption  0.82ms / block (19.5kB/s)
256 bit, ECB, decryption  1.09ms / block (14.5kB/s)

(CBC modes are a little slower than ECB)

(All ATmega328p, 16MHz)
[ I won't respond to messages, use the forum please ]

robtillaart


good speed, given that the Arduino/Mega only have a few KB of RAM, it can encode total RAM within a second.

Arduino can make approx 9000 (18KB) of analogRead samples per second [ @100% ] so I think it can keep up with 3-4000 samples/second.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

MarkT

Glad you like it.  Next project is elliptic curve public key cryptography! (Only half joking)
[ I won't respond to messages, use the forum please ]

Go Up