@@ -4,7 +4,8 @@ import trailofbits.crypto.common
44// BIGNUM *BN_new(void);
55class BN_new extends CustomAllocator {
66 BN_new ( ) {
7- this .getQualifiedName ( ) = "BN_new" and (
7+ this .getQualifiedName ( ) = "BN_new" and
8+ (
89 dealloc instanceof BN_free or
910 dealloc instanceof BN_clear_free
1011 )
@@ -14,7 +15,8 @@ class BN_new extends CustomAllocator {
1415// BIGNUM *BN_secure_new(void);
1516class BN_secure_new extends CustomAllocator {
1617 BN_secure_new ( ) {
17- this .getQualifiedName ( ) = "BN_secure_new" and (
18+ this .getQualifiedName ( ) = "BN_secure_new" and
19+ (
1820 dealloc instanceof BN_free or
1921 dealloc instanceof BN_clear_free
2022 )
@@ -23,24 +25,16 @@ class BN_secure_new extends CustomAllocator {
2325
2426// void BN_free(BIGNUM *a);
2527class BN_free extends CustomDeallocator {
26- BN_free ( ) {
27- this .getQualifiedName ( ) = "BN_free"
28- }
28+ BN_free ( ) { this .getQualifiedName ( ) = "BN_free" }
2929
30- override int getPointer ( ) {
31- result = 0
32- }
30+ override int getPointer ( ) { result = 0 }
3331}
3432
3533// void BN_clear_free(BIGNUM *a);
3634class BN_clear_free extends CustomDeallocator {
37- BN_clear_free ( ) {
38- this .getQualifiedName ( ) = "BN_clear_free"
39- }
35+ BN_clear_free ( ) { this .getQualifiedName ( ) = "BN_clear_free" }
4036
41- override int getPointer ( ) {
42- result = 0
43- }
37+ override int getPointer ( ) { result = 0 }
4438}
4539
4640// void BN_clear(BIGNUM *a);
@@ -50,18 +44,92 @@ class BN_clear extends FunctionCall {
5044 Expr getBignum ( ) { result = this .getArgument ( 0 ) }
5145}
5246
53- // int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
47+ // int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); (and variants)
48+ /// Reference: https://docs.openssl.org/master/man3/BN_rand/#synopsis
5449class BN_rand extends FunctionCall {
55- BN_rand ( ) { this . getTarget ( ) . getName ( ) = "BN_rand" }
56-
57- Expr getBignum ( ) {
58- result = this .getArgument ( 0 )
50+ BN_rand ( ) {
51+ this . getTarget ( ) . getName ( ) . matches ( "BN\\_rand%" ) or
52+ this . getTarget ( ) . getName ( ) . matches ( "BN\\_priv\\_rand%" ) or
53+ this .getTarget ( ) . getName ( ) . matches ( "BN\\_pseudo\\_rand%" )
5954 }
55+
56+ Expr getBignum ( ) { result = this .getArgument ( 0 ) }
6057}
6158
6259class BIGNUM extends FunctionCall {
63- BIGNUM ( ) {
60+ BIGNUM ( ) {
6461 this .getTarget ( ) instanceof BN_new or
6562 this .getTarget ( ) instanceof BN_secure_new
6663 }
6764}
65+
66+ // BN_CTX *BN_CTX_new(void);
67+ class BN_CTX_new extends CustomAllocator {
68+ BN_CTX_new ( ) {
69+ this .getName ( ) = "BN_CTX_new" and
70+ dealloc instanceof BN_CTX_free
71+ }
72+ }
73+
74+ // BN_CTX *BN_CTX_secure_new(void);
75+ class BN_CTX_secure_new extends CustomAllocator {
76+ BN_CTX_secure_new ( ) {
77+ this .getName ( ) = "BN_CTX_secure_new" and
78+ dealloc instanceof BN_CTX_free
79+ }
80+ }
81+
82+ // void BN_CTX_free(BN_CTX *c);
83+ class BN_CTX_free extends CustomDeallocator {
84+ BN_CTX_free ( ) { this .getName ( ) = "BN_CTX_free" }
85+
86+ override int getPointer ( ) { result = 0 }
87+ }
88+
89+ // void BN_CTX_start(BN_CTX *ctx);
90+ class BN_CTX_start extends Expr {
91+ BN_CTX_start ( ) {
92+ exists ( FunctionCall fc |
93+ fc = this and
94+ fc .getTarget ( ) .getName ( ) = "BN_CTX_start"
95+ )
96+ }
97+
98+ Expr getContext ( ) { result = this .( FunctionCall ) .getArgument ( 0 ) }
99+ }
100+
101+ // void BN_CTX_end(BN_CTX *ctx);
102+ class BN_CTX_end extends Expr {
103+ BN_CTX_end ( ) {
104+ exists ( FunctionCall fc |
105+ fc = this and
106+ fc .getTarget ( ) .getName ( ) = "BN_CTX_end"
107+ )
108+ }
109+
110+ Expr getContext ( ) { result = this .( FunctionCall ) .getArgument ( 0 ) }
111+ }
112+
113+ // BIGNUM *BN_CTX_get(BN_CTX *ctx);
114+ class BN_CTX_get extends Expr {
115+ BN_CTX_get ( ) {
116+ exists ( FunctionCall fc |
117+ fc = this and
118+ fc .getTarget ( ) .getName ( ) = "BN_CTX_get"
119+ )
120+ }
121+
122+ Expr getContext ( ) { result = this .( FunctionCall ) .getArgument ( 0 ) }
123+ }
124+
125+ class BN_CTX extends Expr {
126+ BN_CTX ( ) {
127+ exists ( FunctionCall fc |
128+ fc = this and
129+ (
130+ fc .getTarget ( ) instanceof BN_CTX_new or
131+ fc .getTarget ( ) instanceof BN_CTX_secure_new
132+ )
133+ )
134+ }
135+ }
0 commit comments