Skip to content

Commit 646ea55

Browse files
committed
Python/JS: Update Python copy of crypto algorithm modeling
Now to be shared accross both languages, with sync-identical-files
1 parent b7c0d18 commit 646ea55

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

python/ql/src/semmle/crypto/Crypto.qll

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
* Provides classes for modeling cryptographic libraries.
33
*/
44

5-
/*
6-
* The following information is copied from `/semmlecode-javascript-queries/semmle/javascript/frameworks/CryptoLibraries.qll`
7-
* which should be considered the definitive version (as of Feb 2018)
8-
*/
9-
105
/**
116
* Names of cryptographic algorithms, separated into strong and weak variants.
127
*
138
* The names are normalized: upper-case, no spaces, dashes or underscores.
149
*
1510
* The names are inspired by the names used in real world crypto libraries.
11+
*
12+
* The classification into strong and weak are based on Wikipedia, OWASP and google (2017).
1613
*/
1714
private module AlgorithmNames {
1815
predicate isStrongHashingAlgorithm(string name) {
@@ -81,14 +78,6 @@ private module AlgorithmNames {
8178
}
8279

8380
predicate isWeakPasswordHashingAlgorithm(string name) { none() }
84-
85-
/**
86-
* Normalizes `name`: upper-case, no spaces, dashes or underscores.
87-
*
88-
* All names of this module are in this normalized form.
89-
*/
90-
bindingset[name]
91-
string normalizeName(string name) { result = name.toUpperCase().regexpReplaceAll("[-_ ]", "") }
9281
}
9382

9483
private import AlgorithmNames
@@ -121,10 +110,19 @@ abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
121110
string toString() { result = getName() }
122111

123112
/**
124-
* Gets the name of the algorithm.
113+
* Gets the name of this algorithm.
125114
*/
126115
abstract string getName();
127116

117+
/**
118+
* Holds if the name of this algorithm matches `name` modulo case,
119+
* white space, dashes and underscores.
120+
*/
121+
bindingset[name]
122+
predicate matchesName(string name) {
123+
name.toUpperCase().regexpReplaceAll("[-_ ]", "") = getName()
124+
}
125+
128126
/**
129127
* Holds if this algorithm is weak.
130128
*/

0 commit comments

Comments
 (0)