@@ -8,73 +8,49 @@ 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 ) }
1411
15- EVP_Hash_Initializer getInitCall ( ) {
16- CTXFlow:: ctxArgFlowsToCtxArg ( result .getContextArg ( ) , this .getContextArg ( ) )
17- }
18-
19- /**
20- * By default, the algorithm value comes from the init call.
21- * There are variants where this isn't true, in which case the
22- * subclass should override this method.
23- */
24- override Crypto:: AlgorithmValueConsumer getAnAlgorithmValueConsumer ( ) {
25- AlgGetterToAlgConsumerFlow:: flow ( result .( OpenSSLAlgorithmValueConsumer ) .getResultNode ( ) ,
26- DataFlow:: exprNode ( this .getInitCall ( ) .getAlgorithmArg ( ) ) )
27- }
28- }
29-
30- private module AlgGetterToAlgConsumerConfig implements DataFlow:: ConfigSig {
31- predicate isSource ( DataFlow:: Node source ) {
32- exists ( OpenSSLAlgorithmValueConsumer c | c .getResultNode ( ) = source )
33- }
12+ class EVP_Digest_Update_Call extends EVPUpdate {
13+ EVP_Digest_Update_Call ( ) { this .( Call ) .getTarget ( ) .getName ( ) in [ "EVP_DigestUpdate" ] }
3414
35- predicate isSink ( DataFlow:: Node sink ) {
36- exists ( EVP_Hash_Operation c | c .getInitCall ( ) .getAlgorithmArg ( ) = sink .asExpr ( ) )
37- }
15+ override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
3816}
3917
40- private module AlgGetterToAlgConsumerFlow = DataFlow:: Global< AlgGetterToAlgConsumerConfig > ;
4118
4219//https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis
43- class EVP_Q_Digest_Operation extends EVP_Hash_Operation {
20+ class EVP_Q_Digest_Operation extends EVPOneShot , Crypto :: HashOperationInstance {
4421 EVP_Q_Digest_Operation ( ) { this .( Call ) .getTarget ( ) .getName ( ) = "EVP_Q_digest" }
4522
46- //override Crypto::AlgorithmConsumer getAlgorithmConsumer() { }
23+ override Expr getAlgorithmArg ( ) {
24+ result = this .( Call ) .getArgument ( 1 )
25+ }
26+
4727 override EVP_Hash_Initializer getInitCall ( ) {
4828 // This variant of digest does not use an init
4929 // and even if it were used, the init would be ignored/undefined
5030 none ( )
5131 }
5232
53- override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 5 ) }
54-
5533 override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 3 ) }
5634
57- override Crypto :: ArtifactOutputDataFlowNode getOutputArtifact ( ) { result = this .getOutputNode ( ) }
35+ override Expr getOutputArg ( ) { result = this .( Call ) . getArgument ( 5 ) }
5836
59- override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) { result = this .getInputNode ( ) }
37+ override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
38+ result = this .( EVPOperation ) .getOutputArtifact ( )
39+ }
6040
61- override Crypto:: AlgorithmValueConsumer getAnAlgorithmValueConsumer ( ) {
62- // The operation is a direct algorithm consumer
63- // NOTE: the operation itself is already modeld as a value consumer, so we can
64- // simply return 'this', see modeled hash algorithm consuers for EVP_Q_Digest
65- this = result
41+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
42+ result = this .( EVPOperation ) .getInputConsumer ( )
6643 }
6744}
6845
69- class EVP_Digest_Operation extends EVP_Hash_Operation {
46+ class EVP_Digest_Operation extends EVPOneShot , Crypto :: HashOperationInstance {
7047 EVP_Digest_Operation ( ) { this .( Call ) .getTarget ( ) .getName ( ) = "EVP_Digest" }
7148
7249 // There is no context argument for this function
7350 override Expr getContextArg ( ) { none ( ) }
7451
75- override Crypto:: AlgorithmValueConsumer getAnAlgorithmValueConsumer ( ) {
76- AlgGetterToAlgConsumerFlow:: flow ( result .( OpenSSLAlgorithmValueConsumer ) .getResultNode ( ) ,
77- DataFlow:: exprNode ( this .( Call ) .getArgument ( 4 ) ) )
52+ override Expr getAlgorithmArg ( ) {
53+ result = this .( Call ) .getArgument ( 4 )
7854 }
7955
8056 override EVP_Hash_Initializer getInitCall ( ) {
@@ -83,42 +59,33 @@ class EVP_Digest_Operation extends EVP_Hash_Operation {
8359 none ( )
8460 }
8561
86- override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 2 ) }
87-
8862 override Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 0 ) }
8963
90- override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) { result = this .getOutputNode ( ) }
91-
92- override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) { result = this .getInputNode ( ) }
93- }
94-
95- // NOTE: not modeled as hash operations, these are intermediate calls
96- class EVP_Digest_Update_Call extends Call {
97- EVP_Digest_Update_Call ( ) { this .( Call ) .getTarget ( ) .getName ( ) in [ "EVP_DigestUpdate" ] }
98-
99- Expr getInputArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
64+ override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 2 ) }
10065
101- DataFlow:: Node getInputNode ( ) { result .asExpr ( ) = this .getInputArg ( ) }
66+ override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
67+ result = this .( EVPOperation ) .getOutputArtifact ( )
68+ }
10269
103- Expr getContextArg ( ) { result = this .( Call ) .getArgument ( 0 ) }
70+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
71+ result = this .( EVPOperation ) .getInputConsumer ( )
72+ }
10473}
10574
106- class EVP_Digest_Final_Call extends EVP_Hash_Operation {
75+ class EVP_Digest_Final_Call extends EVPFinal , Crypto :: HashOperationInstance {
10776 EVP_Digest_Final_Call ( ) {
10877 this .( Call ) .getTarget ( ) .getName ( ) in [
10978 "EVP_DigestFinal" , "EVP_DigestFinal_ex" , "EVP_DigestFinalXOF"
11079 ]
11180 }
11281
113- EVP_Digest_Update_Call getUpdateCalls ( ) {
114- CTXFlow:: ctxArgFlowsToCtxArg ( result .getContextArg ( ) , this .getContextArg ( ) )
115- }
116-
117- override Expr getInputArg ( ) { result = this .getUpdateCalls ( ) .getInputArg ( ) }
118-
119- override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) { result = this .getInputNode ( ) }
120-
12182 override Expr getOutputArg ( ) { result = this .( Call ) .getArgument ( 1 ) }
83+
84+ override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
85+ result = this .( EVPOperation ) .getOutputArtifact ( )
86+ }
12287
123- override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) { result = this .getOutputNode ( ) }
88+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
89+ result = this .( EVPOperation ) .getInputConsumer ( )
90+ }
12491}
0 commit comments