Skip to content

Commit 9d6bcc7

Browse files
committed
Version 0.3.0
1 parent 8036cee commit 9d6bcc7

File tree

6 files changed

+178
-16
lines changed

6 files changed

+178
-16
lines changed

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
Pre-release
1+
Version 0.3.0 - June 10, 2020
22
- Removed the Visual Studio solution (since it can be automatically
33
generated by CMake), as we prefer to use CMake uniformly across all
44
platforms
5+
- Minor fixes
56

67
Version 0.2.2 - January 16, 2020
78
- Added additional RNG example project to Visual Studio solution

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.2)
2-
project(oqs_cpp)
2+
project(oqs_cpp VERSION 0.3.0 LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 11)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = "liboqs-cpp"
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 0.2.1
41+
PROJECT_NUMBER = 0.3.0
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

RELEASE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
liboqs-cpp version 0.2.2
1+
liboqs-cpp version 0.3.0
22
========================
33

44
About
@@ -13,9 +13,9 @@ The **Open Quantum Safe (OQS) project** has the goal of developing and prototypi
1313
Release notes
1414
=============
1515

16-
This release of liboqs-cpp was released on January 16, 2020. Its release page on GitHub is https://github.com/open-quantum-safe/liboqs-cpp/releases/tag/0.2.2.
16+
This release of liboqs-cpp was released on June 10, 2020. Its release page on GitHub is https://github.com/open-quantum-safe/liboqs-cpp/releases/tag/0.3.0.
1717

1818
What's New
1919
----------
2020

21-
This is the sixth release of liboqs-cpp. For a list of changes see [CHANGES.txt](https://github.com/open-quantum-safe/liboqs-cpp/blob/master/CHANGES.txt).
21+
This is the seventh release of liboqs-cpp. For a list of changes see [CHANGES.txt](https://github.com/open-quantum-safe/liboqs-cpp/blob/master/CHANGES.txt).

unit_tests/tests/test_kem.cpp

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <gtest/gtest.h>
1010

1111
#include "oqs_cpp.h"
12+
#include "rand/rand.h"
1213

1314
// no_thread_KEM_patterns lists KEM patterns that have issues running in a
1415
// separate thread
@@ -18,10 +19,10 @@ static std::vector<std::string> no_thread_KEM_patterns{"Classic-McEliece",
1819
// used for thread-safe console output
1920
static std::mutex mu;
2021

21-
void test_kem(const std::string& kem_name) {
22+
void test_kem_correctness(const std::string& kem_name) {
2223
{
2324
std::lock_guard<std::mutex> lg{mu};
24-
std::cout << kem_name << std::endl;
25+
std::cout << "Correctness - " << kem_name << std::endl;
2526
}
2627
oqs::KeyEncapsulation client{kem_name};
2728
oqs::bytes client_public_key = client.generate_keypair();
@@ -37,7 +38,65 @@ void test_kem(const std::string& kem_name) {
3738
EXPECT_TRUE(is_valid);
3839
}
3940

40-
TEST(oqs_KeyEncapsulation, Enabled) {
41+
void test_kem_wrong_ciphertext(const std::string& kem_name) {
42+
{
43+
std::lock_guard<std::mutex> lg{mu};
44+
std::cout << "Wrong ciphertext - " << kem_name << std::endl;
45+
}
46+
oqs::KeyEncapsulation client{kem_name};
47+
oqs::bytes client_public_key = client.generate_keypair();
48+
oqs::KeyEncapsulation server{kem_name};
49+
oqs::bytes ciphertext, shared_secret_server;
50+
std::tie(ciphertext, shared_secret_server) =
51+
server.encap_secret(client_public_key);
52+
oqs::bytes wrong_ciphertext = oqs::rand::randombytes(ciphertext.size());
53+
oqs::bytes shared_secret_client;
54+
try {
55+
shared_secret_client = client.decap_secret(wrong_ciphertext);
56+
} catch (std::exception& e) {
57+
if (e.what() == std::string{"Can not decapsulate secret"})
58+
return;
59+
else
60+
throw; // this is another un-expected exception
61+
}
62+
bool is_valid = (shared_secret_client == shared_secret_server);
63+
if (is_valid)
64+
std::cerr << kem_name << ": shared secrets should not coincide"
65+
<< std::endl;
66+
EXPECT_FALSE(is_valid);
67+
}
68+
69+
TEST(oqs_KeyEncapsulation, Correctness) {
70+
std::vector<std::thread> thread_pool;
71+
std::vector<std::string> enabled_KEMs = oqs::KEMs::get_enabled_KEMs();
72+
// first test KEMs that belong to no_thread_KEM_patterns[] in the main
73+
// thread (stack size is 8Mb on macOS), due to issues with stack size being
74+
// too small in macOS (512Kb for threads)
75+
for (auto&& kem_name : enabled_KEMs) {
76+
for (auto&& no_thread_kem : no_thread_KEM_patterns) {
77+
if (kem_name.find(no_thread_kem) != std::string::npos) {
78+
test_kem_correctness(kem_name);
79+
}
80+
}
81+
}
82+
// test the remaining KEMs in separate threads
83+
for (auto&& kem_name : enabled_KEMs) {
84+
bool test_in_thread = true;
85+
for (auto&& no_thread_kem : no_thread_KEM_patterns) {
86+
if (kem_name.find(no_thread_kem) != std::string::npos) {
87+
test_in_thread = false;
88+
break;
89+
}
90+
}
91+
if (test_in_thread)
92+
thread_pool.emplace_back(test_kem_correctness, kem_name);
93+
}
94+
// join the rest of the threads
95+
for (auto&& elem : thread_pool)
96+
elem.join();
97+
}
98+
99+
TEST(oqs_KeyEncapsulation, WrongCiphertext) {
41100
std::vector<std::thread> thread_pool;
42101
std::vector<std::string> enabled_KEMs = oqs::KEMs::get_enabled_KEMs();
43102
// first test KEMs that belong to no_thread_KEM_patterns[] in the main
@@ -46,7 +105,7 @@ TEST(oqs_KeyEncapsulation, Enabled) {
46105
for (auto&& kem_name : enabled_KEMs) {
47106
for (auto&& no_thread_kem : no_thread_KEM_patterns) {
48107
if (kem_name.find(no_thread_kem) != std::string::npos) {
49-
test_kem(kem_name);
108+
test_kem_wrong_ciphertext(kem_name);
50109
}
51110
}
52111
}
@@ -60,7 +119,7 @@ TEST(oqs_KeyEncapsulation, Enabled) {
60119
}
61120
}
62121
if (test_in_thread)
63-
thread_pool.emplace_back(test_kem, kem_name);
122+
thread_pool.emplace_back(test_kem_wrong_ciphertext, kem_name);
64123
}
65124
// join the rest of the threads
66125
for (auto&& elem : thread_pool)

unit_tests/tests/test_sig.cpp

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <gtest/gtest.h>
99

1010
#include "oqs_cpp.h"
11+
#include "rand/rand.h"
1112

1213
// no_thread_sig_patterns lists sig patterns that have issues running in a
1314
// separate thread
@@ -17,10 +18,10 @@ static std::vector<std::string> no_thread_sig_patterns{"Rainbow-IIIc",
1718
// used for thread-safe console output
1819
static std::mutex mu;
1920

20-
void test_sig(const std::string& sig_name, const oqs::bytes& msg) {
21+
void test_sig_correctness(const std::string& sig_name, const oqs::bytes& msg) {
2122
{
2223
std::lock_guard<std::mutex> lg{mu};
23-
std::cout << sig_name << std::endl;
24+
std::cout << "Correctness - " << sig_name << std::endl;
2425
}
2526
oqs::Signature signer{sig_name};
2627
oqs::bytes signer_public_key = signer.generate_keypair();
@@ -32,7 +33,107 @@ void test_sig(const std::string& sig_name, const oqs::bytes& msg) {
3233
EXPECT_TRUE(is_valid);
3334
}
3435

35-
TEST(oqs_Signature, Enabled) {
36+
void test_sig_wrong_signature(const std::string& sig_name,
37+
const oqs::bytes& msg) {
38+
{
39+
std::lock_guard<std::mutex> lg{mu};
40+
std::cout << "Wrong signature - " << sig_name << std::endl;
41+
}
42+
oqs::Signature signer{sig_name};
43+
oqs::bytes signer_public_key = signer.generate_keypair();
44+
oqs::bytes signature = signer.sign(msg);
45+
oqs::bytes wrong_signature = oqs::rand::randombytes(signature.size());
46+
oqs::Signature verifier{sig_name};
47+
bool is_valid = verifier.verify(msg, wrong_signature, signer_public_key);
48+
if (is_valid)
49+
std::cerr << sig_name << ": signature verification should have failed"
50+
<< std::endl;
51+
EXPECT_FALSE(is_valid);
52+
}
53+
54+
void test_sig_wrong_public_key(const std::string& sig_name,
55+
const oqs::bytes& msg) {
56+
{
57+
std::lock_guard<std::mutex> lg{mu};
58+
std::cout << "Wrong public key - " << sig_name << std::endl;
59+
}
60+
oqs::Signature signer{sig_name};
61+
oqs::bytes signer_public_key = signer.generate_keypair();
62+
oqs::bytes wrong_public_key =
63+
oqs::rand::randombytes(signer_public_key.size());
64+
oqs::bytes signature = signer.sign(msg);
65+
oqs::Signature verifier{sig_name};
66+
bool is_valid = verifier.verify(msg, signature, wrong_public_key);
67+
if (is_valid)
68+
std::cerr << sig_name << ": signature verification should have failed"
69+
<< std::endl;
70+
EXPECT_FALSE(is_valid);
71+
}
72+
73+
TEST(oqs_Signature, Correctness) {
74+
oqs::bytes message = "This is our favourite message to sign"_bytes;
75+
std::vector<std::thread> thread_pool;
76+
std::vector<std::string> enabled_sigs = oqs::Sigs::get_enabled_sigs();
77+
// first test sigs that belong to no_thread_sig_patterns[] in the main
78+
// thread (stack size is 8Mb on macOS), due to issues with stack size being
79+
// too small in macOS (512Kb for threads)
80+
for (auto&& sig_name : enabled_sigs) {
81+
for (auto&& no_thread_sig : no_thread_sig_patterns) {
82+
if (sig_name.find(no_thread_sig) != std::string::npos) {
83+
test_sig_correctness(sig_name, message);
84+
}
85+
}
86+
}
87+
// test the remaining sigs in separate threads
88+
for (auto&& sig_name : enabled_sigs) {
89+
bool test_in_thread = true;
90+
for (auto&& no_thread_sig : no_thread_sig_patterns) {
91+
if (sig_name.find(no_thread_sig) != std::string::npos) {
92+
test_in_thread = false;
93+
break;
94+
}
95+
}
96+
if (test_in_thread)
97+
thread_pool.emplace_back(test_sig_correctness, sig_name, message);
98+
}
99+
// join the rest of the threads
100+
for (auto&& elem : thread_pool)
101+
elem.join();
102+
}
103+
104+
TEST(oqs_Signature, WrongSignature) {
105+
oqs::bytes message = "This is our favourite message to sign"_bytes;
106+
std::vector<std::thread> thread_pool;
107+
std::vector<std::string> enabled_sigs = oqs::Sigs::get_enabled_sigs();
108+
// first test sigs that belong to no_thread_sig_patterns[] in the main
109+
// thread (stack size is 8Mb on macOS), due to issues with stack size being
110+
// too small in macOS (512Kb for threads)
111+
for (auto&& sig_name : enabled_sigs) {
112+
for (auto&& no_thread_sig : no_thread_sig_patterns) {
113+
if (sig_name.find(no_thread_sig) != std::string::npos) {
114+
test_sig_wrong_signature(sig_name, message);
115+
}
116+
}
117+
}
118+
// test the remaining sigs in separate threads
119+
for (auto&& sig_name : enabled_sigs) {
120+
bool test_in_thread = true;
121+
for (auto&& no_thread_sig : no_thread_sig_patterns) {
122+
if (sig_name.find(no_thread_sig) != std::string::npos) {
123+
test_in_thread = false;
124+
break;
125+
}
126+
}
127+
if (test_in_thread)
128+
thread_pool.emplace_back(test_sig_wrong_signature, sig_name,
129+
message);
130+
}
131+
// join the rest of the threads
132+
for (auto&& elem : thread_pool)
133+
elem.join();
134+
}
135+
136+
TEST(oqs_Signature, WrongPublicKey) {
36137
oqs::bytes message = "This is our favourite message to sign"_bytes;
37138
std::vector<std::thread> thread_pool;
38139
std::vector<std::string> enabled_sigs = oqs::Sigs::get_enabled_sigs();
@@ -42,7 +143,7 @@ TEST(oqs_Signature, Enabled) {
42143
for (auto&& sig_name : enabled_sigs) {
43144
for (auto&& no_thread_sig : no_thread_sig_patterns) {
44145
if (sig_name.find(no_thread_sig) != std::string::npos) {
45-
test_sig(sig_name, message);
146+
test_sig_wrong_public_key(sig_name, message);
46147
}
47148
}
48149
}
@@ -56,7 +157,8 @@ TEST(oqs_Signature, Enabled) {
56157
}
57158
}
58159
if (test_in_thread)
59-
thread_pool.emplace_back(test_sig, sig_name, message);
160+
thread_pool.emplace_back(test_sig_wrong_public_key, sig_name,
161+
message);
60162
}
61163
// join the rest of the threads
62164
for (auto&& elem : thread_pool)

0 commit comments

Comments
 (0)