Skip to content

Commit

Permalink
Merge GH #3655 Allow the pubkey operations wrapper types to move
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Aug 9, 2023
2 parents 47ab8b1 + acb76a8 commit 2878d6a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
23 changes: 21 additions & 2 deletions src/lib/pubkey/pubkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ PK_Encryptor_EME::PK_Encryptor_EME(const Public_Key& key,

PK_Encryptor_EME::~PK_Encryptor_EME() = default;

PK_Encryptor_EME::PK_Encryptor_EME(PK_Encryptor_EME&&) noexcept = default;
PK_Encryptor_EME& PK_Encryptor_EME::operator=(PK_Encryptor_EME&&) noexcept = default;

size_t PK_Encryptor_EME::ciphertext_length(size_t ptext_len) const {
return m_op->ciphertext_length(ptext_len);
}
Expand All @@ -118,6 +121,9 @@ PK_Decryptor_EME::PK_Decryptor_EME(const Private_Key& key,

PK_Decryptor_EME::~PK_Decryptor_EME() = default;

PK_Decryptor_EME::PK_Decryptor_EME(PK_Decryptor_EME&&) noexcept = default;
PK_Decryptor_EME& PK_Decryptor_EME::operator=(PK_Decryptor_EME&&) noexcept = default;

size_t PK_Decryptor_EME::plaintext_length(size_t ctext_len) const {
return m_op->plaintext_length(ctext_len);
}
Expand All @@ -135,6 +141,9 @@ PK_KEM_Encryptor::PK_KEM_Encryptor(const Public_Key& key, std::string_view param

PK_KEM_Encryptor::~PK_KEM_Encryptor() = default;

PK_KEM_Encryptor::PK_KEM_Encryptor(PK_KEM_Encryptor&&) noexcept = default;
PK_KEM_Encryptor& PK_KEM_Encryptor::operator=(PK_KEM_Encryptor&&) noexcept = default;

size_t PK_KEM_Encryptor::shared_key_length(size_t desired_shared_key_len) const {
return m_op->shared_key_length(desired_shared_key_len);
}
Expand Down Expand Up @@ -174,6 +183,9 @@ PK_KEM_Decryptor::PK_KEM_Decryptor(const Private_Key& key,

PK_KEM_Decryptor::~PK_KEM_Decryptor() = default;

PK_KEM_Decryptor::PK_KEM_Decryptor(PK_KEM_Decryptor&&) noexcept = default;
PK_KEM_Decryptor& PK_KEM_Decryptor::operator=(PK_KEM_Decryptor&&) noexcept = default;

void PK_KEM_Decryptor::decrypt(std::span<uint8_t> out_shared_key,
std::span<const uint8_t> encap_key,
size_t desired_shared_key_len,
Expand All @@ -183,8 +195,6 @@ void PK_KEM_Decryptor::decrypt(std::span<uint8_t> out_shared_key,
m_op->kem_decrypt(out_shared_key, encap_key, desired_shared_key_len, salt);
}

PK_Key_Agreement::PK_Key_Agreement(PK_Key_Agreement&&) noexcept = default;

PK_Key_Agreement::PK_Key_Agreement(const Private_Key& key,
RandomNumberGenerator& rng,
std::string_view kdf,
Expand All @@ -197,6 +207,9 @@ PK_Key_Agreement::PK_Key_Agreement(const Private_Key& key,

PK_Key_Agreement::~PK_Key_Agreement() = default;

PK_Key_Agreement::PK_Key_Agreement(PK_Key_Agreement&&) noexcept = default;
PK_Key_Agreement& PK_Key_Agreement::operator=(PK_Key_Agreement&&) noexcept = default;

size_t PK_Key_Agreement::agreed_value_size() const {
return m_op->agreed_value_size();
}
Expand Down Expand Up @@ -237,6 +250,9 @@ std::string PK_Signer::hash_function() const {

PK_Signer::~PK_Signer() = default;

PK_Signer::PK_Signer(PK_Signer&&) noexcept = default;
PK_Signer& PK_Signer::operator=(PK_Signer&&) noexcept = default;

void PK_Signer::update(const uint8_t in[], size_t length) {
m_op->update(in, length);
}
Expand Down Expand Up @@ -315,6 +331,9 @@ PK_Verifier::PK_Verifier(const Public_Key& key,

PK_Verifier::~PK_Verifier() = default;

PK_Verifier::PK_Verifier(PK_Verifier&&) noexcept = default;
PK_Verifier& PK_Verifier::operator=(PK_Verifier&&) noexcept = default;

std::string PK_Verifier::hash_function() const {
return m_op->hash_function();
}
Expand Down
44 changes: 26 additions & 18 deletions src/lib/pubkey/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ class BOTAN_PUBLIC_API(2, 0) PK_Encryptor {
virtual ~PK_Encryptor() = default;

PK_Encryptor(const PK_Encryptor&) = delete;
PK_Encryptor(PK_Encryptor&&) noexcept = delete;
PK_Encryptor& operator=(const PK_Encryptor&) = delete;
PK_Encryptor& operator=(PK_Encryptor&&) noexcept = delete;

PK_Encryptor(PK_Encryptor&&) noexcept = default;
PK_Encryptor& operator=(PK_Encryptor&&) noexcept = default;

private:
virtual std::vector<uint8_t> enc(const uint8_t[], size_t, RandomNumberGenerator&) const = 0;
Expand Down Expand Up @@ -136,9 +137,10 @@ class BOTAN_PUBLIC_API(2, 0) PK_Decryptor {
virtual ~PK_Decryptor() = default;

PK_Decryptor(const PK_Decryptor&) = delete;
PK_Decryptor(PK_Decryptor&&) noexcept = delete;
PK_Decryptor& operator=(const PK_Decryptor&) = delete;
PK_Decryptor& operator=(PK_Decryptor&&) noexcept = delete;

PK_Decryptor(PK_Decryptor&&) noexcept = default;
PK_Decryptor& operator=(PK_Decryptor&&) noexcept = default;

private:
virtual secure_vector<uint8_t> do_decrypt(uint8_t& valid_mask, const uint8_t in[], size_t in_len) const = 0;
Expand Down Expand Up @@ -168,9 +170,10 @@ class BOTAN_PUBLIC_API(2, 0) PK_Signer final {
~PK_Signer();

PK_Signer(const PK_Signer&) = delete;
PK_Signer(PK_Signer&&) noexcept = delete;
PK_Signer& operator=(const PK_Signer&) = delete;
PK_Signer& operator=(PK_Signer&&) noexcept = delete;

PK_Signer(PK_Signer&&) noexcept;
PK_Signer& operator=(PK_Signer&&) noexcept;

/**
* Sign a message all in one go
Expand Down Expand Up @@ -297,9 +300,10 @@ class BOTAN_PUBLIC_API(2, 0) PK_Verifier final {
~PK_Verifier();

PK_Verifier(const PK_Verifier&) = delete;
PK_Verifier(PK_Verifier&&) noexcept = delete;
PK_Verifier& operator=(const PK_Verifier&) = delete;
PK_Verifier& operator=(PK_Verifier&&) noexcept = delete;

PK_Verifier(PK_Verifier&&) noexcept;
PK_Verifier& operator=(PK_Verifier&&) noexcept;

/**
* Verify a signature.
Expand Down Expand Up @@ -407,10 +411,9 @@ class BOTAN_PUBLIC_API(2, 0) PK_Key_Agreement final {

PK_Key_Agreement(const PK_Key_Agreement&) = delete;
PK_Key_Agreement& operator=(const PK_Key_Agreement&) = delete;
PK_Key_Agreement& operator=(PK_Key_Agreement&&) = delete;

// For ECIES
PK_Key_Agreement(PK_Key_Agreement&&) noexcept;
PK_Key_Agreement& operator=(PK_Key_Agreement&&) noexcept;

/**
* Perform Key Agreement Operation
Expand Down Expand Up @@ -492,9 +495,10 @@ class BOTAN_PUBLIC_API(2, 0) PK_Encryptor_EME final : public PK_Encryptor {
~PK_Encryptor_EME() override;

PK_Encryptor_EME(const PK_Encryptor_EME&) = delete;
PK_Encryptor_EME(PK_Encryptor_EME&&) = delete;
PK_Encryptor_EME& operator=(const PK_Encryptor_EME&) = delete;
PK_Encryptor_EME& operator=(PK_Encryptor_EME&&) = delete;

PK_Encryptor_EME(PK_Encryptor_EME&&) noexcept;
PK_Encryptor_EME& operator=(PK_Encryptor_EME&&) noexcept;

/**
* Return an upper bound on the ciphertext length for a particular
Expand Down Expand Up @@ -528,10 +532,12 @@ class BOTAN_PUBLIC_API(2, 0) PK_Decryptor_EME final : public PK_Decryptor {
size_t plaintext_length(size_t ptext_len) const override;

~PK_Decryptor_EME() override;

PK_Decryptor_EME(const PK_Decryptor_EME&) = delete;
PK_Decryptor_EME(PK_Decryptor_EME&&) = delete;
PK_Decryptor_EME& operator=(const PK_Decryptor_EME&) = delete;
PK_Decryptor_EME& operator=(PK_Decryptor_EME&&) = delete;

PK_Decryptor_EME(PK_Decryptor_EME&&) noexcept;
PK_Decryptor_EME& operator=(PK_Decryptor_EME&&) noexcept;

private:
secure_vector<uint8_t> do_decrypt(uint8_t& valid_mask, const uint8_t in[], size_t in_len) const override;
Expand Down Expand Up @@ -605,9 +611,10 @@ class BOTAN_PUBLIC_API(2, 0) PK_KEM_Encryptor final {
~PK_KEM_Encryptor();

PK_KEM_Encryptor(const PK_KEM_Encryptor&) = delete;
PK_KEM_Encryptor(PK_KEM_Encryptor&&) = delete;
PK_KEM_Encryptor& operator=(const PK_KEM_Encryptor&) = delete;
PK_KEM_Encryptor& operator=(PK_KEM_Encryptor&&) = delete;

PK_KEM_Encryptor(PK_KEM_Encryptor&&) noexcept;
PK_KEM_Encryptor& operator=(PK_KEM_Encryptor&&) noexcept;

/**
* Return the length of the shared key returned by this KEM
Expand Down Expand Up @@ -735,9 +742,10 @@ class BOTAN_PUBLIC_API(2, 0) PK_KEM_Decryptor final {

~PK_KEM_Decryptor();
PK_KEM_Decryptor(const PK_KEM_Decryptor&) = delete;
PK_KEM_Decryptor(PK_KEM_Decryptor&&) = delete;
PK_KEM_Decryptor& operator=(const PK_KEM_Decryptor&) = delete;
PK_KEM_Decryptor& operator=(PK_KEM_Decryptor&&) = delete;

PK_KEM_Decryptor(PK_KEM_Decryptor&&) noexcept;
PK_KEM_Decryptor& operator=(PK_KEM_Decryptor&&) noexcept;

/**
* Return the length of the shared key returned by this KEM
Expand Down

0 comments on commit 2878d6a

Please sign in to comment.