Fix accessory key generation

This commit is contained in:
Mike A
2024-02-07 17:45:40 +01:00
parent d4a5fcef10
commit 612fe63408
2 changed files with 21 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
"""Pure-python NIST P-224 Elliptic Curve cryptography. Used for some Apple algorithms."""
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.hashes import SHA1
from cryptography.hazmat.primitives.kdf.x963kdf import X963KDF
ECPoint = tuple[float, float]
@@ -71,7 +71,7 @@ P224_P = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001
def x963_kdf(value: bytes, si: bytes, length: int) -> bytes:
"""Single pass of X9.63 KDF with SHA1."""
return X963KDF(
algorithm=SHA1(), # noqa: S303
algorithm=hashes.SHA256(),
sharedinfo=si,
length=length,
).derive(value)
@@ -86,7 +86,7 @@ def derive_ps_key(privkey: bytes, sk: bytes) -> bytes:
"""
Derive a primary or secondary key used by an accessory.
:param pubkey: Public key generated during pairing
:param privkey: Private key generated during pairing
:param sk: Current secret key for this time period.
Use SKN to derive the primary key, SKS for secondary.
"""