Skip to content

Commit 7c72a65

Browse files
committed
Add RSAPKCS1Signature formatters
1 parent 2d4af33 commit 7c72a65

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@ class CryptographyCreateCall extends MethodCall {
4242
}
4343

4444
Expr getAlgorithmArg() {
45-
this.hasNoArguments() and result = this
46-
or
47-
result = this.(ECDsaCreateCallWithParameters).getArgument(0)
48-
or
49-
result = this.(ECDsaCreateCallWithECCurve).getArgument(0)
45+
if this.getArgument(0).getType().getName().matches("%Parameters")
46+
then result = this.getArgument(0)
47+
else result = this
5048
}
5149

5250
Expr getKeyConsumer() {
53-
this.hasNoArguments() and result = this
54-
or
55-
result = this.(ECDsaCreateCallWithParameters).getArgument(0)
56-
or
57-
result = this.(ECDsaCreateCallWithECCurve)
51+
if this.getArgument(0).getType().getName().matches("%Parameters")
52+
then result = this.getArgument(0)
53+
else result = this
5854
}
5955
}
6056

@@ -215,10 +211,20 @@ private class RSAClass extends CryptographyType {
215211
RSAClass() { this.hasName("RSA") }
216212
}
217213

214+
private class RSAPKCS1SignatureFormatter extends CryptographyType {
215+
RSAPKCS1SignatureFormatter() { this.hasName("RSAPKCS1SignatureFormatter") }
216+
}
217+
218+
private class RSAPKCS1SignatureDeformatter extends CryptographyType {
219+
RSAPKCS1SignatureDeformatter() { this.hasName("RSAPKCS1SignatureDeformatter") }
220+
}
221+
218222
private class SignerType extends Type {
219223
SignerType() {
220224
this instanceof ECDsaClass or
221-
this instanceof RSAClass
225+
this instanceof RSAClass or
226+
this instanceof RSAPKCS1SignatureFormatter or
227+
this instanceof RSAPKCS1SignatureDeformatter
222228
}
223229
}
224230

@@ -310,7 +316,7 @@ class RsaSignerQualifier extends SignerQualifier instanceof Expr {
310316

311317
class SignerUse extends MethodCall {
312318
SignerUse() {
313-
this.getTarget().getName().matches(["Verify%", "Sign%"]) and
319+
this.getTarget().getName().matches(["Verify%", "Sign%", "CreateSignature"]) and
314320
this.getQualifier().getType() instanceof SignerType
315321
}
316322

@@ -340,19 +346,11 @@ class SignerUse extends MethodCall {
340346
result = this.getAnArgument() and result.getType() instanceof HashAlgorithmNameType
341347
}
342348

343-
predicate isSigner() { this.getTarget().getName().matches("Sign%") }
349+
predicate isSigner() { this.getTarget().getName().matches(["Sign%", "CreateSignature"]) }
344350

345351
predicate isVerifier() { this.getTarget().getName().matches("Verify%") }
346352
}
347353

348-
private class ECDsaSigner extends SignerUse {
349-
ECDsaSigner() { this.getQualifier().getType() instanceof ECDsaClass }
350-
}
351-
352-
private class RSASigner extends SignerUse {
353-
RSASigner() { this.getQualifier().getType() instanceof RSAClass }
354-
}
355-
356354
/**
357355
* An AEAD class, such as `AesGcm`, `AesCcm`, or `ChaCha20Poly1305`.
358356
*/

0 commit comments

Comments
 (0)