Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bip-schnorr/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ def jacobi(x):
return pow(x, (p - 1) // 2, p)

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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to d as in the pseudocode? Then we don't need to overwrite the variable and its more consistent with the text.

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)
Expand Down Expand Up @@ -113,7 +117,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.')
Expand Down