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 dc9a597 commit 6a164a6
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions oqs/oqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@ 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 RuntimeError("Can not generate keypair")
)
if rv == OQS_SUCCESS:
return bytes(public_key)
else:
raise RuntimeError("Can not generate keypair")

def export_secret_key(self):
"""Exports the secret key."""
Expand All @@ -290,11 +289,10 @@ 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 RuntimeError("Can not encapsulate secret")
)
if rv == OQS_SUCCESS:
return bytes(ciphertext), bytes(shared_secret)
else:
raise RuntimeError("Can not encapsulate secret")

def decap_secret(self, ciphertext):
"""
Expand All @@ -309,11 +307,10 @@ 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 RuntimeError("Can not decapsulate secret")
)
if rv == OQS_SUCCESS:
return bytes(shared_secret)
else:
raise RuntimeError("Can not decapsulate secret")

def free(self):
"""Releases the native resources."""
Expand Down Expand Up @@ -435,11 +432,10 @@ 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 RuntimeError("Can not generate keypair")
)
if rv == OQS_SUCCESS:
return bytes(public_key)
else:
raise RuntimeError("Can not generate keypair")

def export_secret_key(self):
"""Exports the secret key."""
Expand Down Expand Up @@ -467,11 +463,10 @@ def sign(self, message):
message_len,
self.secret_key,
)
return (
bytes(c_signature[: signature_len.value])
if rv == OQS_SUCCESS
else RuntimeError("Can not sign message")
)
if rv == OQS_SUCCESS:
return bytes(c_signature[: signature_len.value])
else:
raise RuntimeError("Can not sign message")

def verify(self, message, signature, public_key):
"""
Expand Down Expand Up @@ -527,11 +522,10 @@ 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 RuntimeError("Can not sign message with context string")
)
if rv == OQS_SUCCESS:
return bytes(c_signature[: signature_len.value])
else:
raise RuntimeError("Can not sign message with context string")

def verify_with_ctx_str(self, message, signature, context, public_key):
"""
Expand Down

0 comments on commit 6a164a6

Please sign in to comment.