@@ -82,8 +82,33 @@ class SigningCreateCall extends CryptographyCreateCall {
8282 }
8383}
8484
85- class HashAlgorithmCreateCall extends CryptographyCreateCall {
86- HashAlgorithmCreateCall ( ) { this .getQualifier ( ) .getType ( ) instanceof HashAlgorithmType }
85+ /**
86+ * A call to create on an hash algorithm instance.
87+ * The hash algorithm is defined by the qualifier.
88+ */
89+ class HashAlgorithmCreateCall extends Crypto:: AlgorithmValueConsumer instanceof CryptographyCreateCall
90+ {
91+ HashAlgorithmCreateCall ( ) { super .getQualifier ( ) .getType ( ) instanceof HashAlgorithmType }
92+
93+ override Crypto:: AlgorithmInstance getAKnownAlgorithmSource ( ) { result = super .getQualifier ( ) }
94+
95+ override Crypto:: ConsumerInputDataFlowNode getInputNode ( ) { none ( ) }
96+ }
97+
98+ class HashAlgorithmQualifier extends Crypto:: HashAlgorithmInstance instanceof Expr {
99+ HashAlgorithmQualifier ( ) {
100+ this = any ( HashAlgorithmCreateCall c ) .( CryptographyCreateCall ) .getQualifier ( )
101+ }
102+
103+ override Crypto:: THashType getHashFamily ( ) {
104+ result = getHashFamily ( this .getRawHashAlgorithmName ( ) )
105+ }
106+
107+ override string getRawHashAlgorithmName ( ) { result = super .getType ( ) .getName ( ) }
108+
109+ override int getFixedDigestLength ( ) {
110+ hashAlgorithmToFamily ( this .getRawHashAlgorithmName ( ) , _, result )
111+ }
87112}
88113
89114class NamedCurvePropertyAccess extends PropertyAccess {
@@ -111,15 +136,18 @@ class HashAlgorithmName extends PropertyAccess {
111136
112137 string getAlgorithmName ( ) { result = algorithmName }
113138
114- Crypto:: THashType getHashFamily ( ) {
115- if hashAlgorithmToFamily ( this .getAlgorithmName ( ) , _, _)
116- then hashAlgorithmToFamily ( this .getAlgorithmName ( ) , result , _)
117- else result = Crypto:: OtherHashType ( )
118- }
139+ Crypto:: THashType getHashFamily ( ) { result = getHashFamily ( this .getAlgorithmName ( ) ) }
119140
120141 int getFixedDigestLength ( ) { hashAlgorithmToFamily ( this .getAlgorithmName ( ) , _, result ) }
121142}
122143
144+ bindingset [ name]
145+ Crypto:: THashType getHashFamily ( string name ) {
146+ if hashAlgorithmToFamily ( name , _, _)
147+ then hashAlgorithmToFamily ( name , result , _)
148+ else result = Crypto:: OtherHashType ( )
149+ }
150+
123151private predicate hashAlgorithmToFamily (
124152 string hashName , Crypto:: THashType hashFamily , int digestLength
125153) {
@@ -198,40 +226,44 @@ class ByteArrayOrReadOnlyByteSpanType extends Type {
198226 }
199227}
200228
201- class HashUse extends MethodCall {
229+ class HashUse extends Crypto :: AlgorithmValueConsumer instanceof MethodCall {
202230 HashUse ( ) {
203231 this .getQualifier ( ) .getType ( ) instanceof HashAlgorithmType and
204232 this .getTarget ( )
205- .getName ( )
206- .matches ( [
233+ .hasName ( [
207234 "ComputeHash" , "ComputeHashAsync" , "HashCore" , "HashData" , "HashDataAsync" ,
208235 "TransformBlock" , "TransformFinalBlock" , "TryComputeHash" , "TryHashData" ,
209236 "TryHashFinal" , "HashFinal"
210237 ] )
211238 }
212239
213- predicate isIntermediate ( ) { this .getTarget ( ) .hasName ( "HashCore" ) }
240+ predicate isIntermediate ( ) { super .getTarget ( ) .hasName ( "HashCore" ) }
214241
215- Expr getOutputArtifact ( ) {
242+ Expr getOutput ( ) {
216243 not this .isIntermediate ( ) and
217244 // some functions receive the destination as a parameter
218245 if
219- this .getTarget ( ) .getName ( ) = [ "TryComputeHash" , "TryHashFinal" , "TryHashData" ]
246+ super .getTarget ( ) .getName ( ) = [ "TryComputeHash" , "TryHashFinal" , "TryHashData" ]
220247 or
221- this .getTarget ( ) .getName ( ) = [ "HashData" ] and this .getNumberOfArguments ( ) = 2
248+ super .getTarget ( ) .getName ( ) = [ "HashData" ] and super .getNumberOfArguments ( ) = 2
222249 or
223- this .getTarget ( ) .getName ( ) = [ "HashDataAsync" ] and this .getNumberOfArguments ( ) = 3
224- then result = this .getArgument ( 1 )
250+ super .getTarget ( ) .getName ( ) = [ "HashDataAsync" ] and super .getNumberOfArguments ( ) = 3
251+ then result = super .getArgument ( 1 )
225252 else result = this
226253 }
227254
228255 Expr getInputArg ( ) {
229- result = this . getAnArgument ( ) and result .getType ( ) instanceof ByteArrayOrReadOnlyByteSpanType
256+ result = super . getArgument ( 0 ) and result .getType ( ) instanceof ByteArrayOrReadOnlyByteSpanType
230257 }
231- // Expr getStreamArg() {
232- // result = this.getAnArgument() and
233- // result.getType() instanceof Stream
234- // }
258+
259+ Expr getStreamArg ( ) {
260+ result = super .getAnArgument ( ) and
261+ result .getType ( ) instanceof Stream
262+ }
263+
264+ override Crypto:: AlgorithmInstance getAKnownAlgorithmSource ( ) { result = super .getQualifier ( ) }
265+
266+ override Crypto:: ConsumerInputDataFlowNode getInputNode ( ) { none ( ) }
235267}
236268
237269class SignerUse extends MethodCall {
0 commit comments