11#include <botan/asn1_obj.h>
12#include <botan/pk_keys.h>
13#include <botan/pk_ops_fwd.h>
14#include <botan/symkey.h>
22class RandomNumberGenerator;
38 return enc(in, length, rng);
48 return enc(in.data(), in.size(), rng);
106 size_t expected_pt_len,
125 size_t expected_pt_len,
127 const uint8_t required_content_bytes[],
128 const uint8_t required_content_offsets[],
129 size_t required_contents)
const;
147 virtual
secure_vector<uint8_t> do_decrypt(uint8_t& valid_mask, const uint8_t in[],
size_t in_len) const = 0;
167 std::string_view padding,
169 std::string_view provider =
"");
188 return this->signature(rng);
212 void update(
const uint8_t in[],
size_t length);
218 void update(std::span<const uint8_t> in) {
update(in.data(), in.size()); }
224 void update(std::string_view in);
244 size_t signature_length()
const;
259 std::string hash_function()
const;
262 std::unique_ptr<PK_Ops::Signature> m_op;
264 size_t m_parts, m_part_size;
282 std::string_view padding,
284 std::string_view provider =
"");
299 std::string_view provider =
"");
317 bool verify_message(const uint8_t msg[],
size_t msg_length, const uint8_t sig[],
size_t sig_length);
325 bool verify_message(std::span<const uint8_t> msg, std::span<const uint8_t> sig) {
326 return verify_message(msg.data(), msg.size(), sig.data(), sig.size());
342 void update(
const uint8_t msg_part[],
size_t length);
349 void update(std::span<const uint8_t> in) {
update(in.data(), in.size()); }
355 void update(std::string_view in);
364 bool check_signature(
const uint8_t sig[],
size_t length);
386 std::string hash_function()
const;
389 std::unique_ptr<PK_Ops::Verification> m_op;
391 size_t m_parts, m_part_size;
408 std::string_view kdf,
409 std::string_view provider =
"");
428 size_t key_len, const uint8_t in[],
size_t in_len, const uint8_t params[],
size_t params_len) const;
438 std::span<const uint8_t> in,
439 const uint8_t params[],
440 size_t params_len)
const {
441 return derive_key(key_len, in.data(), in.size(), params, params_len);
451 SymmetricKey derive_key(
size_t key_len,
const uint8_t in[],
size_t in_len, std::string_view params =
"")
const;
459 SymmetricKey derive_key(
size_t key_len,
const std::span<const uint8_t> in, std::string_view params =
"")
const;
466 size_t agreed_value_size()
const;
469 std::unique_ptr<PK_Ops::Key_Agreement> m_op;
478 size_t maximum_input_size()
const override;
489 std::string_view padding,
490 std::string_view provider =
"");
504 size_t ciphertext_length(
size_t ptext_len) const override;
509 std::unique_ptr<PK_Ops::Encryption> m_op;
526 std::string_view eme,
527 std::string_view provider =
"");
529 size_t plaintext_length(
size_t ptext_len)
const override;
540 secure_vector<uint8_t> do_decrypt(uint8_t& valid_mask, const uint8_t in[],
size_t in_len) const override;
542 std::unique_ptr<PK_Ops::Decryption> m_op;
551 m_encapsulated_shared_key(std::move(encapsulated_shared_key)), m_shared_key(std::move(shared_key)) {}
567 return std::make_pair(std::exchange(kem.m_encapsulated_shared_key, {}), std::exchange(kem.m_shared_key, {}));
574 m_encapsulated_shared_key(encapsulated_size), m_shared_key(shared_key_size) {}
577 std::vector<uint8_t> m_encapsulated_shared_key;
604 std::string_view kem_param = "",
605 std::string_view provider = "") :
632 size_t shared_key_length(
size_t desired_shared_key_len) const;
637 size_t encapsulated_key_length() const;
651 size_t desired_shared_key_len = 32,
652 std::span<const uint8_t> salt = {}) {
653 std::vector<uint8_t> encapsulated_shared_key(encapsulated_key_length());
656 encrypt(std::span{encapsulated_shared_key}, std::span{shared_key}, rng, desired_shared_key_len, salt);
657 return KEM_Encapsulation(std::move(encapsulated_shared_key), std::move(shared_key));
673 size_t desired_shared_key_len = 32,
674 std::span<const uint8_t> salt = {}) {
675 out_encapsulated_key.resize(encapsulated_key_length());
676 out_shared_key.resize(shared_key_length(desired_shared_key_len));
677 encrypt(std::span{out_encapsulated_key}, std::span{out_shared_key}, rng, desired_shared_key_len, salt);
690 void encrypt(std::span<uint8_t> out_encapsulated_key,
691 std::span<uint8_t> out_shared_key,
692 RandomNumberGenerator& rng,
693 size_t desired_shared_key_len = 32,
694 std::span<const uint8_t> salt = {});
699 size_t desired_shared_key_len,
701 const uint8_t salt[],
703 this->encrypt(out_encapsulated_key, out_shared_key, rng, desired_shared_key_len, {salt, salt_len});
709 size_t desired_shared_key_len,
711 std::span<const uint8_t> salt = {}) {
712 out_encapsulated_key.resize(encapsulated_key_length());
713 out_shared_key.resize(shared_key_length(desired_shared_key_len));
714 encrypt(out_encapsulated_key, out_shared_key, rng, desired_shared_key_len, salt);
718 std::unique_ptr<PK_Ops::KEM_Encryption> m_op;
735 std::string_view kem_param =
"",
736 std::string_view provider =
"");
759 size_t shared_key_length(
size_t desired_shared_key_len) const;
764 size_t encapsulated_key_length() const;
776 void decrypt(std::span<uint8_t> out_shared_key,
777 std::span<const uint8_t> encap_key,
778 size_t desired_shared_key_len = 32,
779 std::span<const uint8_t> salt = {});
796 size_t encap_key_len,
797 size_t desired_shared_key_len,
798 const uint8_t salt[] =
nullptr,
799 size_t salt_len = 0) {
801 decrypt(shared_key, {encap_key, encap_key_len}, desired_shared_key_len, {salt, salt_len});
817 size_t desired_shared_key_len = 32,
818 std::span<const uint8_t> salt = {}) {
820 decrypt(shared_key, encap_key, desired_shared_key_len, salt);
825 std::unique_ptr<PK_Ops::KEM_Decryption> m_op;
KEM_Encapsulation(std::vector< uint8_t > encapsulated_shared_key, secure_vector< uint8_t > shared_key)
const secure_vector< uint8_t > & shared_key() const
static std::pair< std::vector< uint8_t >, secure_vector< uint8_t > > destructure(KEM_Encapsulation &&kem)
const std::vector< uint8_t > & encapsulated_shared_key() const
~PK_Decryptor_EME() override
PK_Decryptor_EME(PK_Decryptor_EME &&) noexcept
PK_Decryptor_EME(const PK_Decryptor_EME &)=delete
PK_Decryptor_EME & operator=(const PK_Decryptor_EME &)=delete
virtual ~PK_Decryptor()=default
virtual size_t plaintext_length(size_t ctext_len) const =0
secure_vector< uint8_t > decrypt(std::span< const uint8_t > in) const
PK_Decryptor & operator=(const PK_Decryptor &)=delete
PK_Decryptor(PK_Decryptor &&) noexcept=default
PK_Decryptor(const PK_Decryptor &)=delete
~PK_Encryptor_EME() override
PK_Encryptor_EME & operator=(const PK_Encryptor_EME &)=delete
PK_Encryptor_EME(PK_Encryptor_EME &&) noexcept
PK_Encryptor_EME(const PK_Encryptor_EME &)=delete
PK_Encryptor & operator=(const PK_Encryptor &)=delete
virtual size_t maximum_input_size() const =0
virtual size_t ciphertext_length(size_t ctext_len) const =0
std::vector< uint8_t > encrypt(std::span< const uint8_t > in, RandomNumberGenerator &rng) const
virtual ~PK_Encryptor()=default
std::vector< uint8_t > encrypt(const uint8_t in[], size_t length, RandomNumberGenerator &rng) const
PK_Encryptor(const PK_Encryptor &)=delete
PK_Encryptor(PK_Encryptor &&) noexcept=default
secure_vector< uint8_t > decrypt(const uint8_t encap_key[], size_t encap_key_len, size_t desired_shared_key_len, const uint8_t salt[]=nullptr, size_t salt_len=0)
PK_KEM_Decryptor(PK_KEM_Decryptor &&) noexcept
PK_KEM_Decryptor & operator=(const PK_KEM_Decryptor &)=delete
PK_KEM_Decryptor(const PK_KEM_Decryptor &)=delete
secure_vector< uint8_t > decrypt(std::span< const uint8_t > encap_key, size_t desired_shared_key_len=32, std::span< const uint8_t > salt={})
void encrypt(secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &out_shared_key, RandomNumberGenerator &rng, size_t desired_shared_key_len=32, std::span< const uint8_t > salt={})
PK_KEM_Encryptor(PK_KEM_Encryptor &&) noexcept
PK_KEM_Encryptor(const PK_KEM_Encryptor &)=delete
PK_KEM_Encryptor & operator=(const PK_KEM_Encryptor &)=delete
PK_Key_Agreement & operator=(const PK_Key_Agreement &)=delete
PK_Key_Agreement(const PK_Key_Agreement &)=delete
PK_Key_Agreement(PK_Key_Agreement &&) noexcept
PK_Signer(PK_Signer &&) noexcept
std::vector< uint8_t > sign_message(std::span< const uint8_t > in, RandomNumberGenerator &rng)
void update(std::span< const uint8_t > in)
PK_Signer & operator=(const PK_Signer &)=delete
void set_output_format(Signature_Format format)
PK_Signer(const PK_Signer &)=delete
PK_Verifier(PK_Verifier &&) noexcept
void update(std::span< const uint8_t > in)
PK_Verifier(const PK_Verifier &)=delete
bool check_signature(std::span< const uint8_t > sig)
PK_Verifier & operator=(const PK_Verifier &)=delete
int(* update)(CTX *, const void *, CC_LONG len)
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_DEPRECATED(msg)
std::string encrypt(const uint8_t input[], size_t input_len, std::string_view passphrase, RandomNumberGenerator &rng)
std::vector< T, secure_allocator< T > > secure_vector
std::array< uint8_t, 2 *ED448_LEN > sign_message(std::span< const uint8_t, ED448_LEN > sk, std::span< const uint8_t, ED448_LEN > pk, bool pgflag, std::span< const uint8_t > context, std::span< const uint8_t > msg)
Sign a message using a keypair (RFC 8032 5.2.6)