Skip to content

Commit

Permalink
ffi/python: enable Seed.keygen(strength)
Browse files Browse the repository at this point in the history
This is just another simple way to generate a key from seed based on
the strength of the desired object.
  • Loading branch information
dkg committed Oct 10, 2024
1 parent 8346566 commit 0d05bfb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ffi/python/fips203.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0d05bfb

Please sign in to comment.