В приложении я нашел тестовые векторы SAE, однако у меня проблема в функции KDF.
Моя функция KDF:
Код: Выделить всё
import hmac
import hashlib
from math import ceil
def kdf(k: bytes):
"""
KDF-SHA-256-256
:k: password-seed (H[max(mac_a, mac_b) || min(mac_a, mac_b), password || counter])
:label: ASCII string indetifying the purpose of the keys derived.
:context: bit string that provides context to identify the derived key
:return: A length-bit derived key
"""
label = b"SAE Hunting and Pecking"
context = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF # Prime number for DH Group 19
length = 256 # Length of the derived key in bits
hash_len = 32 * 8 # Length of the digest produced by hash function (in bits)
iterations = ceil(length / hash_len)
result = b""
for i in range(1, iterations + 1):
data = i.to_bytes(2, "big") + label + context + length.to_bytes(2, "big")
result = result + H(key=k, data=data)
return result[:length]
def H(key: bytes, data: bytes):
"""
:data: message to use
:key: key to use
"""
return hmac.new(key, data, hashlib.sha256).digest()
Код: Выделить всё
group: 19
Password: ‘thisisreallysecret’
Local MAC address: 7b-88-56-20-2d-8d
Peer’s MAC address: e2-47-1c-0a-5a-cb
H(e2-47-1c-0a-5a-cb || 7b-88-56-20-2d-8d, thisisreallysecret || 1)
69f69099 83675392 d0a3a882 47ffef20 413ee972 15872942 4415e139 46ecc206
candidate x value:
a16729e0 339c38f8 b06e2b83 76d43066 85578354 ab09d848 a0f140ac 825e6a3d
Любой мысли о моих ошибках?
Подробнее здесь: https://stackoverflow.com/questions/790 ... -in-python