A paired engineering project completed at Grenoble INP – Esisar (PX222 Maths/Info, March – June 2026) by Jamyson Vetter and Siméon Studer. The project designs, validates, and profiles a complete encryption and decryption chain compliant with NIST FIPS PUB 197 across two complementary paradigms: pure functional algebraic modeling in Haskell and system-level performance engineering in C.
Architecture & Highlights
- Four-Layer Algebraic Modeling in Haskell: Strictly hierarchical, acyclic
module architecture built via polymorphic typeclasses (
Anneauwith explicit algebraic subtractionsub, andCorpswithinv). Instantiates prime fields \(\mathbb{Z}/2\mathbb{Z}\) (Z2.hs) and \(\mathbb{Z}/3\mathbb{Z}\) (Z3.hs) to prove characteristic-independent genericity, generic polynomial rings \(K[X]\) with canonical normalization and Euclidean division (de_polinPolynome.hs), the Galois field \(\text{GF}(2^8) \simeq (\mathbb{Z}/2\mathbb{Z}) [x]/(x^8+x^4+x^3+x+1)\) (GF28.hs), and the tail-recursive Extended Euclidean algorithm with monic Bézout normalization (inv_pinEuclide.hs). - Full NIST FIPS 197 Engine & Dynamic S-Box: Models 32-bit state columns
inside the non-integral quotient ring \(\text{GF}(2^8) [X]/(X^4+1)\) (
GF28X), allowingmixColumnsandinvMixColumnsto be expressed as single modular polynomial multiplications. ComputessubBytesandinvSubBytesdynamically by composing \(\text{GF}(2^8)\) inversion with affine transformations modeled as polynomial multiplications in \(\mathbb{F}_2[X]/(X^8+1)\) (alongside a static lookup alternative inSBox.hs). Supports AES-128 (10 rounds, 44 words), AES-192 (12 rounds, 52 words), and AES-256 (14 rounds, 60 words), plus automated C array code generation (export_key,export_state). - Automated GHCi Verification & NIST Test Vectors: Five bottom-up GHCi test
suites (
tests_complets.ghci) verifying ring/field axioms, formal Bézout identities over \(\mathbb{F}_2[X]\) and \(\mathbb{F}_3[X]\), round-by-round intermediate state matrices (NIST Appendices A & B), and full multi-key round-trip encryption/decryption (Appendix C). - C Implementation, Block Modes & Shannon Entropy: Contiguous-memory C
engine (
AES_en_c/) implementing both directInvCipherandEqInvCipher(Equivalent Inverse Cipher, solving row/column key-schedule transposition viaInvMixColumns_eq), ECB and CBC block cipher modes with strict PKCS#7 padding verification, and BMP pixel encryption (Tux.bmp, ~890.7 KB). First-order Shannon entropy rises from \(3.939\) bits/byte (raw image) to \(6.995\) bits/byte in ECB (retaining visual silhouette) and \(7.9998\) bits/byte (\(7.999785\)) in CBC (complete inter-block diffusion). - Profiling, Algorithmic Factorization & GCC Assembly Tuning: Call-graph
profiling with Valgrind (
Callgrind) andKCachegrindidentified \(>213\text{M}\) redundantxtime()calls insideInvMixColumnsand costly per-blockKeyExpansionrecomputation. Precomputing powers (\(x \cdot s_i, x^2 \cdot s_i, x^3 \cdot s_i\)) reducedInvMixColumnsto 12xtime()calls per column (a 6× reduction to \(35.5\text{M}\) calls, boosting decryption throughput 3.52×). Subsequent GCC (-O0to-O3) optimization analysis viaobjdump -M intel -dS(register allocation, function inlining, \(Nb=4\) loop unrolling, auto-vectorization) achieved 25.85 MB/s in encryption (\(0.036\text{ s}\)) and 23.66 MB/s in decryption (\(0.039\text{ s}\), a 5.4× speedup over-O0).
Technologies
Haskell · C · Abstract Algebra & GF(2⁸) · AES-128/192/256 (FIPS 197) ·
ECB / CBC & PKCS#7 · Shannon Entropy · Valgrind / KCachegrind ·
GCC & x86 Assembly · LaTeX
Technical Report & Documentation
The complete 31-page technical specification and performance report (PX222 Maths/Info – Implémentations d’AES en Haskell et en C, authored in LaTeX by Jamyson Vetter and Siméon Studer, March – June 2026) covers the algebraic proofs, module dependency graphs, NIST validation benches, ECB/CBC entropy experiments, KCachegrind call graphs, and x86 assembly benchmarks.
- 📥 Download Technical Report – Implémentations d’AES en Haskell et en C (PDF) (PDF, 31 pages, 2.3 MB)
- 🔗 GitHub Repository (Haskell & C Source Code) (Full source code, GHCi test benches, and C benchmarks)