File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Expand file tree Collapse file tree 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"]
2323rand-std = [" rand/std" ]
2424recovery = [" secp256k1-sys/recovery" ]
2525lowmemory = [" secp256k1-sys/lowmemory" ]
26- global-context = [" std" , " rand-std" ]
26+ global-context = [" std" , " rand-std" , " global-context-less-secure" ]
27+ global-context-less-secure = []
2728
2829[dependencies ]
2930secp256k1-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;
88#[ cfg( feature = "std" ) ]
99pub use self :: std_only:: * ;
1010
11- #[ cfg( feature = "global-context" ) ]
11+ #[ cfg( feature = "global-context-less-secure " ) ]
1212/// Module implementing a singleton pattern for a global `Secp256k1` context
1313pub mod global {
14+ #[ cfg( feature = "global-context" ) ]
1415 use rand;
16+
1517 use std:: ops:: Deref ;
1618 use std:: sync:: Once ;
1719 use { Secp256k1 , All } ;
@@ -22,6 +24,9 @@ pub mod global {
2224 }
2325
2426 /// 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.
2530 pub static SECP256K1 : & GlobalContext = & GlobalContext { __private : ( ) } ;
2631
2732 impl Deref for GlobalContext {
@@ -32,7 +37,10 @@ pub mod global {
3237 static mut CONTEXT : Option < Secp256k1 < All > > = None ;
3338 ONCE . call_once ( || unsafe {
3439 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+ }
3644 CONTEXT = Some ( ctx) ;
3745 } ) ;
3846 unsafe { CONTEXT . as_ref ( ) . unwrap ( ) }
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ use core::ops::Deref;
158158use core:: mem;
159159use ffi:: { CPtr , types:: AlignedType } ;
160160
161- #[ cfg( feature = "global-context" ) ]
161+ #[ cfg( feature = "global-context-less-secure " ) ]
162162pub use context:: global:: SECP256K1 ;
163163
164164#[ cfg( feature = "bitcoin_hashes" ) ]
@@ -1269,7 +1269,7 @@ mod tests {
12691269
12701270 }
12711271
1272- #[ cfg( feature = "global-context" ) ]
1272+ #[ cfg( feature = "global-context-less-secure " ) ]
12731273 #[ test]
12741274 fn test_global_context ( ) {
12751275 use super :: SECP256K1 ;
You can’t perform that action at this time.
0 commit comments