Skip to content

Commit 2046a40

Browse files
committed
Randomize context on initialization
Signed-off-by: Sebastian Geisler <[email protected]>
1 parent a959de4 commit 2046a40

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rand-std = ["rand/std"]
2929
recovery = ["secp256k1-sys/recovery"]
3030
endomorphism = ["secp256k1-sys/endomorphism"]
3131
lowmemory = ["secp256k1-sys/lowmemory"]
32-
global-context = []
32+
global-context = ["std", "rand"]
3333

3434
# Use this feature to not compile the bundled libsecp256k1 C symbols,
3535
# but use external ones. Use this only if you know what you are doing!

src/context.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ pub mod global {
3131
static ONCE: Once = Once::new();
3232
static mut CONTEXT: Option<Secp256k1<All>> = None;
3333
ONCE.call_once(|| unsafe {
34-
CONTEXT = Some(Secp256k1::new());
34+
let mut ctx = Secp256k1::new();
35+
ctx.randomize(&mut rand::thread_rng());
36+
CONTEXT = Some(ctx);
3537
});
3638
unsafe { CONTEXT.as_ref().unwrap() }
3739
}

0 commit comments

Comments
 (0)