- À Propos
- Fonctionnalités
- Architecture
- Installation
- Utilisation
- Modes Opératoires
- Performance
- Tests
- Structure du Projet
- Documentation Technique
- Références
- Contribution
- Licence
- Documentation
LibAES est une implémentation complète et optimisée de l'Advanced Encryption Standard (AES) écrite en C pur avec support des instructions AES-NI d'Intel et SIMD pour des performances maximales.
Cette bibliothèque offre une API simple et sécurisée pour :
- 🔒 Chiffrement/Déchiffrement de données
- 🛡️ Authentification (mode GCM)
- ⚡ Performance optimale via accélération matérielle
- 🎯 Support complet des standards NIST
- Zero Dependencies : Uniquement la libc standard
- Hardware Accelerated : Utilisation des instructions AES-NI et PCLMULQDQ
- Production Ready : 58 tests unitaires validés
- Standards Compliant : Compatible NIST SP 800-38A/D
- OpenSSL Validated : Tags GCM validés contre OpenSSL
| Algorithme | Tailles de Clé | Status |
|---|---|---|
| AES-ECB | 128, 192, 256 bits | ✅ |
| AES-CBC | 128, 192, 256 bits | ✅ |
| AES-CTR | 128, 192, 256 bits | ✅ |
| AES-OFB | 128, 192, 256 bits | ✅ |
| AES-CFB | 128, 192, 256 bits | ✅ |
| AES-GCM | 128, 192, 256 bits | ✅ |
- ✅ PKCS#7 Padding : Gestion automatique du padding
- ✅ GHASH : Authentification pour le mode GCM
- ✅ Multiplication Galois : Optimisée avec PCLMULQDQ
- ✅ AAD Support : Additional Authenticated Data pour GCM
- ✅ Random Number Generation : Support RDRAND/RDSEED
LibAES utilise les instructions Intel suivantes:
├── AES-NI (AESENC, AESDEC, AESENCLAST, AESDECLAST)
├── PCLMULQDQ (Carry-less multiplication pour GHASH)
├── SSSE3 (Shuffle pour byte-swapping)
└── AVX/AVX2 (Optimisations vectorielles)
- 🔥 AES-NI : Accélération matérielle du chiffrement AES
- ⚡ SIMD : Traitement parallèle des données
- 🎯 Prefetching : Optimisation du cache CPU
- 🔧 Zero-copy : Minimisation des copies mémoire
- Compilateur : GCC 7+ ou Clang 10+
- CPU : Processeur Intel/AMD avec support AES-NI
- Build System : Meson 0.55+ et Ninja
- Système : Linux (testé sur Ubuntu/Debian)
# Cloner le dépôt
git clone https://github.com/votre-repo/libaes.git
cd libaes
# Configuration avec Meson
meson setup build
# Compilation
meson compile -C build
# Installation (optionnel)
sudo meson install -C build# Lancer les tests
meson test -C build
# Résultat attendu : 58/58 tests passés ✅#include "aes.h"
#include <string.h>
int main(void)
{
aes_ctx_t ctx;
uint8_t key[16] = "SecretKey1234567";
uint8_t iv[16] = "InitVector123456";
uint8_t plaintext[32] = "Hello, World! This is AES!";
uint8_t ciphertext[32];
uint8_t decrypted[32];
// Initialisation
memset(&ctx, 0, sizeof(ctx));
ctx.key_size = AES_KEY_128;
ctx.pad = 1; // Activer PKCS#7 padding
memcpy(ctx.key.key_128, key, 16);
memcpy(ctx.iv, iv, 16);
// Expansion de la clé
aes_128_key_expansion(&ctx.key);
// Chiffrement
aes_cbc_enc(ciphertext, sizeof(ciphertext), ctx.iv,
plaintext, sizeof(plaintext), &ctx);
// Déchiffrement
memcpy(ctx.iv, iv, 16); // Réinitialiser l'IV
aes_cbc_dec(decrypted, sizeof(decrypted), ctx.iv,
ciphertext, sizeof(ciphertext), &ctx);
return 0;
}#include "aes.h"
#include <string.h>
int main(void)
{
aes_ctx_t ctx;
aes_gcm_counter_t gcm_out;
uint8_t key[32] = "MyVerySecretKey256bits!!!!!!!!";
uint8_t nonce[16] = {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
0xde, 0xca, 0xf8, 0x88, 0x00, 0x00, 0x00, 0x01};
uint8_t aad[] = "Additional Authenticated Data";
uint8_t plaintext[64] = "Confidential message to encrypt";
uint8_t ciphertext[64];
uint8_t tag[16];
// Configuration
memset(&ctx, 0, sizeof(ctx));
ctx.key_size = AES_KEY_256;
memcpy(ctx.key.key_256, key, 32);
aes_256_key_expansion(&ctx.key);
// Chiffrement avec authentification
gcm_out.out = ciphertext;
gcm_out.size = sizeof(ciphertext);
aes_gcm_enc(&gcm_out, nonce, aad, strlen((char*)aad),
plaintext, strlen((char*)plaintext), &ctx);
// Récupération du tag d'authentification
_mm_storeu_si128((__m128i*)tag, gcm_out.tag);
printf("Tag: ");
for (int i = 0; i < 16; i++)
printf("%02x", tag[i]);
printf("\n");
return 0;
}# Avec la bibliothèque installée
gcc -o myapp myapp.c -laes
# Sans installation (depuis le répertoire build)
gcc -o myapp myapp.c -I./inc -L./build -laes -Wl,-rpath,./build✅ Simple et rapide
⚠️ Non recommandé pour données > 1 bloc (patterns visibles)
📚 Usage: Chiffrement de clés, données aléatoires
✅ Sécurisé pour données de taille variable
✅ Support du padding PKCS#7
📚 Usage: Chiffrement de fichiers, données bulk
✅ Parallélisable (encryption ET decryption)
✅ Pas de padding nécessaire
📚 Usage: Streaming, disques chiffrés
✅ Chiffrement authentifié (AEAD)
✅ Détection de modifications
✅ Support AAD (données authentifiées non chiffrées)
📚 Usage: TLS 1.3, IPsec, communication sécurisée
⚡ Validé contre OpenSSL
✅ Mode stream cipher
✅ Erreur de transmission ne se propage pas
📚 Usage: Streaming en temps réel
✅ Mode stream cipher avec feedback
✅ Auto-synchronisation
📚 Usage: Chiffrement de flux de données
| Mode | Taille Clé | Débit | Latence/16B |
|---|---|---|---|
| ECB-128 | 128 bits | ~8 GB/s | 12 cycles |
| CBC-128 | 128 bits | ~6 GB/s | 18 cycles |
| CTR-128 | 128 bits | ~7 GB/s | 14 cycles |
| GCM-128 | 128 bits | ~5 GB/s | 22 cycles |
Note : Les performances varient selon le CPU. AES-NI offre une accélération de 3-10x par rapport à une implémentation software pure.
# Lancer tous les tests
meson test -C build
# Lancer des tests spécifiques
meson test -C build aes-gcm-test-suite
meson test -C build aes-cbc-test-suite
# Tests verbose
meson test -C build --verbose- ✅ 58 tests unitaires validés
- ✅ Vecteurs de test NIST SP 800-38A/D
- ✅ Validation croisée avec OpenSSL
- ✅ Tests de padding PKCS#7
- ✅ Tests multi-blocs et blocs partiels
- ✅ Tests AAD (Additional Authenticated Data)
Des tests de débogage et validation sont disponibles dans tests/manual/ :
cd tests/manual
gcc -o test_openssl_gcm test_openssl_gcm.c -lssl -lcrypto
./test_openssl_gcm # Compare avec OpenSSLVoir tests/manual/README.md pour plus de détails.
libaes/
├── 📂 inc/ # Headers publics
│ ├── aes.h # API principale
│ ├── gf.h # Galois Field operations
│ └── ...
├── 📂 src/ # Code source
│ ├── 📂 cbc/ # Mode CBC
│ ├── 📂 ctr/ # Mode CTR
│ ├── 📂 ecb/ # Mode ECB
│ ├── 📂 gcm/ # Mode GCM
│ │ ├── aes_gcm.c # Implémentation GCM
│ │ └── gfmul.c # Multiplication Galois (PCLMULQDQ)
│ ├── 📂 ofb/ # Mode OFB
│ ├── 📂 cfb/ # Mode CFB
│ ├── 📂 utils/ # Utilitaires
│ │ ├── aes_block.c # Helpers AES encrypt/decrypt
│ │ └── ...
│ ├── 📂 pkcs/ # PKCS#7 padding
│ ├── 📂 random/ # RDRAND/RDSEED
│ └── 📂 rc/ # Round Constants
├── 📂 tests/ # Tests unitaires
│ ├── 📂 aes_gcm/ # Tests GCM
│ ├── 📂 aes_cbc/ # Tests CBC
│ ├── 📂 aes_ctr/ # Tests CTR
│ ├── 📂 manual/ # Tests manuels et debug
│ └── ...
├── 📂 docs/ # Documentation technique
│ ├── Intel white papers
│ ├── NIST specifications
│ └── ...
├── meson.build # Configuration Meson
└── README.md # Ce fichier
- NIST FIPS 197 : Advanced Encryption Standard
- NIST SP 800-38A : Recommendation for Block Cipher Modes of Operation
- NIST SP 800-38D : Recommendation for Block Cipher Modes: Galois/Counter Mode (GCM)
Le mode GCM utilise une fonction de hachage universelle GHASH basée sur la multiplication dans GF(2^128). Notre implémentation :
- Utilise l'instruction PCLMULQDQ pour la multiplication carry-less
- Applique la réduction polynomiale avec le polynôme irréductible x^128 + x^7 + x^2 + x + 1
- Gère correctement les byte-swaps pour compatibilité big-endian
- Validée contre OpenSSL pour tous les vecteurs de test
L'expansion de clé utilise les instructions AES-NI :
AESKEYGENASSISTpour la génération des round keys- Support des 3 tailles (128, 192, 256 bits)
- Optimisation avec SIMD pour les opérations vectorielles
- Intel Intrinsics Guide - Cryptography
- NIST AES Standard (FIPS 197)
- NIST SP 800-38D - GCM Specification
- AES Key Schedule Explained - Braincoke
- AES Key Expansion - BrainKart
- Wikipedia - AES Key Schedule
- Wikipedia - Advanced Encryption Standard
- Wikipedia - Modes d'opération
- Advanced Encryption Standard Instructions (AES-NI)
- Carry-Less Multiplication Instruction (PCLMULQDQ)
- Optimized GHASH Function Technology Guide
Les contributions sont les bienvenues ! Voici comment participer :
- 🍴 Fork le projet
- 🔧 Créez une branche pour votre feature (
git checkout -b feature/AmazingFeature) - ✅ Committez vos changements (
git commit -m 'Add some AmazingFeature') - 📤 Push vers la branche (
git push origin feature/AmazingFeature) - 🎉 Ouvrez une Pull Request
- Suivre le style de code existant (C18, indentation tabs)
- Ajouter des tests pour toute nouvelle fonctionnalité
- Mettre à jour la documentation si nécessaire
- S'assurer que tous les tests passent (
meson test -C build)
Ce projet est sous licence MIT - voir le fichier LICENSE pour plus de détails.
MIT License
Copyright (c) 2024 sam0verfl0w
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- Intel pour la documentation détaillée des instructions AES-NI
- NIST pour les spécifications et vecteurs de test
- OpenSSL pour la validation croisée
- La communauté crypto pour les retours et contributions
Projet développé par sam0verfl0w dans le cadre de l'apprentissage de la cryptographie moderne et des optimisations matérielles.
⭐ N'hésitez pas à mettre une étoile si ce projet vous a été utile ! ⭐
Documentation • Tests • Issues • Discussions
Made with ❤️ and ☕ by sam0verfl0w