Update bls_verify.md

This commit is contained in:
Justin 2018-12-10 14:30:36 +00:00 committed by GitHub
parent c782725aa1
commit 411d347b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -67,17 +67,18 @@ G2_cofactor = 305502333931268344200999753193121504214466019254188142667664032982
q = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab q = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab
def hash_to_G2(message, domain): def hash_to_G2(message, domain):
x1 = int.from_bytes(hash(bytes8(domain) + b'\x01' + message), 'big') # Initial candidate x coordinate
x2 = int.from_bytes(hash(bytes8(domain) + b'\x02' + message), 'big') x_re = int.from_bytes(hash(bytes8(domain) + b'\x01' + message), 'big')
x_coordinate = FQ2([x1, x2]) # x1 + x2 * i x_im = int.from_bytes(hash(bytes8(domain) + b'\x02' + message), 'big')
x_coordinate = FQ2([x_re, x_im]) # x = x_re + i * x_im
# Test candidate y coordinates until a one is found
while 1: while 1:
x_cubed_plus_b2 = x_coordinate ** 3 + FQ2([4, 4]) y_coordinate_squared = x_coordinate ** 3 + FQ2([4, 4]) # The curve is y^2 = x^3 + 4(i + 1)
y_coordinate = modular_squareroot(x_cubed_plus_b2) y_coordinate = modular_squareroot(y_coordinate_squared)
if y_coordinate is not None: if y_coordinate is not None: # Check if quadratic residue found
break return multiply_in_G2((x_coordinate, y_coordinate), G2_cofactor)
x_coordinate += FQ2([1, 0]) # Add one until we get a quadratic residue x_coordinate += FQ2([1, 0]) # Add 1 and try again
assert is_on_G2((x_coordinate, y_coordinate))
return multiply_in_G2((x_coordinate, y_coordinate), G2_cofactor)
``` ```
### `modular_squareroot` ### `modular_squareroot`