2727 ML_DSA_87_NAME ,
2828 ML_DSA_87_SK_LEN ,
2929 ML_DSA_87_PK_LEN ,
30- ML_DSA_87_SIGN_LEN
30+ ML_DSA_87_SIGN_LEN ,
31+ ML_BUFFER_LIMITS
3132)
3233
34+
3335def create_signature (algorithm : str , message : bytes , private_key : bytes ) -> bytes :
3436 """
3537 Creates a digital signature for a message using a post-quantum signature scheme.
@@ -42,7 +44,7 @@ def create_signature(algorithm: str, message: bytes, private_key: bytes) -> byte
4244 Returns:
4345 Signature bytes of fixed size defined by the algorithm.
4446 """
45- with oqs .Signature (algorithm , secret_key = private_key ) as signer :
47+ with oqs .Signature (algorithm , secret_key = private_key [: ML_BUFFER_LIMITS [ algorithm ][ "SK_LEN" ]] ) as signer :
4648 return signer .sign (message )
4749
4850def verify_signature (algorithm : str , message : bytes , signature : bytes , public_key : bytes ) -> bool :
@@ -59,7 +61,7 @@ def verify_signature(algorithm: str, message: bytes, signature: bytes, public_ke
5961 True if valid, False if invalid.
6062 """
6163 with oqs .Signature (algorithm ) as verifier :
62- return verifier .verify (message , signature , public_key )
64+ return verifier .verify (message , signature , public_key [: ML_BUFFER_LIMITS [ algorithm ][ "PK_LEN" ]] )
6365
6466def generate_sign_keys (algorithm : str = ML_DSA_87_NAME ):
6567 """
@@ -166,7 +168,7 @@ def decrypt_kyber_shared_secrets(ciphertext_blob: bytes, private_key: bytes, otp
166168 shared_secrets = b''
167169 cursor = 0
168170
169- with oqs .KeyEncapsulation (ML_KEM_1024_NAME , secret_key = private_key ) as kem :
171+ with oqs .KeyEncapsulation (ML_KEM_1024_NAME , secret_key = private_key [: ML_BUFFER_LIMITS [ ML_KEM_1024_NAME ][ "SK_LEN" ]] ) as kem :
170172 while len (shared_secrets ) < otp_pad_size :
171173 ciphertext = ciphertext_blob [cursor :cursor + cipher_size ]
172174 if len (ciphertext ) != cipher_size :
@@ -193,7 +195,7 @@ def generate_kyber_shared_secrets(public_key: bytes, otp_pad_size: int = OTP_PAD
193195
194196 with oqs .KeyEncapsulation (ML_KEM_1024_NAME ) as kem :
195197 while len (shared_secrets ) < otp_pad_size :
196- ciphertext , shared_secret = kem .encap_secret (public_key )
198+ ciphertext , shared_secret = kem .encap_secret (public_key [: ML_BUFFER_LIMITS [ ML_KEM_1024_NAME ][ "PK_LEN" ]] )
197199 ciphertexts_blob += ciphertext
198200 shared_secrets += shared_secret
199201
0 commit comments