Skip to content

Commit 560513f

Browse files
committed
call secp256k1_context_randomize() on _libsecp256k1_context
1 parent cdcfd3b commit 560513f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

bitcoin/core/key.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import ctypes.util
2020
import hashlib
2121
import sys
22+
from os import urandom
2223
import bitcoin
2324
import bitcoin.signature
2425

@@ -227,8 +228,15 @@ def use_libsecp256k1_for_signing(do_use):
227228
_libsecp256k1 = ctypes.cdll.LoadLibrary(_libsecp256k1_path)
228229
_libsecp256k1.secp256k1_context_create.restype = ctypes.c_void_p
229230
_libsecp256k1.secp256k1_context_create.errcheck = _check_res_void_p
231+
_libsecp256k1.secp256k1_context_randomize.restype = ctypes.c_int
232+
_libsecp256k1.secp256k1_context_randomize.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
230233
_libsecp256k1_context = _libsecp256k1.secp256k1_context_create(SECP256K1_CONTEXT_SIGN)
231234
assert(_libsecp256k1_context is not None)
235+
seed = urandom(32)
236+
result = _libsecp256k1.secp256k1_context_randomize(_libsecp256k1_context, seed)
237+
assert 1 == result
238+
239+
232240

233241
_libsecp256k1_enable_signing = True
234242

0 commit comments

Comments
 (0)