mirror of
https://github.com/bitcoin/bips.git
synced 2026-04-06 16:16:45 +00:00
bip340: Allow variable-length messages
This commit is contained in:
committed by
Pieter Wuille
parent
6163d36d0b
commit
200f9b26fe
@@ -96,8 +96,6 @@ def pubkey_gen(seckey: bytes) -> bytes:
|
||||
return bytes_from_point(P)
|
||||
|
||||
def schnorr_sign(msg: bytes, seckey: bytes, aux_rand: bytes) -> bytes:
|
||||
if len(msg) != 32:
|
||||
raise ValueError('The message must be a 32-byte array.')
|
||||
d0 = int_from_bytes(seckey)
|
||||
if not (1 <= d0 <= n - 1):
|
||||
raise ValueError('The secret key must be an integer in the range 1..n-1.')
|
||||
@@ -121,8 +119,6 @@ def schnorr_sign(msg: bytes, seckey: bytes, aux_rand: bytes) -> bytes:
|
||||
return sig
|
||||
|
||||
def schnorr_verify(msg: bytes, pubkey: bytes, sig: bytes) -> bool:
|
||||
if len(msg) != 32:
|
||||
raise ValueError('The message must be a 32-byte array.')
|
||||
if len(pubkey) != 32:
|
||||
raise ValueError('The public key must be a 32-byte array.')
|
||||
if len(sig) != 64:
|
||||
|
||||
@@ -14,3 +14,7 @@ index,secret key,public key,aux_rand,message,signature,verification result,comme
|
||||
12,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F69E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,sig[0:32] is equal to field size
|
||||
13,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E177769FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141,FALSE,sig[32:64] is equal to curve order
|
||||
14,,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC30,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E17776969E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,public key is not a valid X coordinate because it exceeds the field size
|
||||
15,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,,71535DB165ECD9FBBC046E5FFAEA61186BB6AD436732FCCC25291A55895464CF6069CE26BF03466228F19A3A62DB8A649F2D560FAC652827D1AF0574E427AB63,TRUE,message of size 0 (added 2022-12)
|
||||
16,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,11,08A20A0AFEF64124649232E0693C583AB1B9934AE63B4C3511F3AE1134C6A303EA3173BFEA6683BD101FA5AA5DBC1996FE7CACFC5A577D33EC14564CEC2BACBF,TRUE,message of size 1 (added 2022-12)
|
||||
17,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,0102030405060708090A0B0C0D0E0F1011,5130F39A4059B43BC7CAC09A19ECE52B5D8699D1A71E3C52DA9AFDB6B50AC370C4A482B77BF960F8681540E25B6771ECE1E5A37FD80E5A51897C5566A97EA5A5,TRUE,message of size 17 (added 2022-12)
|
||||
18,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999,403B12B0D8555A344175EA7EC746566303321E5DBFA8BE6F091635163ECA79A8585ED3E3170807E7C03B720FC54C7B23897FCBA0E9D0B4A06894CFD249F22367,TRUE,message of size 100 (added 2022-12)
|
||||
|
||||
|
@@ -249,6 +249,20 @@ def vector14():
|
||||
|
||||
return (None, pubkey, None, msg, sig, "FALSE", "public key is not a valid X coordinate because it exceeds the field size")
|
||||
|
||||
def varlen_vector(msg_int):
|
||||
seckey = bytes_from_int(int(16 * "0340", 16))
|
||||
pubkey = pubkey_gen(seckey)
|
||||
aux_rand = bytes_from_int(0)
|
||||
msg = msg_int.to_bytes((msg_int.bit_length() + 7) // 8, "big")
|
||||
sig = schnorr_sign(msg, seckey, aux_rand)
|
||||
comment = "message of size %d (added 2022-12)"
|
||||
return (seckey, pubkey, aux_rand, msg, sig, "TRUE", comment % len(msg))
|
||||
|
||||
vector15 = lambda : varlen_vector(0)
|
||||
vector16 = lambda : varlen_vector(0x11)
|
||||
vector17 = lambda : varlen_vector(0x0102030405060708090A0B0C0D0E0F1011)
|
||||
vector18 = lambda : varlen_vector(int(100 * "99", 16))
|
||||
|
||||
vectors = [
|
||||
vector0(),
|
||||
vector1(),
|
||||
@@ -264,7 +278,11 @@ vectors = [
|
||||
vector11(),
|
||||
vector12(),
|
||||
vector13(),
|
||||
vector14()
|
||||
vector14(),
|
||||
vector15(),
|
||||
vector16(),
|
||||
vector17(),
|
||||
vector18(),
|
||||
]
|
||||
|
||||
# Converts the byte strings of a test vector into hex strings
|
||||
|
||||
Reference in New Issue
Block a user