Introduction
Implement AES-256, RSA, SHA-256/3, ECDSA, and Diffie-Hellman from mathematical primitives without using crypto libraries. This comprehensive guide covers everything from design through implementation, testing, and deployment.
Implement AES-256, RSA, SHA-256/3, ECDSA, and Diffie-Hellman from mathematical primitives without using crypto libraries.
Implement AES-256, RSA, SHA-256/3, ECDSA, and Diffie-Hellman from mathematical primitives without using crypto libraries. This comprehensive guide covers everything from design through implementation, testing, and deployment.
AES operates on 4×4 byte state matrices. Key expansion: generate 14 round keys from 256-bit master key using Rijndael key schedule. Each of 14 rounds applies 4 transformations: SubBytes (16-entry S-box substitution), ShiftRows (rotate each row left by its index), MixColumns (GF(2^8) matrix multiplication — most complex step), AddRoundKey (XOR with round key). Implement GF(2^8) arithmetic: multiplication uses XTIMES function and Russian peasant multiplication.
10 components required for this project.
| # | Component | Purpose | Qty |
|---|---|---|---|
| 1 | Python 3.10+ | Implementation language (easy big integers) | x1 |
| 2 | sympy (for prime generation) | Large prime number generation | x1 |
| 3 | pytest | NIST test vectors for validation | x1 |
| 4 | Hypothesis library | Property-based testing (encrypt then decrypt) | x1 |
| 5 | bitstring | Bit-level manipulation | x1 |
| 6 | Timing analysis tools | Side-channel vulnerability research | x1 |
| 7 | NIST FIPS standards | Algorithm specification documents | x1 |
| 8 | PyCryptodome (reference) | Reference implementation for test comparison | x1 |
| 9 | SageMath (optional) | Elliptic curve mathematics | x1 |
| 10 | Jupyter | Mathematical exploration | x1 |
Follow these 3 steps carefully.
AES operates on 4×4 byte state matrices. Key expansion: generate 14 round keys from 256-bit master key using Rijndael key schedule. Each of 14 rounds applies 4 transformations: SubBytes (16-entry S-box substitution), ShiftRows (rotate each row left by its index), MixColumns (GF(2^8) matrix multiplication — most complex step), AddRoundKey (XOR with round key). Implement GF(2^8) arithmetic: multiplication uses XTIMES function and Russian peasant multiplication.
Key generation: generate two large primes p, q (512 bits each for 1024-bit RSA). n = p×q. φ(n) = (p-1)(q-1). Choose e (typically 65537, must be coprime to φ(n)). Compute d = e^-1 mod φ(n) using Extended Euclidean Algorithm. Public key: (n, e). Private key: (n, d). Encrypt: C = M^e mod n. Decrypt: M = C^d mod n. Miller-Rabin primality test for large primes. Chinese Remainder Theorem for efficient decryption.
SHA-256 processes messages in 512-bit (64-byte) blocks. Preprocessing: append
Core code for aes.py:
Test Cryptography Library Implementation by verifying each subsystem individually before full integration.
Verify power voltages, check ground connections, use serial monitor for debug.
An interactive simulator will be available here — simulate circuits and run code in-browser without hardware.