diff options
author | Jonas Nick <jonasd.nick@gmail.com> | 2019-09-26 21:12:21 +0000 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2020-01-19 14:47:33 -0800 |
commit | 78bb31c3bf1aa9459643653e07715d597df4a24f (patch) | |
tree | 5da66a409f36ee614c49d02728525b1e4cdac011 | |
parent | e0e422a5cad47653a092b175dfb1878fef021b0b (diff) | |
download | bips-78bb31c3bf1aa9459643653e07715d597df4a24f.tar.xz |
Accept seckey in the form of bytes and not int in the reference BIP-schnorr code to match the spec.
-rw-r--r-- | bip-schnorr/reference.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/bip-schnorr/reference.py b/bip-schnorr/reference.py index 016ce97..e5d9557 100644 --- a/bip-schnorr/reference.py +++ b/bip-schnorr/reference.py @@ -66,12 +66,16 @@ def is_quad(x): return jacobi(x) == 1 def pubkey_gen(seckey): - P = point_mul(G, seckey) + x = int_from_bytes(seckey) + if not (1 <= x <= n - 1): + raise ValueError('The secret key must be an integer in the range 1..n-1.') + P = point_mul(G, x) return bytes_from_point(P) def schnorr_sign(msg, seckey0): if len(msg) != 32: raise ValueError('The message must be a 32-byte array.') + seckey0 = int_from_bytes(seckey0) if not (1 <= seckey0 <= n - 1): raise ValueError('The secret key must be an integer in the range 1..n-1.') P = point_mul(G, seckey0) @@ -122,7 +126,7 @@ def test_vectors(): result = result == 'TRUE' print('\nTest vector #%-3i: ' % int(index)) if seckey != '': - seckey = int(seckey, 16) + seckey = bytes.fromhex(seckey) pubkey_actual = pubkey_gen(seckey) if pubkey != pubkey_actual: print(' * Failed key generation.') |