File tree 3 files changed +14
-5
lines changed
3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ std = ["secp256k1-sys/std"]
23
23
rand-std = [" rand/std" ]
24
24
recovery = [" secp256k1-sys/recovery" ]
25
25
lowmemory = [" secp256k1-sys/lowmemory" ]
26
- global-context = [" std" , " rand-std" ]
26
+ global-context = [" std" , " rand-std" , " global-context-less-secure" ]
27
+ global-context-less-secure = []
27
28
28
29
[dependencies ]
29
30
secp256k1-sys = { version = " 0.4.0" , default-features = false , path = " ./secp256k1-sys" }
Original file line number Diff line number Diff line change @@ -8,10 +8,12 @@ use Secp256k1;
8
8
#[ cfg( feature = "std" ) ]
9
9
pub use self :: std_only:: * ;
10
10
11
- #[ cfg( feature = "global-context" ) ]
11
+ #[ cfg( feature = "global-context-less-secure " ) ]
12
12
/// Module implementing a singleton pattern for a global `Secp256k1` context
13
13
pub mod global {
14
+ #[ cfg( feature = "global-context" ) ]
14
15
use rand;
16
+
15
17
use std:: ops:: Deref ;
16
18
use std:: sync:: Once ;
17
19
use { Secp256k1 , All } ;
@@ -22,6 +24,9 @@ pub mod global {
22
24
}
23
25
24
26
/// A global, static context to avoid repeatedly creating contexts where one can't be passed
27
+ ///
28
+ /// If the global-context feature is enabled (and not just the global-context-less-secure),
29
+ /// this will have been randomized.
25
30
pub static SECP256K1 : & GlobalContext = & GlobalContext { __private : ( ) } ;
26
31
27
32
impl Deref for GlobalContext {
@@ -32,7 +37,10 @@ pub mod global {
32
37
static mut CONTEXT : Option < Secp256k1 < All > > = None ;
33
38
ONCE . call_once ( || unsafe {
34
39
let mut ctx = Secp256k1 :: new ( ) ;
35
- ctx. randomize ( & mut rand:: thread_rng ( ) ) ;
40
+ #[ cfg( feature = "global-context" ) ]
41
+ {
42
+ ctx. randomize ( & mut rand:: thread_rng ( ) ) ;
43
+ }
36
44
CONTEXT = Some ( ctx) ;
37
45
} ) ;
38
46
unsafe { CONTEXT . as_ref ( ) . unwrap ( ) }
Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ use core::ops::Deref;
156
156
use core:: mem;
157
157
use ffi:: { CPtr , types:: AlignedType } ;
158
158
159
- #[ cfg( feature = "global-context" ) ]
159
+ #[ cfg( feature = "global-context-less-secure " ) ]
160
160
pub use context:: global:: SECP256K1 ;
161
161
162
162
#[ cfg( feature = "bitcoin_hashes" ) ]
@@ -1263,7 +1263,7 @@ mod tests {
1263
1263
assert_tokens ( & sig. readable ( ) , & [ Token :: BorrowedStr ( SIG_STR ) ] ) ;
1264
1264
}
1265
1265
1266
- #[ cfg( feature = "global-context" ) ]
1266
+ #[ cfg( feature = "global-context-less-secure " ) ]
1267
1267
#[ test]
1268
1268
fn test_global_context ( ) {
1269
1269
use super :: SECP256K1 ;
You can’t perform that action at this time.
0 commit comments