From 9dc0019ada9e3f61e6d07d2047e86a033a698077 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Tue, 22 Oct 2024 13:58:39 +0200 Subject: [PATCH] Use utility-functions for byte conversion --- fido2/arkg.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fido2/arkg.py b/fido2/arkg.py index 10b94c4f..14ad4b25 100644 --- a/fido2/arkg.py +++ b/fido2/arkg.py @@ -1,4 +1,5 @@ from .cose import CoseKey +from .utils import int2bytes, bytes2int from cryptography.hazmat.primitives.hashes import SHA256, Hash, HashAlgorithm from cryptography.hazmat.primitives.hmac import HMAC @@ -64,7 +65,7 @@ def hash_to_field(msg, count, dst, p, L, H): for i in range(count): offset = L * i tv = uniform_bytes[offset : offset + L] - e_j = int.from_bytes(tv) % p + e_j = bytes2int(tv) % p elements.append(e_j) return elements @@ -102,7 +103,7 @@ def hash_to_field(self, msg, count): for i in range(count): offset = self.L * i tv = uniform_bytes[offset : offset + self.L] - e_j = int.from_bytes(tv) % self.p + e_j = bytes2int(tv) % self.p elements.append(e_j) return elements @@ -169,7 +170,7 @@ def sub_kem_encaps(self, pk: Point, info: bytes) -> Tuple[bytes, bytes]: c = Elliptic-Curve-Point-to-Octet-String(pk') """ pk_prime, sk_prime = self.sub_kem_generate() - k = int.to_bytes((pk * sk_prime).x, 32) + k = int2bytes((pk * sk_prime).x, 32) c = SEC1Encoder().encode_public_key(pk_prime, compressed=False) return k, c @@ -321,8 +322,8 @@ def derive_public_key(self, info: bytes) -> Tuple[CoseKey, bytes]: 1: 2, 3: -7, -1: 1, - -2: int.to_bytes(point.x, 32), - -3: int.to_bytes(point.y, 32), + -2: int2bytes(point.x, 32), + -3: int2bytes(point.y, 32), } ) return pk, kh