66
77import experimental.Quantum.Language
88
9-
109from Crypto:: NonceNode n , Crypto:: CipherOperationNode op , Crypto:: FlowAwareElement src , string msg
1110where
1211 op .getANonce ( ) = n and
12+ // Only encryption mode is relevant for insecure nonces, consder any 'unknown' subtype
13+ // as possibly encryption.
14+ (
15+ op .getCipherOperationSubtype ( ) instanceof Crypto:: EncryptionSubtype
16+ or
17+ op .getCipherOperationSubtype ( ) instanceof Crypto:: WrapSubtype
18+ or
19+ op .getCipherOperationSubtype ( ) instanceof Crypto:: UnwrapSubtype
20+ ) and
1321 (
1422 // Known sources cases that are not secure
1523 src = n .getSourceElement ( ) and
16- not src instanceof SecureRandomnessInstance and
17- msg = "Operation uses insecure nonce source $@"
18-
24+ not src instanceof SecureRandomnessInstance and
25+ msg = "Operation uses insecure nonce source $@"
1926 or
2027 // Totally unknown sources (unmodeled input sources)
21- not exists ( n .getSourceElement ( ) ) and msg = "Operation uses unknown nonce source" and src = n .asElement ( )
28+ not exists ( n .getSourceElement ( ) ) and
29+ msg = "Operation uses unknown nonce source" and
30+ src = n .asElement ( )
2231 )
2332select n , msg , src , src .toString ( )
2433
25-
2634// variant using instances, does not yield the same results
2735// from Crypto::NonceArtifactConsumer n, Crypto::CipherOperationInstance op, Crypto::FlowAwareElement src, string msg
2836// where
2937// op.getNonceConsumer() = n and
38+ // TODO: only perform the query on encryption
3039// (
3140// // Known sources cases that are not secure
3241// src = n.getAKnownArtifactSource()and
3342// not src instanceof SecureRandomnessInstance and
3443// msg = "Operation uses insecure nonce source $@"
35-
3644// or
3745// // Totally unknown sources (unmodeled input sources)
3846// // When this occurs set src to n, just to bind it, but the output message will not report any source
3947// not exists(n.getAKnownArtifactSource()) and msg = "Operation uses unknown nonce source" and src = n
4048// )
4149// select n, msg, src, src.toString()
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
5550// NOTE: this will find all unknowns too, constants, and allocations, without needing to model them
5651// which is kinda nice, but accidental, since getSourceElement is not modeled for everything
5752// If users want to find constants or unallocated, they need to model those sources, and output the
@@ -61,7 +56,6 @@ select n, msg, src, src.toString()
6156// will see the nonce and operation are secure, regardless of potentially insecure IV sources
6257// resulting in False Negatives
6358// NOTE: need to have a query where the op has no Nonce
64-
6559// // Ideal query
6660// from Crypto::NonceNode n, Crypto::CipherOperationNode op
6761// where
0 commit comments