Skip to content

Commit d3665f9

Browse files
committed
C++: add sample code for InsufficientKeySize.qhelp
1 parent 0e50c4b commit d3665f9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
void encrypt_with_openssl(EVP_PKEY_CTX *ctx) {
2+
3+
// BAD: only 1024 bits for an RSA key
4+
EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 1024);
5+
6+
// GOOD: 2048 bits for an RSA key
7+
EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 2048);
8+
}

cpp/ql/src/Security/CWE/CWE-326/InsufficientKeySize.qhelp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ encrypted data.</p>
1717
</recommendation>
1818
<example>
1919

20+
<p>The following code shows an example of using the <code>openssl</code> library to generate an RSA key.
21+
When creating a key, you must specify which key size to use. The first example uses 1024 bits, which is not
22+
considered sufficient. The second example uses 2048 bits, which is currently considered sufficient.</p>
2023

24+
<sample src="InsufficientKeySize.c" />
2125

2226
</example>
2327
<references>
@@ -27,8 +31,6 @@ Approved Security Functions</a>.</li>
2731
<li>NIST, SP 800-131A: <a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf">
2832
Transitions: Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths</a>.</li>
2933

30-
31-
3234
<!-- LocalWords: CWE
3335
-->
3436

0 commit comments

Comments
 (0)