Skip to content

Commit fac677d

Browse files
committed
feat: add predicates relating to lanes, memory_cost KDF parameters
1 parent a8f26bc commit fac677d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

python/ql/lib/experimental/cryptography/CryptoArtifact.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ abstract class KeyDerivationOperation extends CryptographicOperation {
135135

136136
DataFlow::Node getHashConfigSrc() { none() }
137137

138+
DataFlow::Node getLanesConfigSrc() { none() }
139+
140+
DataFlow::Node getMemoryCostConfigSrc() { none() }
141+
138142
// TODO: get encryption algorithm for CBC-based KDF?
139143
DataFlow::Node getDerivedKeySizeSrc() { none() }
140144

@@ -147,6 +151,10 @@ abstract class KeyDerivationOperation extends CryptographicOperation {
147151

148152
abstract predicate requiresHash();
149153

154+
abstract predicate requiresLanes();
155+
156+
abstract predicate requiresMemoryCost();
157+
150158
//abstract predicate requiresKeySize(); // Going to assume all requires a size
151159
abstract predicate requiresMode();
152160
}

python/ql/lib/experimental/cryptography/modules/CryptographyModule.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ module KDF {
116116

117117
override predicate requiresIteration() { this.getAlgorithm().getKDFName() in ["PBKDF2HMAC", "ARGON2"] }
118118

119+
override predicate requiresLanes() { this.getAlgorithm().getKDFName() in ["ARGON2"] }
120+
121+
override predicate requiresMemoryCost() { this.getAlgorithm().getKDFName() in ["ARGON2"] }
122+
119123
override DataFlow::Node getIterationSizeSrc() {
120124
this.requiresIteration() and
121125
if this.getAlgorithm().getKDFName() = "ARGON2"
@@ -144,6 +148,18 @@ module KDF {
144148
result = Utils::getUltimateSrcFromApiNode(this.getParameter(0, "algorithm"))
145149
}
146150

151+
override DataFlow::Node getLanesConfigSrc() {
152+
this.requiresLanes() and
153+
// ASSUMPTION: ONLY EVER in keyword parameter
154+
result = Utils::getUltimateSrcFromApiNode(this.getKeywordParameter("lanes"))
155+
}
156+
157+
override DataFlow::Node getMemoryCostConfigSrc() {
158+
this.requiresMemoryCost() and
159+
// ASSUMPTION: ONLY EVER in keyword parameter
160+
result = Utils::getUltimateSrcFromApiNode(this.getKeywordParameter("memory_cost"))
161+
}
162+
147163
// TODO: get encryption algorithm for CBC-based KDF?
148164
override DataFlow::Node getDerivedKeySizeSrc() {
149165
if this.getAlgorithm().getKDFName() = "ARGON2"

python/ql/lib/experimental/cryptography/modules/stdlib/HashlibModule.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ module KDF {
197197
override predicate requiresSalt() { any() }
198198

199199
override predicate requiresIteration() { any() }
200+
201+
override predicate requiresLanes() { none() }
202+
203+
override predicate requiresMemoryCost() { none() }
200204
}
201205

202206
// TODO: better modeling of scrypt
@@ -233,5 +237,9 @@ module KDF {
233237
override predicate requiresSalt() { any() }
234238

235239
override predicate requiresIteration() { none() }
240+
241+
override predicate requiresLanes() { none() }
242+
243+
override predicate requiresMemoryCost() { none() }
236244
}
237245
}

0 commit comments

Comments
 (0)