What is the most efficient (in cycles per byte) cryptographically secure symmetric cipher to implement using only 8-bit operations? Algorithms like TEA are great for embedded devices, but it is optimized for 32-bit operations. I am not looking for the most efficient implementation of an algorithm, but rather an algorithm which was designed with this in mind. The MCU in question is a 3.5 MHz Z80 with 16K RAM.

Looking this up, I found resources showing how to implement AES on 4-bit microcontrollers, and how to implement secure hashes on 8-bit microcontrollers, but neither of those answer my actual question.

  • $\begingroup$ Related: Is there any recent cryptographic algorithm especially designed for low-level processors? $\endgroup$
    – e-sushi
    Feb 23, 2018 at 13:30
  • $\begingroup$ @forest: if you happen to time AES, SPECK, or/and other contenders on your Z80 platform, please post the summary of your benchmarks (e.g. in an update of the question). $\endgroup$
    – fgrieu
    Feb 25, 2018 at 10:08
  • 2
    $\begingroup$ It's always amazing that there are still using the Zilog Z80. I've got one here embedded in a Philips MSX-2 computer (VG8235) which I used when I was 11/12 years old (it's the 3rd one, the previous ones having been tossed away by various buggers when I didn't have any room to store them). It's got one big advantage over modern CPU's: the I/O PIN's are fully buffered, these buggers are hard to destroy. One of mine survived a full short-out on the pins. $\endgroup$
    – Maarten Bodewes
    Feb 25, 2018 at 14:55

4 Answers 4


SPECK was actually designed with 8-bit CPUs in mind. I use Simon and Speck extensively, and there's example source code and comparisons out there, as well as a good paper. The references are good and will lead you the the original sources. AES is generally faster but takes more resources, which you may or may not have.

I do not use AES on a MCU because it will have state information unless it has an AES hardware core. It's easier to keep the changes of the feistel network just as register information and you then do not need to worry about eating into your valuable RAM space.


I second Richie Frame's observation that AES is an excellent choice. I'd use AES-128 in CTR mode, which has the advantage that decryption is the same as encryption (thus is as fast, contrary to some other modes).

Update: SPECK, considered in this other answer, is good if compactness or speed per encryption for narrow block size are the choice criteria. SPECK-32 can be competitive with AES from the standpoint of cycles/byte on a Z80 (as asked in the question) because the state fits in registers. But I doubt SPECK-128 can be competitive with AES from the standpoint of cycles/byte on a Z80, because the multi-bit rotation and large number of rounds are going to be show stoppers; and the state has to be in memory.

AES is good on 8-bit CPU (especially if a wide block is desired) because

  • It has a natural implementation with as the only data transformations: XOR between octets, and lookup of two 256-octet tables. Contrary to many modern ciphers, no word rotation is needed, which is extremely desirable in the context, in which that would be slow even when using assembly.
  • With an implementation (still natural) separating derivation of round subkeys from encryption itself, speed for large data will be hard to beat, thanks to the carefully crafted structure of AES.
  • Typical C compilers can generate fair code, and optimization is relatively easy.
  • With the precaution of locating the two 256-octet tables on page boundaries, a natural implementation on a CPU without data cache (such as the Z80) will typically exhibits no data timing dependency (but I have seen small caches, e.g. 16-octet, in the read path of Flash memory).

As illustration, here is reference code:

// ezAES: Public domain AES-128 encryption.
// C99-conformant. Well suited to 8-bit CPUs.
// CAUTION: vulnerable to fault attacks and side-channels, including
// Differential Power Analysis, and possibly data cache timing attack.

// Data types
typedef unsigned char octet_t;      // 8-bit octet
typedef octet_t ezAESblk_t[16];     // AES data block
typedef octet_t ezAESkey_t[16];     // key for AES-128
typedef octet_t ezAESsks_t[11*16];  // subkeys for AES-128

// Sbox for encryption, FIPS-197 figure 7
static const octet_t ezAESs[256] = {

// Tabulation of (x<<1)^((x>>7)*0x1B)
static const octet_t ezAESt[256] = {

// Round constants
static const octet_t ezAESr[10] = {

// encrypt one block
void ezAESenc
          ezAESblk_t    oC, // ciphertext output
    const ezAESblk_t    iP, // plaintext input
    const ezAESsks_t    iS  // round subkeys
    ) {
    ezAESblk_t vB;          // current state of the block
    ezAESblk_t vT;          // temporary
    octet_t vn;

    // first AddRoundKey
    vn = 16;
    do {
        vB[vn] = iP[vn] ^ iS[vn];
    } while( vn!=0 );

    // round loop, started 10 times; exits with break in the middle of the last round
    for( ; ; ) {

        // ShiftRows and SubBytes, performed 10 times
        vT[ 0] = ezAESs[vB[ 0]]; vT[ 1] = ezAESs[vB[ 5]]; vT[ 2] = ezAESs[vB[10]]; vT[ 3] = ezAESs[vB[15]];
        vT[ 4] = ezAESs[vB[ 4]]; vT[ 5] = ezAESs[vB[ 9]]; vT[ 6] = ezAESs[vB[14]]; vT[ 7] = ezAESs[vB[ 3]];
        vT[ 8] = ezAESs[vB[ 8]]; vT[ 9] = ezAESs[vB[13]]; vT[10] = ezAESs[vB[ 2]]; vT[11] = ezAESs[vB[ 7]];
        vT[12] = ezAESs[vB[12]]; vT[13] = ezAESs[vB[ 1]]; vT[14] = ezAESs[vB[ 6]]; vT[15] = ezAESs[vB[11]];

        if ( (vn += 16)==10*16 )

        // MixColumns and AddRoundKey, performed 9 times
#define EZAESMA(x) \
    vB[x+2] = vT[x+0]^vT[x+1];                  /* 1 1 0 0 */               \
    vB[x+3] = vT[x+2]^vT[x+3];                  /* 0 0 1 1 */               \
    vB[x+0] = ezAESt[vB[x+2]]^vT[x+1]^vB[x+3]   /* 2 3 1 1 */ ^iS[x+0+vn];  \
    vB[x+2] ^= ezAESt[vB[x+3]]^vT[x+3]          /* 1 1 2 3 */ ^iS[x+2+vn];  \
    vB[x+3] = vT[x+1]^vT[x+2];                  /* 0 1 1 0 */               \
    vT[x+3] ^= vT[x+0];                         /* 1 0 0 1 */               \
    vB[x+1] = ezAESt[vB[x+3]]^vT[x+2]^vT[x+3]   /* 1 2 3 1 */ ^iS[x+1+vn];  \
    vB[x+3] ^= ezAESt[vT[x+3]]^vT[x+0]          /* 3 1 1 2 */ ^iS[x+3+vn];
        EZAESMA( 0)
        EZAESMA( 4)
        EZAESMA( 8)
#undef EZAESMA
        // here the content of vT is immaterial

    // last AddRoundKey
    vn = 16;
    do  {
        oC[vn] = vT[vn] ^ iS[10*16+vn];
    } while( vn!=0 );

// prepare round subkeys
void ezAESkey (
          ezAESsks_t    oS, // round subkeys output
    const ezAESkey_t    iK  // key input
    ) {
    octet_t vj, vk;

    // first subkey is the key
    vj = 16;
    do {
        oS[vj] = iK[vj];
    while ( vj!=0 );

     // for each 4-octet word of each 10 other subkeys
    vk = 0;
    do  {
        if( (vj&15)==0 ) {
            oS[16+vj] = ezAESs[oS[13+vj]]^oS[  vj]^ezAESr[vk++];
            oS[17+vj] = ezAESs[oS[14+vj]]^oS[1+vj];
            oS[18+vj] = ezAESs[oS[15+vj]]^oS[2+vj];
            oS[19+vj] = ezAESs[oS[12+vj]]^oS[3+vj];
        else {
            oS[16+vj] = oS[12+vj]^oS[  vj];
            oS[17+vj] = oS[13+vj]^oS[1+vj];
            oS[18+vj] = oS[14+vj]^oS[2+vj];
            oS[19+vj] = oS[15+vj]^oS[3+vj];
    } while( ( vj += 4)!=10*16 );

// Minimal test and demo. Returns 0 for OK, 1 for error.
int ezAESchk(void) {
    // test values from FIPS-197 appendix C.1
    const ezAESkey_t key = {
    const ezAESblk_t plaintext = {
    const ezAESblk_t ciphertext = {
    ezAESsks_t subkeys;
    ezAESblk_t result;
    octet_t j, r;

    // derive the round subkeys
    ezAESkey( subkeys, key );

    // encrypt
    ezAESenc( result, plaintext, subkeys );

    // compare result and known-good ciphertext
    for( j = r = 0; j<16; ++j)
        r |= result[j] ^ ciphertext[j];

    return r!=0;    // 0 for OK, 1 for error
  • $\begingroup$ One of the issues with AES is, while it may be faster, having more state information requires more memory accesses. I have enough RAM that a kilobyte of state information is not the end of the world, but extremely frequent memory accesses can be harmful to speed. PUSH takes 11 cycles and POP takes 10 on the Z80 architecture, for example. Memory accesses take a minimum of 4 cycles. So while AES, with state information, may be faster in cycles-per-byte than another cipher, the memory access delays on a Z80 can reduce the effective throughput. I'd probably have to test it to see for sure. $\endgroup$
    – forest
    Feb 24, 2018 at 8:45
  • $\begingroup$ @forest: yes, memory accesses are costly, and AES is not designed to reduce them to the max on a machine with few registers. However the implementation of MixColumns (and its bundling with AddRoundKey) allows some locality. E.g. if we have registers to spare, in EZAESMA the first affectation of vB[x+2], the first two affectations of vB[x+3] and the affectation of vT[x+3] need not hit memory; these really are local temps. And in the end, because AES performs relatively few operations per octet of ciphertext, it can be faster than SIMON or SPECK on cycles/byte. $\endgroup$
    – fgrieu
    Feb 24, 2018 at 11:49

I do not have benchmarks on this particular processor, so this answer is opinion / guesswork.

Gimli is fast and low-memory, but is just a permutation. Ciphers can be pretty trivially implemented on top of it though. It was designed to be efficient on a wide variety of hardware, and there is a reference implementation for an 8-bit AVR microcontroller. Libhydrogen uses Gimli to construct all of its symmetric primitives, and is optimized for microcontroller use.

All of the eSTREAM profile 1 (software optimized) ciphers could also be considered, though I don't know about their relative performance on 8-bit microcontrollers as the eSTREAM performance tests page does not have any such benchmarks. Being a variant of Salsa ChaCha should also be considered.

Blake2s is a hash function optimized for 8-32-bit systems, and is quite fast.

One particular Arduino cryptographic library I found has some benchmarks of various ciphers, and ChaCha seems good there, though that's one particular set of implementations on a different platform and doesn't include Gimli.

  • $\begingroup$ From gimli.cr.yp.to/perf.html, for ATMega at least, it looks like Salsa20 is significantly faster than Gimli small, with Gimli fast requiring far too many bytes of ROM. It looks like Gimli wouldn't provide me with any advantages over Salsa20/ChaCha20. $\endgroup$
    – forest
    Feb 23, 2018 at 5:22

SAFER++ might also be a good choice as it has only 8-bit operations, however it requires 512 bytes of ROM for tables.

Speck has one rotation by 8 and one by 3 per round. Rotation by 8 was probably chosen so bytes can be swapped on 8-bit CPU. It is probably the most compact, which on microcontrollers is often more important than speed.

RC4 is also 8-bit friendly, but not considered secure.

AES is also good on 8-bit CPU, but smallest implementation is vulnerable to side-channel attacks (even more than typical big table based implementation).

  • $\begingroup$ The Z80 has really slow memory access, so large lookup table or state arrays aren't ideal. $\endgroup$
    – forest
    Aug 11, 2022 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.