def kdf(key_material):
"""NIST SP 800-56a Concatenation Key Derivation Function (see section 5.8.1).
Pretty much copied from geth's implementation:
https://github.com/ethereum/go-ethereum/blob/673007d7aed1d2678ea3277eceb7b55dc29cf092/crypto/ecies/ecies.go#L167
"""
key = b""
hash_blocksize = hashes.SHA256().block_size
reps = ((KEY_LEN + 7) * 8) / (hash_blocksize * 8)
counter = 0
while counter <= reps:
counter += 1
ctx = sha256()
ctx.update(struct.pack('>I', counter))
ctx.update(key_material)
key += ctx.digest()
return key[:KEY_LEN]
评论列表
文章目录