-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow the pubkey operations wrapper types to move #3655
Conversation
87ea9fa
to
60566b5
Compare
MSVC having problems here that I don't understand |
For reasons the '= default' definition of the move c'tor and move assignment is trying to instantiate the m_op's d'tor when compiling a shared library with MSVC. This does not work inline, because the PK_Ops::* class is just forward declared in the header.
331e8eb
to
7e16655
Compare
For some reason MSVC seems to instantiate the destructor of I don't know why MSVC needs to call the destructor of @randombit: I replaced your attempted fix with the above-described workaround on this branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay! That'll make certain things easier for sure.
Thinking about this a bit more, it's actually fairly obvious: The d'tor of For instance, when applying the following patch to the initial PR (without the diff --git a/src/tests/test_kyber.cpp b/src/tests/test_kyber.cpp
index 2e85d156a..948efa158 100644
--- a/src/tests/test_kyber.cpp
+++ b/src/tests/test_kyber.cpp
@@ -29,6 +29,10 @@ namespace Botan_Tests {
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
+inline decltype(auto) encrypt_wrapper(Botan::PK_KEM_Encryptor enc) {
+ return enc.encrypt(Test::rng());
+}
+
class KYBER_Tests final : public Test {
public:
static Test::Result run_kyber_test(const char* test_name, Botan::KyberMode mode, size_t strength) {
@@ -50,7 +54,7 @@ class KYBER_Tests final : public Test {
// Bob (reading from serialized public key)
Botan::Kyber_PublicKey alice_pub_key(pub_key_bits, mode);
auto enc = Botan::PK_KEM_Encryptor(alice_pub_key, "Raw", "base");
- const auto kem_result = enc.encrypt(Test::rng());
+ const auto kem_result = encrypt_wrapper(std::move(enc));
// Alice (reading from serialized private key)
Botan::Kyber_PrivateKey alice_priv_key(priv_key_bits, mode);
|
Have to be honest my intuition on how move works does not explain why the destructor would have to be visible but ¯_(ツ)_/¯ |
Hm I guess the issue is that in C++ move isn't really the right word to describe what is happening. You start with one object, after the move you have a new object, along with the original moved-from object which is in a potentially invalid state. So you still need to destroy the original. Versus Rust where a move really is just a move. |
That's also my intuition of what is happening.
Yeah, the situation you describe above is the price we pay for C++'s legacy. When do we start rewriting Botan in Rust? 😄 |
LOL I would love to tbh; I sincerely do think "Rust implementation of X designed to provide a C API" is an underexplored territory. That said I think people would be unhappy since Rust's story for weird architectures, baremetal, accessing CPU instructions, inline asm, etc, while certainly improving in the last few years, is still way behind C++. I have on the todo list writing a new Rust ASN.1 library (the two major ones that currently exist are both pretty terrible, so this is a personal pain point for me) that would also expose it to C. Something like this would give a pretty good indicator if it was viable or not. |
GH #3641