1
- // Common predicates relating to encryption in C and C++
1
+ /**
2
+ * Provides predicates relating to encryption in C and C++.
3
+ */
2
4
import cpp
3
5
4
- /** A blacklist of algorithms that are known to be insecure */
6
+ /**
7
+ * Returns an algorithm that is known to be insecure.
8
+ */
5
9
string algorithmBlacklist ( ) {
6
10
result = "DES" or
7
11
result = "RC2" or
@@ -10,14 +14,19 @@ string algorithmBlacklist() {
10
14
result = "ARCFOUR" // a variant of RC4
11
15
}
12
16
13
- // these are only bad if they're being used for encryption, and it's
14
- // hard to know when that's happening
17
+ /**
18
+ * Returns the name of a hash algorithm that is insecure if it is being used for
19
+ * encryption (but it is hard to know when that is happening).
20
+ */
15
21
string hashAlgorithmBlacklist ( ) {
16
22
result = "SHA1" or
17
23
result = "MD5"
18
24
}
19
25
20
- /** A regex for matching strings that look like they contain a blacklisted algorithm */
26
+ /**
27
+ * Returns a regular expression for matching strings that look like they
28
+ * contain an algorithm that is known to be insecure.
29
+ */
21
30
string algorithmBlacklistRegex ( ) {
22
31
result =
23
32
// algorithms usually appear in names surrounded by characters that are not
@@ -31,7 +40,9 @@ string algorithmBlacklistRegex() {
31
40
")([^a-z].*|$)"
32
41
}
33
42
34
- /** A whitelist of algorithms that are known to be secure */
43
+ /**
44
+ * Returns an algorithms that is known to be secure.
45
+ */
35
46
string algorithmWhitelist ( ) {
36
47
result = "RSA" or
37
48
result = "SHA256" or
@@ -42,17 +53,20 @@ string algorithmWhitelist() {
42
53
result = "ECIES"
43
54
}
44
55
45
- /** A regex for matching strings that look like they contain a whitelisted algorithm */
56
+ /**
57
+ * Returns a regular expression for matching strings that look like they
58
+ * contain an algorithm that is known to be secure.
59
+ */
46
60
string algorithmWhitelistRegex ( ) {
47
- // The implementation of this is a duplicate of algorithmBlacklistRegex, as it isn't
48
- // possible to have string -> string functions at the moment
61
+ // The implementation of this is a duplicate of algorithmBlacklistRegex, as
62
+ // it isn't possible to have string -> string functions at the moment
49
63
// algorithms usually appear in names surrounded by characters that are not
50
64
// alphabetical characters in the same case. This handles the upper and lower
51
65
// case cases
52
66
result = "(^|.*[^A-Z])" + algorithmWhitelist ( ) + "([^A-Z].*|$)"
53
67
or
54
68
// for lowercase, we want to be careful to avoid being confused by camelCase
55
- // hence we require two preceding uppercase letters to be sure of a case switch,
56
- // or a preceding non-alphabetic character
69
+ // hence we require two preceding uppercase letters to be sure of a case
70
+ // switch, or a preceding non-alphabetic character
57
71
result = "(^|.*[A-Z]{2}|.*[^a-zA-Z])" + algorithmWhitelist ( ) .toLowerCase ( ) + "([^a-z].*|$)"
58
72
}
0 commit comments