only expose BLS tests for the used APIs
This commit is contained in:
parent
dd9325d9fa
commit
3b80e12fc3
|
@ -94,42 +94,12 @@ def hash_message_compressed(msg: bytes) -> Tuple[str, str]:
|
||||||
return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)]
|
return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)]
|
||||||
|
|
||||||
|
|
||||||
def case01_message_hash_G2_uncompressed():
|
def case01_sign():
|
||||||
for msg in MESSAGES:
|
|
||||||
yield f'uncom_g2_hash_{encode_hex(msg)}', {
|
|
||||||
'input': {
|
|
||||||
'message': encode_hex(msg),
|
|
||||||
},
|
|
||||||
'output': hash_message(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def case02_message_hash_G2_compressed():
|
|
||||||
for msg in MESSAGES:
|
|
||||||
yield f'com_g2_hash_{encode_hex(msg)}', {
|
|
||||||
'input': {
|
|
||||||
'message': encode_hex(msg),
|
|
||||||
},
|
|
||||||
'output': hash_message_compressed(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def case03_private_to_public_key():
|
|
||||||
pubkeys = [bls. G2ProofOfPossession.PrivToPub(privkey) for privkey in PRIVKEYS]
|
|
||||||
pubkeys_serial = ['0x' + pubkey.hex() for pubkey in pubkeys]
|
|
||||||
for privkey, pubkey_serial in zip(PRIVKEYS, pubkeys_serial):
|
|
||||||
yield f'priv_to_pub_{int_to_hex(privkey)}', {
|
|
||||||
'input': int_to_hex(privkey),
|
|
||||||
'output': pubkey_serial,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def case04_sign_message():
|
|
||||||
for privkey in PRIVKEYS:
|
for privkey in PRIVKEYS:
|
||||||
for message in MESSAGES:
|
for message in MESSAGES:
|
||||||
sig = bls.G2ProofOfPossession.Sign(privkey, message)
|
sig = bls.G2ProofOfPossession.Sign(privkey, message)
|
||||||
full_name = f'{int_to_hex(privkey)}_{encode_hex(message)}'
|
full_name = f'{int_to_hex(privkey)}_{encode_hex(message)}'
|
||||||
yield f'sign_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
yield f'sign_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
||||||
'input': {
|
'input': {
|
||||||
'privkey': int_to_hex(privkey),
|
'privkey': int_to_hex(privkey),
|
||||||
'message': encode_hex(message),
|
'message': encode_hex(message),
|
||||||
|
@ -138,14 +108,14 @@ def case04_sign_message():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def case05_verify_message():
|
def case02_verify():
|
||||||
for i, privkey in enumerate(PRIVKEYS):
|
for i, privkey in enumerate(PRIVKEYS):
|
||||||
for message in MESSAGES:
|
for message in MESSAGES:
|
||||||
# Valid signature
|
# Valid signature
|
||||||
signature = bls.G2ProofOfPossession.Sign(privkey, message)
|
signature = bls.G2ProofOfPossession.Sign(privkey, message)
|
||||||
pubkey = bls.G2Basic.PrivToPub(privkey)
|
pubkey = bls.G2Basic.PrivToPub(privkey)
|
||||||
full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_valid'
|
full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_valid'
|
||||||
yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
||||||
'input': {
|
'input': {
|
||||||
'pubkey': encode_hex(pubkey),
|
'pubkey': encode_hex(pubkey),
|
||||||
'message': encode_hex(message),
|
'message': encode_hex(message),
|
||||||
|
@ -157,7 +127,7 @@ def case05_verify_message():
|
||||||
# Invalid signatures -- wrong pubkey
|
# Invalid signatures -- wrong pubkey
|
||||||
wrong_pubkey = bls.G2Basic.PrivToPub(PRIVKEYS[(i + 1) % len(PRIVKEYS)])
|
wrong_pubkey = bls.G2Basic.PrivToPub(PRIVKEYS[(i + 1) % len(PRIVKEYS)])
|
||||||
full_name = f'{encode_hex(wrong_pubkey)}_{encode_hex(message)}_wrong_pubkey'
|
full_name = f'{encode_hex(wrong_pubkey)}_{encode_hex(message)}_wrong_pubkey'
|
||||||
yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
||||||
'input': {
|
'input': {
|
||||||
'pubkey': encode_hex(wrong_pubkey),
|
'pubkey': encode_hex(wrong_pubkey),
|
||||||
'message': encode_hex(message),
|
'message': encode_hex(message),
|
||||||
|
@ -169,7 +139,7 @@ def case05_verify_message():
|
||||||
# Invalid signature -- tampered with signature
|
# Invalid signature -- tampered with signature
|
||||||
tampered_signature = signature[:-4] + b'\xFF\xFF\xFF\xFF'
|
tampered_signature = signature[:-4] + b'\xFF\xFF\xFF\xFF'
|
||||||
full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_tampered_signature'
|
full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_tampered_signature'
|
||||||
yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', {
|
||||||
'input': {
|
'input': {
|
||||||
'pubkey': encode_hex(pubkey),
|
'pubkey': encode_hex(pubkey),
|
||||||
'message': encode_hex(message),
|
'message': encode_hex(message),
|
||||||
|
@ -179,25 +149,16 @@ def case05_verify_message():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def case06_aggregate_sigs():
|
def case03_aggregate():
|
||||||
for message in MESSAGES:
|
for message in MESSAGES:
|
||||||
sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in PRIVKEYS]
|
sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in PRIVKEYS]
|
||||||
yield f'agg_sigs_{encode_hex(message)}', {
|
yield f'aggregate_{encode_hex(message)}', {
|
||||||
'input': [encode_hex(sig) for sig in sigs],
|
'input': [encode_hex(sig) for sig in sigs],
|
||||||
'output': encode_hex(bls.G2ProofOfPossession.Aggregate(sigs)),
|
'output': encode_hex(bls.G2ProofOfPossession.Aggregate(sigs)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def case07_aggregate_pubkeys():
|
def case04_fast_aggregate_verify():
|
||||||
pubkeys = [bls.G2Basic.PrivToPub(privkey) for privkey in PRIVKEYS]
|
|
||||||
pubkeys_serial = [encode_hex(pubkey) for pubkey in pubkeys]
|
|
||||||
yield f'agg_pub_keys', {
|
|
||||||
'input': pubkeys_serial,
|
|
||||||
'output': encode_hex(bls.G2ProofOfPossession._AggregatePKs(pubkeys)),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def case08_fast_aggregate_verify():
|
|
||||||
for i, message in enumerate(MESSAGES):
|
for i, message in enumerate(MESSAGES):
|
||||||
privkeys = PRIVKEYS[:i + 1]
|
privkeys = PRIVKEYS[:i + 1]
|
||||||
sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in privkeys]
|
sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in privkeys]
|
||||||
|
@ -242,7 +203,7 @@ def case08_fast_aggregate_verify():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def case09_aggregate_verify():
|
def case05_aggregate_verify():
|
||||||
pairs = []
|
pairs = []
|
||||||
sigs = []
|
sigs = []
|
||||||
for privkey, message in zip(PRIVKEYS, MESSAGES):
|
for privkey, message in zip(PRIVKEYS, MESSAGES):
|
||||||
|
@ -273,10 +234,6 @@ def case09_aggregate_verify():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
# Proof-of-possession
|
|
||||||
|
|
||||||
|
|
||||||
def create_provider(handler_name: str,
|
def create_provider(handler_name: str,
|
||||||
test_case_fn: Callable[[], Iterable[Tuple[str, Dict[str, Any]]]]) -> gen_typing.TestProvider:
|
test_case_fn: Callable[[], Iterable[Tuple[str, Dict[str, Any]]]]) -> gen_typing.TestProvider:
|
||||||
|
|
||||||
|
@ -303,13 +260,9 @@ def create_provider(handler_name: str,
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
gen_runner.run_generator("bls", [
|
gen_runner.run_generator("bls", [
|
||||||
create_provider('msg_hash_uncompressed', case01_message_hash_G2_uncompressed),
|
create_provider('sign', case01_sign),
|
||||||
create_provider('msg_hash_compressed', case02_message_hash_G2_compressed),
|
create_provider('verify', case02_verify),
|
||||||
create_provider('priv_to_pub', case03_private_to_public_key),
|
create_provider('aggregate', case03_aggregate),
|
||||||
create_provider('sign_msg', case04_sign_message),
|
create_provider('fast_aggregate_verify', case04_fast_aggregate_verify),
|
||||||
create_provider('verify_msg', case05_verify_message),
|
create_provider('aggregate_verify', case05_aggregate_verify),
|
||||||
create_provider('aggregate_sigs', case06_aggregate_sigs),
|
|
||||||
create_provider('aggregate_pubkeys', case07_aggregate_pubkeys),
|
|
||||||
create_provider('fast_aggregate_verify', case08_fast_aggregate_verify),
|
|
||||||
create_provider('aggregate_verify', case09_aggregate_verify),
|
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in New Issue