7

I using a microcontroller which only support AES-ECB encryption i.e. no decryption-mode, CBC, GCM or similar modes.

However, I'm wondering if it's possible to implement AES-CTR or similar on top of AES-ECB?

I'm grateful for help, tips, similar implementations etc.

Cheers

2 Answers2

15

Yes, you can do this. In fact, implementing other cipher modes is precisely what ECB mode is good for (and, indeed, just about all it is good for).

To implement AES-CTR, simply fill an array of 128-bit blocks with increasing counter values, encrypt it with AES-ECB and XOR the resulting keystream with the plaintext (for encryption) or ciphertext (for decryption).

Ilmari Karonen
  • 46,700
  • 5
  • 112
  • 189
9

Of course you can implement CTR mode if all you have is ECB. All you have to do is use ECB to encrypt the successive counter values and use the resulting ECB-ciphertext as the CTR keystream to xor with the actual plaintext you want to encrypt. So for example, the first few counter values to encrypt with ECB would be (where $N$ is a 64 bit nonce / IV which is then concatenated with a 64 bit counter) $N || 0$, followed by $N || 1$, then $N || 2$ and so on.

Note that CTR mode doesn't require the decryption function of AES, so you're covered there too.

J.D.
  • 4,455
  • 18
  • 22