Skip to content

Commit 965d131

Browse files
committed
C++: Add more test cases.
1 parent fb02e99 commit 965d131

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| library/tests_library.h:4:6:4:19 | do_aes_encrypt | This function, "do_aes_encrypt", may be a custom implementation of a cryptographic primitive. |
12
| tests_crypto.cpp:11:6:11:18 | encryptString | This function, "encryptString", may be a custom implementation of a cryptographic primitive. |
23
| tests_crypto.cpp:30:6:30:14 | MyEncrypt | This function, "MyEncrypt", may be a custom implementation of a cryptographic primitive. |
34
| tests_crypto.cpp:83:6:83:18 | init_aes_sbox | This function, "init_aes_sbox", may be a custom implementation of a cryptographic primitive. |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Cryptography 'library' snippets. Nothing in this file should be flagged by the query, because
2+
// it's in a library.
3+
4+
void do_aes_encrypt(unsigned int *v) {
5+
COMPUTE(v)
6+
}

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-1240/tests_not_crypto.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,23 @@ namespace std
2121
extern ostream cout;
2222
}
2323

24+
// this macro expands to some compute operations that look a bit like cryptography
25+
#define COMPUTE(v) \
26+
v[0] ^= v[1] ^ v[2] ^ v[3] ^ v[4]; \
27+
v[1] ^= v[2] ^ v[3] ^ v[4] ^ v[5]; \
28+
v[2] ^= v[3] ^ v[4] ^ v[5] ^ v[6]; \
29+
v[3] ^= v[4] ^ v[5] ^ v[6] ^ v[7];
30+
2431
// ---
2532

33+
#include "library/tests_library.h"
34+
35+
bool isEnabledAes() {
36+
// This function has "Aes" in it's name, but does not contain enough compute to
37+
// be an encryption implementation.
38+
return false;
39+
}
40+
2641
uint32_t lookup[256];
2742

2843
uint8_t computeCRC32(const uint8_t *data, size_t dataLen) {
@@ -79,13 +94,6 @@ void output_encrypt_decrypt_algorithms() {
7994
std::cout << indent << "Chacha (" << yes_no_setting() << ")\n";
8095
}
8196

82-
// this macro expands to some compute operations that look a bit like cryptography
83-
#define COMPUTE(v) \
84-
v[0] ^= v[1] ^ v[2] ^ v[3] ^ v[4]; \
85-
v[1] ^= v[2] ^ v[3] ^ v[4] ^ v[5]; \
86-
v[2] ^= v[3] ^ v[4] ^ v[5] ^ v[6]; \
87-
v[3] ^= v[4] ^ v[5] ^ v[6] ^ v[7];
88-
8997
void wideStringCharsAt(int *v) {
9098
// This function has "des" and "rsa" in the name.
9199
COMPUTE(v)

0 commit comments

Comments
 (0)