1- // Common predicates relating to encryption in C and C++
1+ /**
2+ * Provides predicates relating to encryption in C and C++.
3+ */
24import cpp
35
4- /** A blacklist of algorithms that are known to be insecure */
6+ /**
7+ * Returns an algorithm that is known to be insecure.
8+ */
59string algorithmBlacklist ( ) {
610 result = "DES" or
711 result = "RC2" or
@@ -10,14 +14,19 @@ string algorithmBlacklist() {
1014 result = "ARCFOUR" // a variant of RC4
1115}
1216
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+ */
1521string hashAlgorithmBlacklist ( ) {
1622 result = "SHA1" or
1723 result = "MD5"
1824}
1925
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+ */
2130string algorithmBlacklistRegex ( ) {
2231 result =
2332 // algorithms usually appear in names surrounded by characters that are not
@@ -31,7 +40,9 @@ string algorithmBlacklistRegex() {
3140 ")([^a-z].*|$)"
3241}
3342
34- /** A whitelist of algorithms that are known to be secure */
43+ /**
44+ * Returns an algorithms that is known to be secure.
45+ */
3546string algorithmWhitelist ( ) {
3647 result = "RSA" or
3748 result = "SHA256" or
@@ -42,17 +53,20 @@ string algorithmWhitelist() {
4253 result = "ECIES"
4354}
4455
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+ */
4660string 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
4963 // algorithms usually appear in names surrounded by characters that are not
5064 // alphabetical characters in the same case. This handles the upper and lower
5165 // case cases
5266 result = "(^|.*[^A-Z])" + algorithmWhitelist ( ) + "([^A-Z].*|$)"
5367 or
5468 // 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
5771 result = "(^|.*[A-Z]{2}|.*[^a-zA-Z])" + algorithmWhitelist ( ) .toLowerCase ( ) + "([^a-z].*|$)"
5872}
0 commit comments