@@ -8,118 +8,78 @@ private import OpenSSLOperationBase
88private import EVPHashInitializer
99private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
1010
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" }
1413
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 ) }
4015}
4116
42- private module AlgGetterToAlgConsumerFlow = DataFlow:: Global< AlgGetterToAlgConsumerConfig > ;
43-
4417//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 {
4619 EVP_Q_Digest_Operation ( ) { this .( Call ) .getTarget ( ) .getName ( ) = "EVP_Q_digest" }
4720
48- //override Crypto::AlgorithmConsumer getAlgorithmConsumer() { }
21+ override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
22+
4923 override EVP_Hash_Initializer getInitCall ( ) {
5024 // This variant of digest does not use an init
5125 // and even if it were used, the init would be ignored/undefined
5226 none ( )
5327 }
5428
55- override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 5 ) }
56-
5729 override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 3 ) }
5830
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 ) }
6232
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 ( )
6835 }
6936
70- override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
37+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
38+ result = EVPOperation .super .getInputConsumer ( )
39+ }
7140}
7241
73- class EVP_Digest_Operation extends EVP_Hash_Operation {
42+ class EVP_Digest_Operation extends EVPOperation , Crypto :: HashOperationInstance {
7443 EVP_Digest_Operation ( ) { this .( Call ) .getTarget ( ) .getName ( ) = "EVP_Digest" }
7544
7645 // There is no context argument for this function
7746 override Expr getContextArg ( ) { none ( ) }
7847
48+ override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 4 ) }
49+
7950 override EVP_Hash_Initializer getInitCall ( ) {
8051 // This variant of digest does not use an init
8152 // and even if it were used, the init would be ignored/undefined
8253 none ( )
8354 }
8455
85- override Expr getAlgorithmArg ( ) { result = this .( Call ) .getArgument ( 4 ) }
86-
87- override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 2 ) }
88-
8956 override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 0 ) }
9057
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 ) }
10159
102- DataFlow:: Node getInputNode ( ) { result .asExpr ( ) = this .getInputArg ( ) }
60+ override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
61+ result = EVPOperation .super .getOutputArtifact ( )
62+ }
10363
104- Expr getContextArg ( ) { result = this .( Call ) .getArgument ( 0 ) }
64+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
65+ result = EVPOperation .super .getInputConsumer ( )
66+ }
10567}
10668
107- class EVP_Digest_Final_Call extends EVP_Hash_Operation {
69+ class EVP_Digest_Final_Call extends EVPFinal , Crypto :: HashOperationInstance {
10870 EVP_Digest_Final_Call ( ) {
10971 this .( Call ) .getTarget ( ) .getName ( ) in [
11072 "EVP_DigestFinal" , "EVP_DigestFinal_ex" , "EVP_DigestFinalXOF"
11173 ]
11274 }
11375
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-
12276 override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
12377
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+ }
12585}
0 commit comments