From 0d05bfb886c272614d835297bba5fee4ee936bf2 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Thu, 10 Oct 2024 13:48:54 -0400 Subject: [PATCH] ffi/python: enable Seed.keygen(strength) This is just another simple way to generate a key from seed based on the strength of the desired object. --- ffi/python/fips203.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ffi/python/fips203.py b/ffi/python/fips203.py index 7a7a2b4..b1a2b00 100644 --- a/ffi/python/fips203.py +++ b/ffi/python/fips203.py @@ -97,6 +97,7 @@ Please report issues at https://github.com/integritychain/fips203/issues ''' +from __future__ import annotations '''__version__ should track package.version from ../Cargo.toml''' __version__ = '0.4.0' @@ -158,6 +159,12 @@ def __repr__(self) -> str: def __bytes__(self) -> bytes: return bytes(self._seed.data) + def keygen(self, strength: int) -> Tuple[EncapsulationKey, DecapsulationKey]: + for kt in ML_KEM_512, ML_KEM_768, ML_KEM_1024: + if kt._strength == strength: + return kt.keygen(self) + raise Exception(f"Unknown strength: {strength}, must be 512, 768, or 1024.") + class Ciphertext(): '''ML-KEM Ciphertext