Merge pull request #108 from ethereum/eip2333_blsv4

Support the updated EIP2333 (BLS v4)
This commit is contained in:
Carl Beekhuizen 2020-09-22 12:22:05 +02:00 committed by GitHub
commit 59156d95c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 20 deletions

View File

@ -48,13 +48,18 @@ def _HKDF_mod_r(*, IKM: bytes, key_info: bytes=b'') -> int:
Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2333.md#hkdf_mod_r
"""
L = 48 # `ceil((3 * ceil(log2(r))) / 16)`, where `r` is the order of the BLS 12-381 curve
okm = HKDF(
salt=b'BLS-SIG-KEYGEN-SALT-',
IKM=IKM + b'\x00', # add postfix `I2OSP(0, 1)`
L=L,
info=key_info + L.to_bytes(2, 'big'),
)
return int.from_bytes(okm, byteorder='big') % bls_curve_order
salt = b'BLS-SIG-KEYGEN-SALT-'
SK = 0
while SK == 0:
salt = SHA256(salt)
okm = HKDF(
salt=salt,
IKM=IKM + b'\x00', # add postfix `I2OSP(0, 1)`
L=L,
info=key_info + L.to_bytes(2, 'big'),
)
SK = int.from_bytes(okm, byteorder='big') % bls_curve_order
return SK
def derive_child_SK(*, parent_SK: int, index: int) -> int:

View File

@ -17,6 +17,7 @@ with open(test_vector_filefolder, 'r') as f:
test_vectors = json.load(f)['kdf_tests']
@pytest.mark.skip(reason="py_ecc doesn't support BLS v4 yet")
@pytest.mark.parametrize(
'test',
test_vectors
@ -26,6 +27,7 @@ def test_hkdf_mod_r(test) -> None:
assert bls.KeyGen(seed) == _HKDF_mod_r(IKM=seed)
@pytest.mark.skip(reason="py_ecc doesn't support BLS v4 yet")
@pytest.mark.parametrize(
'seed',
[b'\x00' * 32]

View File

@ -2,27 +2,27 @@
"kdf_tests": [
{
"seed": "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04",
"master_SK": 5399117110774477986698372024995405256382522670366369834617409486544348441851,
"master_SK": 6083874454709270928345386274498605044986640685124978867557563392430687146096,
"child_index": 0,
"child_SK": 11812940737387919040225825939013910852517748782307378293770044673328955938106
"child_SK": 20397789859736650942317412262472558107875392172444076792671091975210932703118
},
{
"seed": "3141592653589793238462643383279502884197169399375105820974944592",
"master_SK": 36167147331491996618072159372207345412841461318189449162487002442599770291484,
"master_SK": 29757020647961307431480504535336562678282505419141012933316116377660817309383,
"child_index": 3141592653,
"child_SK": 41787458189896526028601807066547832426569899195138584349427756863968330588237
"child_SK": 25457201688850691947727629385191704516744796114925897962676248250929345014287
},
{
"seed": "0099FF991111002299DD7744EE3355BBDD8844115566CC55663355668888CC00",
"master_SK": 13904094584487173309420026178174172335998687531503061311232927109397516192843,
"master_SK": 27580842291869792442942448775674722299803720648445448686099262467207037398656,
"child_index": 4294967295,
"child_SK": 12482522899285304316694838079579801944734479969002030150864436005368716366140
"child_SK": 29358610794459428860402234341874281240803786294062035874021252734817515685787
},
{
"seed": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"master_SK": 44010626067374404458092393860968061149521094673473131545188652121635313364506,
"master_SK": 19022158461524446591288038168518313374041767046816487870552872741050760015818,
"child_index": 42,
"child_SK": 4011524214304750350566588165922015929937602165683407445189263506512578573606
"child_SK": 31372231650479070279774297061823572166496564838472787488249775572789064611981
}
]
}

File diff suppressed because one or more lines are too long