蟻ーヴェデルチ

覚悟はいいか?

KDF1

Key Derivation Functions: How many KDFs are there?

KDF1というのを調べる機会があって、結果を確認するためのコードをpythonで書いてみた。KDF1は鍵導出関数というものの一種らしい。

from binascii import unhexlify
from hashlib import sha1
from math import ceil

Z = ''.join(chr(x) for x in range(0, 16))
Hash = sha1(Z).digest()

d = int(ceil((float)(len(Z)) / len(Hash)))
T = ''
other = 'Hello KDF1'

for c in range(0, d): 
    C = unhexlify('%08X' % c)
    T = T + sha1(Z + C + other).digest()

print('Z:    ' + Z.encode('hex'))
print('KDF1: ' + T[:len(Z)].encode('hex'))

便宜上sha1にしているけれど、別のアルゴリズムでもOKなはず。実はこれでええのかイマイチ自信はない!