Skip to content

Commit 7906e78

Browse files
committed
Version 0.12.0
Signed-off-by: Vlad Gheorghiu <[email protected]>
1 parent 41f7bcb commit 7906e78

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public_key)`
1111
- When operations fail (i.e., `OQS_SUCCESS != 0`) in functions returning
1212
non-boolean objects, a `RuntimeError` is now raised, instead of returning 0
13-
- Bugfix on Linux, `c_int` -> `c_size_t` for buffer sizes
13+
- Bugfix on Linux platforms, `c_int` -> `c_size_t` for buffer sizes
1414
- Pyright type checking fixes
1515
- Updated examples to use `ML-KEM` and `ML-DSA` as the defaults
1616

oqs/oqs.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def _install_liboqs(target_directory, oqs_version=None):
110110
def _load_liboqs():
111111
if "OQS_INSTALL_PATH" in os.environ:
112112
oqs_install_dir = os.path.abspath(os.environ["OQS_INSTALL_PATH"])
113-
else:
113+
else:
114114
home_dir = os.path.expanduser("~")
115115
oqs_install_dir = os.path.abspath(home_dir + os.path.sep + "_oqs") # $HOME/_oqs
116-
116+
117117
oqs_lib_dir = (
118118
os.path.abspath(oqs_install_dir + os.path.sep + "bin") # $HOME/_oqs/bin
119119
if platform.system() == "Windows"
@@ -122,10 +122,14 @@ def _load_liboqs():
122122
oqs_lib64_dir = (
123123
os.path.abspath(oqs_install_dir + os.path.sep + "bin") # $HOME/_oqs/bin
124124
if platform.system() == "Windows"
125-
else os.path.abspath(oqs_install_dir + os.path.sep + "lib64") # $HOME/_oqs/lib64
125+
else os.path.abspath(
126+
oqs_install_dir + os.path.sep + "lib64"
127+
) # $HOME/_oqs/lib64
126128
)
127129
try:
128-
_liboqs = _load_shared_obj(name="oqs", additional_searching_paths=[oqs_lib_dir, oqs_lib64_dir])
130+
_liboqs = _load_shared_obj(
131+
name="oqs", additional_searching_paths=[oqs_lib_dir, oqs_lib64_dir]
132+
)
129133
assert _liboqs
130134
except RuntimeError:
131135
# We don't have liboqs, so we try to install it automatically
@@ -462,18 +466,18 @@ def sign(self, message):
462466
c_signature = ct.create_string_buffer(self._sig.contents.length_signature)
463467

464468
# Initialize to maximum signature size
465-
signature_len = ct.c_size_t(self._sig.contents.length_signature)
469+
c_signature_len = ct.c_size_t(self._sig.contents.length_signature)
466470

467471
rv = native().OQS_SIG_sign(
468472
self._sig,
469473
ct.byref(c_signature),
470-
ct.byref(signature_len),
474+
ct.byref(c_signature_len),
471475
c_message,
472476
c_message_len,
473477
self.secret_key,
474478
)
475479
if rv == OQS_SUCCESS:
476-
return bytes(c_signature[: signature_len.value])
480+
return bytes(c_signature[: c_signature_len.value])
477481
else:
478482
raise RuntimeError("Can not sign message")
479483

@@ -489,7 +493,7 @@ def verify(self, message, signature, public_key):
489493
c_message = ct.create_string_buffer(message, len(message))
490494
c_message_len = ct.c_size_t(len(c_message))
491495
c_signature = ct.create_string_buffer(signature, len(signature))
492-
signature_len = ct.c_size_t(len(c_signature))
496+
c_signature_len = ct.c_size_t(len(c_signature))
493497
c_public_key = ct.create_string_buffer(
494498
public_key, self._sig.contents.length_public_key
495499
)
@@ -499,7 +503,7 @@ def verify(self, message, signature, public_key):
499503
c_message,
500504
c_message_len,
501505
c_signature,
502-
signature_len,
506+
c_signature_len,
503507
c_public_key,
504508
)
505509
return True if rv == OQS_SUCCESS else False
@@ -511,24 +515,30 @@ def sign_with_ctx_str(self, message, context):
511515
:param context: the context string.
512516
:param message: the message to sign.
513517
"""
518+
if context and not self._sig.contents.sig_with_ctx_support:
519+
raise RuntimeError("Signing with context string not supported")
520+
514521
# Provide length to avoid extra null char
515522
c_message = ct.create_string_buffer(message, len(message))
516523
c_message_len = ct.c_size_t(len(c_message))
517-
c_context = ct.create_string_buffer(context, len(context))
518-
context_len = ct.c_size_t(len(c_context))
524+
if len(context) == 0:
525+
c_context = None
526+
c_context_len = 0
527+
else:
528+
c_context = ct.create_string_buffer(context, len(context))
529+
c_context_len = ct.c_size_t(len(c_context))
519530
c_signature = ct.create_string_buffer(self._sig.contents.length_signature)
520531

521532
# Initialize to maximum signature size
522533
c_signature_len = ct.c_size_t(self._sig.contents.length_signature)
523-
524534
rv = native().OQS_SIG_sign_with_ctx_str(
525535
self._sig,
526536
ct.byref(c_signature),
527537
ct.byref(c_signature_len),
528538
c_message,
529539
c_message_len,
530540
c_context,
531-
context_len,
541+
c_context_len,
532542
self.secret_key,
533543
)
534544
if rv == OQS_SUCCESS:
@@ -545,13 +555,20 @@ def verify_with_ctx_str(self, message, signature, context, public_key):
545555
:param context: the context string.
546556
:param public_key: the signer's public key.
547557
"""
558+
if context and not self._sig.contents.sig_with_ctx_support:
559+
raise RuntimeError("Verifying with context string not supported")
560+
548561
# Provide length to avoid extra null char
549562
c_message = ct.create_string_buffer(message, len(message))
550563
c_message_len = ct.c_size_t(len(c_message))
551564
c_signature = ct.create_string_buffer(signature, len(signature))
552565
c_signature_len = ct.c_size_t(len(c_signature))
553-
c_context = ct.create_string_buffer(context, len(context))
554-
c_context_len = ct.c_size_t(len(c_context))
566+
if len(context) == 0:
567+
c_context = None
568+
c_context_len = 0
569+
else:
570+
c_context = ct.create_string_buffer(context, len(context))
571+
c_context_len = ct.c_size_t(len(c_context))
555572
c_public_key = ct.create_string_buffer(
556573
public_key, self._sig.contents.length_public_key
557574
)

tests/test_kem.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
disabled_KEM_patterns = []
77

88
if platform.system() == "Windows":
9-
disabled_KEM_patterns = ["Classic-McEliece"]
9+
disabled_KEM_patterns = [""]
1010

1111

1212
def test_correctness():
@@ -47,7 +47,7 @@ def check_wrong_ciphertext(alg_name):
4747

4848
def test_not_supported():
4949
try:
50-
with oqs.KeyEncapsulation("bogus"):
50+
with oqs.KeyEncapsulation("unsupported_sig"):
5151
raise AssertionError("oqs.MechanismNotSupportedError was not raised.")
5252
except oqs.MechanismNotSupportedError:
5353
pass
@@ -56,7 +56,6 @@ def test_not_supported():
5656

5757

5858
def test_not_enabled():
59-
# TODO: test broken as the compiled lib determines which algorithms are supported and enabled
6059
for alg_name in oqs.get_supported_kem_mechanisms():
6160
if alg_name not in oqs.get_enabled_kem_mechanisms():
6261
# Found a non-enabled but supported alg

tests/test_sig.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import platform # to learn the OS we're on
33
import random
44

5+
from oqs.oqs import Signature
6+
57
# Sigs for which unit testing is disabled
68
disabled_sig_patterns = []
79

@@ -18,7 +20,7 @@ def test_correctness():
1820

1921
def test_correctness_with_ctx_str():
2022
for alg_name in oqs.get_enabled_sig_mechanisms():
21-
if not alg_name.startswith("ML-DSA"):
23+
if not Signature(alg_name).details["sig_with_ctx_support"]:
2224
continue
2325
if any(item in alg_name for item in disabled_sig_patterns):
2426
continue
@@ -92,7 +94,7 @@ def check_wrong_public_key(alg_name):
9294

9395
def test_not_supported():
9496
try:
95-
with oqs.Signature("bogus"):
97+
with oqs.Signature("unsupported_sig"):
9698
raise AssertionError("oqs.MechanismNotSupportedError was not raised.")
9799
except oqs.MechanismNotSupportedError:
98100
pass
@@ -101,7 +103,6 @@ def test_not_supported():
101103

102104

103105
def test_not_enabled():
104-
# TODO: test broken as the compiled lib determines which algorithms are supported and enabled
105106
for alg_name in oqs.get_supported_sig_mechanisms():
106107
if alg_name not in oqs.get_enabled_sig_mechanisms():
107108
# Found a non-enabled but supported alg

0 commit comments

Comments
 (0)