Skip to content

Commit a3e93ce

Browse files
committed
quantum-c#: add hash operation instance
1 parent 6d0024d commit a3e93ce

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

csharp/ql/lib/experimental/quantum/dotnet/Cryptography.qll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,29 @@ class HashUse extends MethodCall {
197197
.getName()
198198
.matches([
199199
"ComputeHash", "ComputeHashAsync", "HashCore", "HashData", "HashDataAsync",
200-
"TransformBlock", "TransformFinalBlock", "TryComputeHash", "TryHashData", "TryHashFinal"
200+
"TransformBlock", "TransformFinalBlock", "TryComputeHash", "TryHashData",
201+
"TryHashFinal", "HashFinal"
201202
])
202203
}
203204

204205
predicate isIntermediate() { this.getTarget().hasName("HashCore") }
206+
207+
Expr getOutputArtifact() {
208+
not this.isIntermediate() and
209+
// some functions receive the destination as a parameter
210+
if
211+
this.getTarget().getName() = ["TryComputeHash", "TryHashFinal", "TryHashData"]
212+
or
213+
this.getTarget().getName() = ["HashData"] and this.getNumberOfArguments() = 2
214+
or
215+
this.getTarget().getName() = ["HashDataAsync"] and this.getNumberOfArguments() = 3
216+
then result = this.getArgument(1)
217+
else result = this
218+
}
219+
220+
Expr getInputConsumer() {
221+
not this.getTarget().getName() = "HashFinal" and result = this.getArgument(0)
222+
}
205223
}
206224

207225
class SignerUse extends MethodCall {

csharp/ql/lib/experimental/quantum/dotnet/OperationInstances.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ class HashOperationInstance extends Crypto::HashOperationInstance instanceof Has
5050

5151
HashOperationInstance() { creator = HashCreateToUseFlow::getCreationFromUse(this, _, _) }
5252

53-
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() { none() }
53+
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
54+
result = DataFlow::exprNode(this.(HashUse).getOutputArtifact())
55+
}
5456

55-
override Crypto::ConsumerInputDataFlowNode getInputConsumer() { none() }
57+
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
58+
result = DataFlow::exprNode(this.(HashUse).getInputConsumer())
59+
}
5660

5761
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() { none() }
5862
}

0 commit comments

Comments
 (0)