Skip to content

Commit

Permalink
Merge pull request #1179 from ethereum/bls-test-pad-issue
Browse files Browse the repository at this point in the history
Bls G2 padding issue
  • Loading branch information
protolambda authored Jun 14, 2019
2 parents 7cf0dcd + aed5db0 commit 79e6850
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test_generators/bls/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
from py_ecc import bls


def int_to_hex(n: int) -> str:
return '0x' + int_to_big_endian(n).hex()
F2Q_COEFF_LEN = 48
G2_COMPRESSED_Z_LEN = 48


def int_to_hex(n: int, byte_length: int=None) -> str:
byte_value = int_to_big_endian(n)
if byte_length:
byte_value = byte_value.rjust(byte_length, b'\x00')
return '0x' + byte_value.hex()


def hex_to_int(x: str) -> int:
Expand Down Expand Up @@ -58,8 +65,8 @@ def hash_message(msg: bytes,
"""
return [
[
int_to_hex(fq2.coeffs[0]),
int_to_hex(fq2.coeffs[1]),
int_to_hex(fq2.coeffs[0], F2Q_COEFF_LEN),
int_to_hex(fq2.coeffs[1], F2Q_COEFF_LEN),
]
for fq2 in bls.utils.hash_to_G2(msg, domain)
]
Expand All @@ -75,8 +82,7 @@ def hash_message_compressed(msg: bytes, domain: int) -> Tuple[str, str]:
- Message hash as a compressed G2 point
"""
z1, z2 = bls.utils.compress_G2(bls.utils.hash_to_G2(msg, domain))
return [int_to_hex(z1), int_to_hex(z2)]

return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)]


@to_tuple
Expand Down

0 comments on commit 79e6850

Please sign in to comment.