1
+ import cpp
2
+ import WindowsCng
3
+ //TODO: Verify NCrypt calls (parameters) & find all other APIs that should be included (i.e. decrypt, etc.)
4
+ predicate isExprKeyHandleForBCryptSignHash ( Expr e ) {
5
+ exists ( FunctionCall call |
6
+ e = call .getArgument ( 0 )
7
+ and
8
+ call .getTarget ( ) .hasGlobalName ( "BCryptSignHash" )
9
+ )
10
+ }
11
+
12
+ class BCryptSignHashArgumentSink extends BCryptOpenAlgorithmProviderSink {
13
+ BCryptSignHashArgumentSink ( ) {
14
+ isExprKeyHandleForBCryptSignHash ( this .asExpr ( ) )
15
+ }
16
+ }
17
+
18
+ class BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource extends BCryptOpenAlgorithmProviderSource {
19
+ BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource ( ) {
20
+ this .asExpr ( ) instanceof StringLiteral and
21
+ (
22
+ this .asExpr ( ) .getValue ( ) in [ "DH" , "DSA" , "ECDSA" , "ECDH" ]
23
+ or this .asExpr ( ) .getValue ( ) .matches ( "ECDH%" )
24
+ or this .asExpr ( ) .getValue ( ) .matches ( "RSA%" )
25
+ )
26
+ }
27
+ }
28
+
29
+ predicate stepOpenAlgorithmProvider ( DataFlow:: Node node1 , DataFlow:: Node node2 )
30
+ {
31
+ exists ( FunctionCall call |
32
+ // BCryptOpenAlgorithmProvider 2nd argument specifies the algorithm to be used
33
+ node1 .asExpr ( ) = call .getArgument ( 1 )
34
+ and
35
+ call .getTarget ( ) .hasGlobalName ( "BCryptOpenAlgorithmProvider" )
36
+ and
37
+ node2 .asDefiningArgument ( ) = call .getArgument ( 0 )
38
+ )
39
+ }
40
+
41
+ predicate stepImportGenerateKeyPair ( DataFlow:: Node node1 , DataFlow:: Node node2 )
42
+ {
43
+ exists ( FunctionCall call |
44
+ node1 .asExpr ( ) = call .getArgument ( 0 )
45
+ and
46
+ ( call .getTarget ( ) .hasGlobalName ( "BCryptImportKeyPair" ) or
47
+ call .getTarget ( ) .hasGlobalName ( "BCryptGenerateKeyPair" ) )
48
+ and
49
+ node2 .asDefiningArgument ( ) = call .getArgument ( 1 )
50
+ )
51
+ }
52
+
53
+ predicate isWindowsCngAsymmetricKeyAdditionalTaintStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
54
+ stepOpenAlgorithmProvider ( node1 , node2 )
55
+ or
56
+ stepImportGenerateKeyPair ( node1 , node2 )
57
+ }
0 commit comments