Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions oqs/oqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,24 @@ def __init__(self, alg_name, secret_key=None):

self._kem = native().OQS_KEM_new(ct.create_string_buffer(alg_name.encode()))

self.method_name = self._kem.contents.method_name
self.alg_version = self._kem.contents.alg_version
self.claimed_nist_level = self._kem.contents.claimed_nist_level
self.ind_cca = self._kem.contents.ind_cca
self.length_public_key = self._kem.contents.length_public_key
self.length_secret_key = self._kem.contents.length_secret_key
self.length_ciphertext = self._kem.contents.length_ciphertext
self.length_shared_secret = self._kem.contents.length_shared_secret

self.details = {
"name": self._kem.contents.method_name.decode(),
"version": self._kem.contents.alg_version.decode(),
"claimed_nist_level": int(self._kem.contents.claimed_nist_level),
"is_ind_cca": bool(self._kem.contents.ind_cca),
"length_public_key": int(self._kem.contents.length_public_key),
"length_secret_key": int(self._kem.contents.length_secret_key),
"length_ciphertext": int(self._kem.contents.length_ciphertext),
"length_shared_secret": int(self._kem.contents.length_shared_secret),
"name": self.method_name.decode(),
"version": self.alg_version.decode(),
"claimed_nist_level": int(self.claimed_nist_level),
"is_ind_cca": bool(self.ind_cca),
"length_public_key": int(self.length_public_key),
"length_secret_key": int(self.length_secret_key),
"length_ciphertext": int(self.length_ciphertext),
"length_shared_secret": int(self.length_shared_secret),
}

if secret_key:
Expand Down Expand Up @@ -412,15 +421,25 @@ def __init__(self, alg_name, secret_key=None):
raise MechanismNotSupportedError(alg_name)

self._sig = native().OQS_SIG_new(ct.create_string_buffer(alg_name.encode()))

self.method_name = self._sig.contents.method_name
self.alg_version = self._sig.contents.alg_version
self.claimed_nist_level = self._sig.contents.claimed_nist_level
self.euf_cma = self._sig.contents.euf_cma
self.sig_with_ctx_support = self._sig.contents.sig_with_ctx_support
self.length_public_key = self._sig.contents.length_public_key
self.length_secret_key = self._sig.contents.length_secret_key
self.length_signature = self._sig.contents.length_signature

self.details = {
"name": self._sig.contents.method_name.decode(),
"version": self._sig.contents.alg_version.decode(),
"claimed_nist_level": int(self._sig.contents.claimed_nist_level),
"is_euf_cma": bool(self._sig.contents.euf_cma),
"sig_with_ctx_support": bool(self._sig.contents.sig_with_ctx_support),
"length_public_key": int(self._sig.contents.length_public_key),
"length_secret_key": int(self._sig.contents.length_secret_key),
"length_signature": int(self._sig.contents.length_signature),
"name": self.method_name.decode(),
"version": self.alg_version.decode(),
"claimed_nist_level": int(self.claimed_nist_level),
"is_euf_cma": bool(self.euf_cma),
"sig_with_ctx_support": bool(self.sig_with_ctx_support),
"length_public_key": int(self.length_public_key),
"length_secret_key": int(self.length_secret_key),
"length_signature": int(self.length_signature),
}

if secret_key:
Expand Down
21 changes: 20 additions & 1 deletion tests/test_kem.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,31 @@ def test_not_enabled():
raise AssertionError(f"An unexpected exception was raised: {ex}")


def test_python_attributes():
for alg_name in oqs.get_enabled_kem_mechanisms():
with oqs.KeyEncapsulation(alg_name) as kem:
if kem.method_name.decode() != alg_name:
raise AssertionError("Incorrect oqs.KeyEncapsulation.method_name")
if kem.alg_version is None:
raise AssertionError("Undefined oqs.KeyEncapsulation.alg_version")
if not 1 <= kem.claimed_nist_level <= 5:
raise AssertionError("Invalid oqs.KeyEncapsulation.claimed_nist_level")
if kem.length_public_key == 0:
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_public_key")
if kem.length_secret_key == 0:
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_secret_key")
if kem.length_ciphertext == 0:
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_signature")
if kem.length_shared_secret == 0:
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_shared_secret")


if __name__ == "__main__":
try:
import nose2

nose2.main()
except ImportError:
raise RuntimeError(
"nose2 module not found. Please install it with 'pip install node2'."
"nose2 module not found. Please install it with 'pip install nose2'."
)
19 changes: 18 additions & 1 deletion tests/test_sig.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,29 @@ def test_not_enabled():
raise AssertionError(f"An unexpected exception was raised: {ex}")


def test_python_attributes():
for alg_name in oqs.get_enabled_sig_mechanisms():
with oqs.Signature(alg_name) as sig:
if sig.method_name.decode() != alg_name:
raise AssertionError("Incorrect oqs.Signature.method_name")
if sig.alg_version is None:
raise AssertionError("Undefined oqs.Signature.alg_version")
if not 1 <= sig.claimed_nist_level <= 5:
raise AssertionError("Invalid oqs.Signature.claimed_nist_level")
if sig.length_public_key == 0:
raise AssertionError("Incorrect oqs.Signature.length_public_key")
if sig.length_secret_key == 0:
raise AssertionError("Incorrect oqs.Signature.length_secret_key")
if sig.length_signature == 0:
raise AssertionError("Incorrect oqs.Signature.length_signature")


if __name__ == "__main__":
try:
import nose2

nose2.main()
except ImportError:
raise RuntimeError(
"nose2 module not found. Please install it with 'pip install node2'."
"nose2 module not found. Please install it with 'pip install nose2'."
)
Loading