@@ -8,118 +8,78 @@ private import OpenSSLOperationBase
8
8
private import EVPHashInitializer
9
9
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
10
10
11
- // import EVPHashConsumers
12
- abstract class EVP_Hash_Operation extends OpenSSLOperation , Crypto:: HashOperationInstance {
13
- Expr getContextArg ( ) { result = this .( Call ) .getArgument ( 0 ) }
11
+ class EVP_Digest_Update_Call extends EVPUpdate {
12
+ EVP_Digest_Update_Call ( ) { this .( Call ) .getTarget ( ) .getName ( ) = "EVP_DigestUpdate" }
14
13
15
- Expr getAlgorithmArg ( ) { result = this .getInitCall ( ) .getAlgorithmArg ( ) }
16
-
17
- EVP_Hash_Initializer getInitCall ( ) {
18
- CTXFlow:: ctxArgFlowsToCtxArg ( result .getContextArg ( ) , this .getContextArg ( ) )
19
- }
20
-
21
- /**
22
- * By default, the algorithm value comes from the init call.
23
- * There are variants where this isn't true, in which case the
24
- * subclass should override this method.
25
- */
26
- override Crypto:: AlgorithmValueConsumer getAnAlgorithmValueConsumer ( ) {
27
- AlgGetterToAlgConsumerFlow:: flow ( result .( OpenSSLAlgorithmValueConsumer ) .getResultNode ( ) ,
28
- DataFlow:: exprNode ( this .getAlgorithmArg ( ) ) )
29
- }
30
- }
31
-
32
- private module AlgGetterToAlgConsumerConfig implements DataFlow:: ConfigSig {
33
- predicate isSource ( DataFlow:: Node source ) {
34
- exists ( OpenSSLAlgorithmValueConsumer c | c .getResultNode ( ) = source )
35
- }
36
-
37
- predicate isSink ( DataFlow:: Node sink ) {
38
- exists ( EVP_Hash_Operation c | c .getAlgorithmArg ( ) = sink .asExpr ( ) )
39
- }
14
+ override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
40
15
}
41
16
42
- private module AlgGetterToAlgConsumerFlow = DataFlow:: Global< AlgGetterToAlgConsumerConfig > ;
43
-
44
17
//https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis
45
- class EVP_Q_Digest_Operation extends EVP_Hash_Operation {
18
+ class EVP_Q_Digest_Operation extends EVPOperation , Crypto :: HashOperationInstance {
46
19
EVP_Q_Digest_Operation ( ) { this .( Call ) .getTarget ( ) .getName ( ) = "EVP_Q_digest" }
47
20
48
- //override Crypto::AlgorithmConsumer getAlgorithmConsumer() { }
21
+ override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
22
+
49
23
override EVP_Hash_Initializer getInitCall ( ) {
50
24
// This variant of digest does not use an init
51
25
// and even if it were used, the init would be ignored/undefined
52
26
none ( )
53
27
}
54
28
55
- override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 5 ) }
56
-
57
29
override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 3 ) }
58
30
59
- override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) { result = this .getOutputNode ( ) }
60
-
61
- override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) { result = this .getInputNode ( ) }
31
+ override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 5 ) }
62
32
63
- override Crypto:: AlgorithmValueConsumer getAnAlgorithmValueConsumer ( ) {
64
- // The operation is a direct algorithm consumer
65
- // NOTE: the operation itself is already modeld as a value consumer, so we can
66
- // simply return 'this', see modeled hash algorithm consuers for EVP_Q_Digest
67
- this = result
33
+ override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
34
+ result = EVPOperation .super .getOutputArtifact ( )
68
35
}
69
36
70
- override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
37
+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
38
+ result = EVPOperation .super .getInputConsumer ( )
39
+ }
71
40
}
72
41
73
- class EVP_Digest_Operation extends EVP_Hash_Operation {
42
+ class EVP_Digest_Operation extends EVPOperation , Crypto :: HashOperationInstance {
74
43
EVP_Digest_Operation ( ) { this .( Call ) .getTarget ( ) .getName ( ) = "EVP_Digest" }
75
44
76
45
// There is no context argument for this function
77
46
override Expr getContextArg ( ) { none ( ) }
78
47
48
+ override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 4 ) }
49
+
79
50
override EVP_Hash_Initializer getInitCall ( ) {
80
51
// This variant of digest does not use an init
81
52
// and even if it were used, the init would be ignored/undefined
82
53
none ( )
83
54
}
84
55
85
- override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 4 ) }
86
-
87
- override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 2 ) }
88
-
89
56
override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 0 ) }
90
57
91
- override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) { result = this .getOutputNode ( ) }
92
-
93
- override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) { result = this .getInputNode ( ) }
94
- }
95
-
96
- // NOTE: not modeled as hash operations, these are intermediate calls
97
- class EVP_Digest_Update_Call extends Call {
98
- EVP_Digest_Update_Call ( ) { this .( Call ) .getTarget ( ) .getName ( ) in [ "EVP_DigestUpdate" ] }
99
-
100
- Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
58
+ override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 2 ) }
101
59
102
- DataFlow:: Node getInputNode ( ) { result .asExpr ( ) = this .getInputArg ( ) }
60
+ override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
61
+ result = EVPOperation .super .getOutputArtifact ( )
62
+ }
103
63
104
- Expr getContextArg ( ) { result = this .( Call ) .getArgument ( 0 ) }
64
+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
65
+ result = EVPOperation .super .getInputConsumer ( )
66
+ }
105
67
}
106
68
107
- class EVP_Digest_Final_Call extends EVP_Hash_Operation {
69
+ class EVP_Digest_Final_Call extends EVPFinal , Crypto :: HashOperationInstance {
108
70
EVP_Digest_Final_Call ( ) {
109
71
this .( Call ) .getTarget ( ) .getName ( ) in [
110
72
"EVP_DigestFinal" , "EVP_DigestFinal_ex" , "EVP_DigestFinalXOF"
111
73
]
112
74
}
113
75
114
- EVP_Digest_Update_Call getUpdateCalls ( ) {
115
- CTXFlow:: ctxArgFlowsToCtxArg ( result .getContextArg ( ) , this .getContextArg ( ) )
116
- }
117
-
118
- override Expr getInputArg ( ) { result = this .getUpdateCalls ( ) .getInputArg ( ) }
119
-
120
- override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) { result = this .getInputNode ( ) }
121
-
122
76
override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
123
77
124
- override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) { result = this .getOutputNode ( ) }
78
+ override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
79
+ result = EVPFinal .super .getOutputArtifact ( )
80
+ }
81
+
82
+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
83
+ result = EVPFinal .super .getInputConsumer ( )
84
+ }
125
85
}
0 commit comments