From dc9a5976ff65cd878ff04ad8f863be0266912a66 Mon Sep 17 00:00:00 2001 From: Vlad Gheorghiu Date: Wed, 15 Jan 2025 09:41:03 -0500 Subject: [PATCH] Update Signed-off-by: Vlad Gheorghiu --- oqs/oqs.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/oqs/oqs.py b/oqs/oqs.py index cd5fcb5..cfa3065 100644 --- a/oqs/oqs.py +++ b/oqs/oqs.py @@ -266,7 +266,11 @@ def generate_keypair(self): rv = native().OQS_KEM_keypair( self._kem, ct.byref(public_key), ct.byref(self.secret_key) ) - return bytes(public_key) if rv == OQS_SUCCESS else 0 + return ( + bytes(public_key) + if rv == OQS_SUCCESS + else RuntimeError("Can not generate keypair") + ) def export_secret_key(self): """Exports the secret key.""" @@ -286,7 +290,11 @@ def encap_secret(self, public_key): rv = native().OQS_KEM_encaps( self._kem, ct.byref(ciphertext), ct.byref(shared_secret), c_public_key ) - return bytes(ciphertext), bytes(shared_secret) if rv == OQS_SUCCESS else 0 + return bytes(ciphertext), ( + bytes(shared_secret) + if rv == OQS_SUCCESS + else RuntimeError("Can not encapsulate secret") + ) def decap_secret(self, ciphertext): """ @@ -301,7 +309,11 @@ def decap_secret(self, ciphertext): rv = native().OQS_KEM_decaps( self._kem, ct.byref(shared_secret), c_ciphertext, self.secret_key ) - return bytes(shared_secret) if rv == OQS_SUCCESS else 0 + return ( + bytes(shared_secret) + if rv == OQS_SUCCESS + else RuntimeError("Can not decapsulate secret") + ) def free(self): """Releases the native resources.""" @@ -423,7 +435,11 @@ def generate_keypair(self): rv = native().OQS_SIG_keypair( self._sig, ct.byref(public_key), ct.byref(self.secret_key) ) - return bytes(public_key) if rv == OQS_SUCCESS else 0 + return ( + bytes(public_key) + if rv == OQS_SUCCESS + else RuntimeError("Can not generate keypair") + ) def export_secret_key(self): """Exports the secret key.""" @@ -451,8 +467,11 @@ def sign(self, message): message_len, self.secret_key, ) - - return bytes(c_signature[: signature_len.value]) if rv == OQS_SUCCESS else 0 + return ( + bytes(c_signature[: signature_len.value]) + if rv == OQS_SUCCESS + else RuntimeError("Can not sign message") + ) def verify(self, message, signature, public_key): """ @@ -479,7 +498,6 @@ def verify(self, message, signature, public_key): signature_len, c_public_key, ) - return True if rv == OQS_SUCCESS else False def sign_with_ctx_str(self, message, context): @@ -509,8 +527,11 @@ def sign_with_ctx_str(self, message, context): context_len, self.secret_key, ) - - return bytes(c_signature[: signature_len.value]) if rv == OQS_SUCCESS else 0 + return ( + bytes(c_signature[: signature_len.value]) + if rv == OQS_SUCCESS + else RuntimeError("Can not sign message with context string") + ) def verify_with_ctx_str(self, message, signature, context, public_key): """ @@ -542,7 +563,6 @@ def verify_with_ctx_str(self, message, signature, context, public_key): context_len, c_public_key, ) - return True if rv == OQS_SUCCESS else False def free(self):