From 2046a4090574ae380280a886df11b8bba84e60d0 Mon Sep 17 00:00:00 2001 From: Sebastian Geisler Date: Mon, 3 Aug 2020 12:07:26 +0200 Subject: [PATCH] Randomize context on initialization Signed-off-by: Sebastian Geisler --- Cargo.toml | 2 +- src/context.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index be37c4e..298496a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ rand-std = ["rand/std"] recovery = ["secp256k1-sys/recovery"] endomorphism = ["secp256k1-sys/endomorphism"] lowmemory = ["secp256k1-sys/lowmemory"] -global-context = [] +global-context = ["std", "rand"] # Use this feature to not compile the bundled libsecp256k1 C symbols, # but use external ones. Use this only if you know what you are doing! diff --git a/src/context.rs b/src/context.rs index 80290e6..0e55d59 100644 --- a/src/context.rs +++ b/src/context.rs @@ -31,7 +31,9 @@ pub mod global { static ONCE: Once = Once::new(); static mut CONTEXT: Option> = None; ONCE.call_once(|| unsafe { - CONTEXT = Some(Secp256k1::new()); + let mut ctx = Secp256k1::new(); + ctx.randomize(&mut rand::thread_rng()); + CONTEXT = Some(ctx); }); unsafe { CONTEXT.as_ref().unwrap() } }