Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Gheorghiu <[email protected]>
  • Loading branch information
vsoftco committed Jan 15, 2025
1 parent ebc8657 commit dc9a597
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions oqs/oqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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):
"""
Expand All @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit dc9a597

Please sign in to comment.