1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
diff --git a/oqs/oqs.py b/oqs/oqs.py
index f75aa38..537bc13 100644
--- a/oqs/oqs.py
+++ b/oqs/oqs.py
@@ -246,15 +246,24 @@ class KeyEncapsulation(ct.Structure):
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:
@@ -412,15 +421,25 @@ class Signature(ct.Structure):
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:
diff --git a/tests/test_kem.py b/tests/test_kem.py
index ca4fa52..2c3d068 100644
--- a/tests/test_kem.py
+++ b/tests/test_kem.py
@@ -68,6 +68,25 @@ 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
@@ -75,5 +94,5 @@ if __name__ == "__main__":
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'."
)
diff --git a/tests/test_sig.py b/tests/test_sig.py
index 580774b..598139e 100644
--- a/tests/test_sig.py
+++ b/tests/test_sig.py
@@ -115,6 +115,23 @@ 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
@@ -122,5 +139,5 @@ if __name__ == "__main__":
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'."
)
|