AES-128 Block Cipher

hard · cryptography, block-cipher, aes, bitwise

AES-128 Block Cipher

Implement AES-128 encryption and decryption for a single 16-byte block. You must not use any crypto library. Implement the AES round function and key schedule from scratch (FIPS-197).

Function signatures

func AES128EncryptBlock(key [16]byte, block [16]byte) [16]byte
func AES128DecryptBlock(key [16]byte, block [16]byte) [16]byte

AES conventions

  • Block size: 16 bytes.
  • Key size: 16 bytes (AES-128).
  • Number of rounds: 10.
  • State is a 4x4 byte matrix in column-major order: state[r + 4*c] is row r, column c.

Round structure

Initial round:

  • AddRoundKey

Rounds 1..9:

  • SubBytes
  • ShiftRows
  • MixColumns
  • AddRoundKey

Final round:

  • SubBytes
  • ShiftRows
  • AddRoundKey

Decryption uses inverse operations and round keys in reverse order.

Notes

  • Use GF(2^8) multiplication with modulus 0x11b.
  • Use the provided S-box and inverse S-box.
  • This is a learning exercise. Do not ship your own AES implementation.
Run tests to see results
No issues detected