@@ -10,7 +10,7 @@ use secp256k1_sys::types::{c_int, c_uchar, c_void};
10
10
11
11
use crate :: ffi:: { self , CPtr } ;
12
12
use crate :: key:: { PublicKey , SecretKey } ;
13
- use crate :: { constants, Error } ;
13
+ use crate :: { constants, Error , Secp256k1 } ;
14
14
15
15
// The logic for displaying shared secrets relies on this (see `secret.rs`).
16
16
const SHARED_SECRET_SIZE : usize = constants:: SECRET_KEY_SIZE ;
@@ -39,14 +39,20 @@ impl SharedSecret {
39
39
#[ inline]
40
40
pub fn new ( point : & PublicKey , scalar : & SecretKey ) -> SharedSecret {
41
41
let mut buf = [ 0u8 ; SHARED_SECRET_SIZE ] ;
42
+
42
43
let res = unsafe {
43
- ffi:: secp256k1_ecdh (
44
- ffi:: secp256k1_context_no_precomp,
45
- buf. as_mut_ptr ( ) ,
46
- point. as_c_ptr ( ) ,
47
- scalar. as_c_ptr ( ) ,
48
- ffi:: secp256k1_ecdh_hash_function_default,
49
- ptr:: null_mut ( ) ,
44
+ crate :: with_global_context (
45
+ |secp : & Secp256k1 < crate :: AllPreallocated > | {
46
+ ffi:: secp256k1_ecdh (
47
+ secp. ctx . as_ptr ( ) ,
48
+ buf. as_mut_ptr ( ) ,
49
+ point. as_c_ptr ( ) ,
50
+ scalar. as_c_ptr ( ) ,
51
+ ffi:: secp256k1_ecdh_hash_function_default,
52
+ ptr:: null_mut ( ) ,
53
+ )
54
+ } ,
55
+ None ,
50
56
)
51
57
} ;
52
58
debug_assert_eq ! ( res, 1 ) ;
@@ -125,13 +131,18 @@ pub fn shared_secret_point(point: &PublicKey, scalar: &SecretKey) -> [u8; 64] {
125
131
let mut xy = [ 0u8 ; 64 ] ;
126
132
127
133
let res = unsafe {
128
- ffi:: secp256k1_ecdh (
129
- ffi:: secp256k1_context_no_precomp,
130
- xy. as_mut_ptr ( ) ,
131
- point. as_c_ptr ( ) ,
132
- scalar. as_c_ptr ( ) ,
133
- Some ( c_callback) ,
134
- ptr:: null_mut ( ) ,
134
+ crate :: with_global_context (
135
+ |secp : & Secp256k1 < crate :: AllPreallocated > | {
136
+ ffi:: secp256k1_ecdh (
137
+ secp. ctx . as_ptr ( ) ,
138
+ xy. as_mut_ptr ( ) ,
139
+ point. as_c_ptr ( ) ,
140
+ scalar. as_c_ptr ( ) ,
141
+ Some ( c_callback) ,
142
+ ptr:: null_mut ( ) ,
143
+ )
144
+ } ,
145
+ None ,
135
146
)
136
147
} ;
137
148
// Our callback *always* returns 1.
0 commit comments