Skip to content

Homemade implementation of Square Attack against 4 rounds AES

License

Notifications You must be signed in to change notification settings

thomasperrot/aes-square-attack

Repository files navigation

AES Square Attack

Python3.5+ compatible Continuous Integration Status Coverage Status MIT License Code style black

Homemade implementation of Square Attack against 4 rounds AES

Overview

This repository is a simple implementation of the Square Attack against 4 rounds AES, based on this amazing website (all credits goes to David Wong). The source code gathers all the functions to encrypt using 128-bit AES algorithm, and a module dedicated to square attack.

The source code has absolutely no documentation, as all you need is already provided in the above mention website, and documenting is pretty boring.

Quickstart

To install the package:

pip install .

This attack is a chosen plaintext attack, so you must find a way to encrypt the initial delta set. To do this, implement your own function, respecting the following signature:

from typing import Iterable, List
from aes.common import State

def encrypt_delta_set(delta_set: Iterable[State]) -> List[State]:
    ...

As an example, the one implemented in this source code is just a homemade AES that encrypts the delta set using a supplied key. Use functools.partial if you need extra arguments (see tests/functional/test_crack_key.py).

Once it is done, you can perform the attack using the following snippet:

import binascii
from functools import partial

from aes.square import crack_key

def encrypt_delta_set(delta_set: Iterable[State]) -> List[State]:
    ...

cracked_key = crack_key(encrypt_delta_set)
print(f"[+] Found key: {binascii.hexlify(cracked_key)}")

Issues

If you encounter an issue, please fill free to open an issue.

About

Homemade implementation of Square Attack against 4 rounds AES

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published