8051 and AVR Cryptolibrary

Skein hash and ThreeFish block cipher NEW!

Skein is a proposed hash function, submitted to the SHA-3 competition. Based around a new block cipher called ThreeFish. Both will certainly receive attention and cryptoanalysis in the forthcoming SHA-3 process.

Although these are certainly more heavy-weight than needed for most of applications in this class of microcontrollers, it might be interesting to study them as a counterpoint of the much more lightweight ciphers presented on these pages. See the table at bottom of page for performance figures. A few more words on these implementations here.

Both implementations are for Skein-256-256 and ThreeFish 256 with 256-bit (32-byte) block and key size.


Data block and key length are 64 bits.


The XTEA cipher only slightly modified as an SDCC function, together with an appropriate header and an example test "application".

Both encryption and decryption is implemented; if only one of these is needed, comment the corresponding #define in xtea.h. The original implementation in C provided for reference.


  • include xtea.h into your application
  • define a secret key as an "initialized" array of 16 bytes (or 4 longints, or any similar scheme) in code memory
  • fill in 8 bytes of plaintext (ciphertext, if decription is to be used rather than encryption) into the global xtea_data.b array (alternatively, into the xtea_data.l.x and xtea_data.l.y long int variables)
  • call xtea(&key) (xtea_i(&key) for decryption)
  • ciphertext (plaintext in case of decryption) is now in the xtea_data.b array
Usage as pseudorandom number generator (pRNG):
  • it is enough to have only encryption selected using the #defines in xtea.h
  • define a secret key as above
  • before first usage, fill in the xtea_data.b array with "random" seed (e.g. based on timer, keyboard input, or similar "random" input), or store/restore the current value of seed in nonvolatile memory
  • to generate one pseudorandom number, call xtea(&key)
  • use (part of) the ciphertext as the pseudorandom number (observe proper "handling" (e.g. scaling) of pseudorandom numbers)
  • re-seed xtea_data.b xoring with "real randomness" regularly.


Data block and key length are 64 bits.


All implementations are for 96-bit data block and 96-bit key, based on 8-bit word size.
             tea.a51      xtea.a51      skipjack.a51  skipfast.a51   skipregs.a51   sea.a51-Sea   sea.a51-EDSea                  ThreeFish-256
size(bytes)  206          218           364           1428           1140           524           604                            2543
cycles       9350         6952          1682          788            788            7878          8250                           12760
kB/sec       2.9          3.8           15.9          33.8           33.8           5.1           4.8                            8.4

             tea_i.a51    xtea_i.a51    skipj_i.a51   skipf_i.a51    skipr_i.a51    sea.a51-iSea
size(bytes)  213          224           364           1444           1156           524
cycles       9436         7051          1683          804            804            7878
kB/sec       2.8          3.8           15.9          33.2           33.2           5.1

             tea.asm      xtea.asm                    skipfast.asm                  sea.asm-Sea   sea.asm-EDSea   sea.asm-Sea2   ThreeFish-256
size(bytes)  2*94=188     2*103=206                   2*942=1884                    2*417=834     2*453=906       2*225=450      2*2446=4892
cycles       6861         6347                        901                           9658          9937            10906          10564
kB/sec       18.7         20.2                        142.1                         19.9          19.3            17.6           48.5

Please note, that SEA uses 96-bit key, while TEA and SkipJack use only 64-bit key. ThreeFish-256 uses a 256-bit key.
Remark: kB/sec values are based on 20MHz 6-clock '51(RD2) and 16MHz AVR.