Skip to content

FibStack/learning-aes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning AES

This repository contains a sample implementation of the Advanced Encryption Standard (AES) described in the article.

Warning

The code here is for illustrative purpose only, DO NOT use in production.

  • Performance has been sacrificed in favour of readability.
  • No input validation or boundary checks are performed.
  • Test coverage is limited and does not include every edge case.

If you need AES for real applications, use the language specific standard library that takes advantage of hardware acceleration when available.

Repository layout

File Purpose
aes/sub_bytes.go Substitution‑byte tables and helper functions.
aes/round_keys.go Implementation of the KeyExpansion() routine and its helpers.
aes/cipher.go Core AES encryption Cipher() and supporting routines.
aes/inv_cipher.go AES decryption InvCipher() and related helpers.
aes/cipher_modes.go ECB, CBC, and CTR mode wrappers that use the block cipher.
main.go Demonstrates key derivation via PBKDF2, PKCS#7 padding, and compares encryption/decryption between Go’s standard library and this implementation for all three modes.

Playing with the code

Requirements: Go version 1.25.0 or up.

# Clone the repo
git clone https://github.com/FibStack/aes-tutorial.git
cd aes-tutorial

# Ensure module dependencies are downloaded
go mod tidy

# Run the demo program
go run main.go

You should see output similar to:


Generating salt, IV, and keys

Testing ECB cipher mode
ECB encryption worked with 128bit key.
ECB decryption worked with 128bit key.
ECB encryption worked with 192bit key.
ECB decryption worked with 192bit key.
ECB encryption worked with 256bit key.
ECB decryption worked with 256bit key.

Testing CBC cipher mode
CBC encryption worked with 128bit key.
CBC decryption worked with 128bit key.
CBC encryption worked with 192bit key.
CBC decryption worked with 192bit key.
CBC encryption worked with 256bit key.
CBC decryption worked with 256bit key.

Testing CTR cipher mode
CTR encryption worked with 128bit key.
CTR decryption worked with 128bit key.
CTR encryption worked with 192bit key.
CTR decryption worked with 192bit key.
CTR encryption worked with 256bit key.
CTR decryption worked with 256bit key.

To execute the unit tests, run:

go test ./aes

License

This project is released under the MIT License – see LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages