11---
2- description : Cryptographic Security Guidelines
2+ description : Cryptographic Security Guidelines & Post-Quantum Readiness
33alwaysApply : true
44---
55
66rule_id: codeguard-1-crypto-algorithms
77
8- # Cryptographic Security Guidelines
8+ # Cryptographic Security Guidelines & Post-Quantum Readiness
99
10- ## Banned (Insecure) Algorithms
10+ ## 1. Banned (Insecure) Algorithms
1111
12- The following algorithms are known to be broken or fundamentally insecure. ** NEVER** generate or use code with these algorithms.
13- Examples:
12+ The following algorithms are known to be broken or fundamentally insecure. NEVER generate or use code with these algorithms.
1413
15- * Hash: ` MD2 ` , ` MD4 ` , ` MD5 ` , ` SHA-0 `
16- * Symmetric: ` RC2 ` , ` RC4 ` , ` Blowfish ` , ` DES ` , ` 3DES `
17- * Key Exchange: Static RSA, Anonymous Diffie-Hellman
18- * Classical: ` Vigenère `
14+ * Hash: ` MD2 ` , ` MD4 ` , ` MD5 ` , ` SHA-0 `
15+ * Symmetric: ` RC2 ` , ` RC4 ` , ` Blowfish ` , ` DES ` , ` 3DES `
16+ * Key Exchange: Static RSA, Anonymous Diffie-Hellman
17+ * Classical: ` Vigenère `
1918
20- ## Deprecated (Legacy/Weak) Algorithms
19+ Reason: These are cryptographically broken and vulnerable to collision or man-in-the-middle attacks.
2120
22- The following algorithms are not outright broken, but have known weaknesses, or are considered obsolete. ** NEVER** generate or use code with these algorithms.
23- Examples:
21+ ## 2. Deprecated (Legacy/Weak) Algorithms
2422
25- * Hash: ` SHA-1 `
26- * Symmetric: ` AES-CBC ` , ` AES-ECB `
27- * Signature: RSA with ` PKCS#1 v1.5 ` padding
28- * Key Exchange: DHE with weak/common primes
23+ The following algorithms have known weaknesses or are considered obsolete. Avoid in new designs and prioritize migration.
2924
25+ * Hash: ` SHA-1 `
26+ * Symmetric: ` AES-CBC ` , ` AES-ECB `
27+ * Signature: RSA with ` PKCS#1 v1.5 ` padding
28+ * Key Exchange: DHE with weak/common primes
3029
31- ## Deprecated SSL/Crypto APIs - FORBIDDEN
32- NEVER use these deprecated functions. Use the replacement APIs listed below:
30+ ## 3. Recommended & Post-Quantum Ready Algorithms
3331
34- ### Symmetric Encryption (AES)
32+ Implement these modern, secure algorithms to ensure resistance against both classical and quantum threats.
33+
34+ ### Symmetric Encryption
35+ * Standard: ` AES-GCM ` (AEAD), ` ChaCha20-Poly1305 ` (when allowed).
36+ * PQC Requirement: Prefer AES-256 keys (or stronger) as they are resistant to quantum attacks (Grover's algorithm).
37+ * Avoid: Custom crypto or unauthenticated modes.
38+
39+ ### Key Exchange (KEM)
40+ * Standard: ECDHE (` X25519 ` or ` secp256r1 ` )
41+ * PQC Requirement: Use Hybrid Key Exchange (Classical + PQC) when supported.
42+ * Preferred: ` X25519MLKEM768 ` (X25519 + ML-KEM-768)
43+ * Alternative: ` SecP256r1MLKEM768 ` (P-256 + ML-KEM-768)
44+ * High Assurance: ` SecP384r1MLKEM1024 ` (P-384 + ML-KEM-1024)
45+ * Pure PQC: ML-KEM-768 (baseline) or ML-KEM-1024. Avoid ML-KEM-512 unless explicitly risk-accepted.
46+ * Constraints:
47+ * Use vendor-documented identifiers (RFC 9242/9370).
48+ * Remove legacy/draft "Hybrid-Kyber" groups (e.g., ` X25519Kyber ` ) and draft or hardcoded OIDs.
49+
50+ ### Signatures & Certificates
51+ * Standard: ECDSA (` P-256 ` )
52+ * PQC Migration: Continue using ECDSA (` P-256 ` ) for mTLS and code signing until hardware-backed (HSM/TPM) ML-DSA is available.
53+ * Hardware Requirement: Do not enable PQC ML-DSA signatures using software-only keys. Require HSM/TPM storage.
54+
55+ ### Protocol Versions
56+ * (D)TLS: Enforce (D)TLS 1.3 only (or later).
57+ * IPsec: Enforce IKEv2 only.
58+ * Use ESP with AEAD (AES-256-GCM).
59+ * Require PFS via ECDHE.
60+ * Implement RFC 9242 and RFC 9370 for Hybrid PQC (ML-KEM + ECDHE).
61+ * Ensure re-keys (CREATE_CHILD_SA) maintain hybrid algorithms.
62+ * SSH: Enable only vendor-supported PQC/hybrid KEX (e.g., ` sntrup761x25519 ` ).
63+
64+ ## 4. Secure Implementation Guidelines
65+
66+ ### General Best Practices
67+ * Configuration over Code: Expose algorithm choices in config/policy to allow agility without code changes.
68+ * Key Management:
69+ * Use KMS/HSM for key storage.
70+ * Generate keys with a CSPRNG.
71+ * Separate encryption keys from signature keys.
72+ * Rotate keys per policy.
73+ * NEVER hardcode keys, secrets, or experimental OIDs.
74+ * Telemetry: Capture negotiated groups, handshake sizes, and failure causes to monitor PQC adoption.
75+
76+ ### Deprecated SSL/Crypto APIs (C/OpenSSL) - FORBIDDEN
77+ NEVER use these deprecated functions. Use the replacement EVP high-level APIs.
78+
79+ #### Symmetric Encryption (AES)
3580- Deprecated: ` AES_encrypt() ` , ` AES_decrypt() `
36- - Replacement: Use EVP high-level APIs:
37- ``` c
38- EVP_EncryptInit_ex ()
81+ - Replacement:
82+
83+ EVP_EncryptInit_ex() // Use EVP_aes_256_gcm() for PQC readiness
3984 EVP_EncryptUpdate()
4085 EVP_EncryptFinal_ex()
41- EVP_DecryptInit_ex()
42- EVP_DecryptUpdate()
43- EVP_DecryptFinal_ex()
44- ```
45-
46- ### RSA Operations
47- - Deprecated: `RSA_new()`, `RSA_up_ref()`, `RSA_free()`, `RSA_set0_crt_params()`, `RSA_get0_n()`
48- - Replacement: Use EVP key management APIs:
49- ```c
86+
87+
88+ #### RSA/PKEY Operations
89+ - Deprecated: ` RSA_new() ` , ` RSA_free() ` , ` RSA_get0_n() `
90+ - Replacement:
91+
5092 EVP_PKEY_new()
5193 EVP_PKEY_up_ref()
5294 EVP_PKEY_free()
53- ```
54-
55- ### Hash Functions
56- - Deprecated: `SHA1_Init()`, `SHA1_Update()`, `SHA1_Final()`
57- - Replacement: Use EVP digest APIs:
58- ```c
59- EVP_DigestInit_ex ()
60- EVP_DigestUpdate()
61- EVP_DigestFinal_ex()
62- EVP_Q_digest() // For simple one-shot hashing
63- ```
64-
65- ### MAC Operations
66- - Deprecated: `CMAC_Init()`, `HMAC()` (especially with SHA1)
67- - Replacement: Use EVP MAC APIs:
68- ```c
69- EVP_Q_MAC () // For simple MAC operations
70- ```
71-
72- ### Key Wrapping
73- - Deprecated: `AES_wrap_key()`, `AES_unwrap_key()`
74- - Replacement: Use EVP key wrapping APIs or implement using EVP encryption
75-
76- ### Other Deprecated Functions
77- - Deprecated: `DSA_sign()`, `DH_check()`
78- - Replacement: Use corresponding EVP APIs for DSA and DH operations
79-
80- ## Banned Insecure Algorithms - STRICTLY FORBIDDEN
81- These algorithms MUST NOT be used in any form:
82-
83- ### Hash Algorithms (Banned)
84- - MD2, MD4, MD5, SHA-0
85- - Reason: Cryptographically broken, vulnerable to collision attacks
86- - Use Instead: SHA-256, SHA-384, SHA-512
87-
88- ### Symmetric Ciphers (Banned)
89- - RC2, RC4, Blowfish, DES, 3DES
90- - Reason: Weak key sizes, known vulnerabilities
91- - Use Instead: AES-128, AES-256, ChaCha20
92-
93- ### Key Exchange (Banned)
94- - Static RSA key exchange
95- - Anonymous Diffie-Hellman
96- - Reason: No forward secrecy, vulnerable to man-in-the-middle attacks
97- - Use Instead: ECDHE, DHE with proper validation
98-
99- ## Broccoli Project Specific Requirements
100- - HMAC() with SHA1: Deprecated per Broccoli project requirements
95+
96+
97+ #### Hash & MAC Functions
98+ - Deprecated: ` SHA1_Init() ` , ` HMAC() ` (especially with SHA1)
99+ - Replacement:
100+
101+ EVP_DigestInit_ex() // Use SHA-256 or stronger
102+ EVP_Q_MAC() // For one-shot MAC
103+
104+
105+ ## 5. Broccoli Project Specific Requirements
106+ - HMAC() with SHA1: Deprecated.
101107- Replacement: Use HMAC with SHA-256 or stronger:
102- ``` c
103- // Instead of HMAC() with SHA1
104- EVP_Q_MAC (NULL, "HMAC", NULL, "SHA256", NULL, key, key_len, data, data_len, out, out_size, &out_len);
105- ```
106108
107- ## Secure Crypto Implementation Pattern
109+
110+ // Example: Secure replacement for HMAC-SHA1
111+ ``` c
112+ EVP_Q_MAC (NULL, "HMAC", NULL, "SHA256", NULL, key, key_len, data, data_len, out, out_size, &out_len);
113+ ```
114+
115+ ## 6. Secure Crypto Implementation Pattern
116+
117+
118+ // Example: Secure AES-256-GCM encryption (PQC-Ready Symmetric Strength)
108119```c
109- // Example: Secure AES encryption
110120EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
111121if (!ctx) handle_error();
112122
123+ // Use AES-256-GCM
113124if (EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, key, iv) != 1)
114125 handle_error();
115126
@@ -124,11 +135,3 @@ ciphertext_len += len;
124135
125136EVP_CIPHER_CTX_free(ctx);
126137```
127-
128- ## Code Review Checklist
129- - [ ] No deprecated SSL/crypto APIs used
130- - [ ] No banned algorithms (MD5, DES, RC4, etc.)
131- - [ ] HMAC uses SHA-256 or stronger (not SHA1)
132- - [ ] All crypto operations use EVP high-level APIs
133- - [ ] Proper error handling for all crypto operations
134- - [ ] Key material properly zeroed after use
0 commit comments