1#ifndef LIBFILEZILLA_ENCRYPTION_HEADER
2#define LIBFILEZILLA_ENCRYPTION_HEADER
33 explicit operator bool()
const {
34 return key_.size() == key_size && salt_.size() == salt_size;
38 return key_ ==
rhs.key_ && salt_ ==
rhs.salt_;
42 return !(*
this ==
rhs);
46 return key_ <
rhs.key_ || (key_ ==
rhs.key_ && salt_ <
rhs.salt_);
49 std::string to_base64(
bool pad =
true)
const;
53 std::vector<uint8_t> key_;
54 std::vector<uint8_t> salt_;
74 min_iterations = 100000
82 static private_key from_password(std::string_view
const&
password, std::vector<uint8_t>
const& salt,
unsigned int iterations = min_iterations)
87 explicit operator bool()
const {
88 return key_.size() == key_size && salt_.size() == salt_size;
91 std::vector<uint8_t>
const& salt()
const {
101 std::string to_base64(
bool pad =
true)
const;
105 std::vector<uint8_t> key_;
106 std::vector<uint8_t> salt_;
185 min_iterations = 100000
198 explicit operator bool()
const {
199 return key_.size() == key_size && salt_.size() == salt_size;
202 std::vector<uint8_t>
const& salt()
const {
206 std::string to_base64(
bool pad =
true)
const;
207 static symmetric_key from_base64(std::string_view
const&
base64);
208 static symmetric_key from_base64(std::wstring_view
const&
base64);
213 std::vector<uint8_t>
const& key()
const;
215 static size_t encryption_overhead();
217 std::vector<uint8_t> key_;
218 std::vector<uint8_t> salt_;
Represents a X25519 private key with associated salt.
Definition encryption.hpp:62
public_key pubkey() const
Calculates the public key corresponding to the private key.
static private_key from_password(std::vector< uint8_t > const &password, std::vector< uint8_t > const &salt, unsigned int iterations=min_iterations)
Derives a symmetric key using PBKDF2-SHA256 from the given password and salt.
static private_key generate()
Generates a random private key.
std::vector< uint8_t > shared_secret(public_key const &pub) const
Calculates a shared secret using Elliptic Curve Diffie-Hellman on Curve25519 (X25519)
Represents a X25519 public key with associated salt.
Definition encryption.hpp:25
Symmetric encryption key with associated salt.
Definition encryption.hpp:173
static symmetric_key from_password(std::vector< uint8_t > const &password, std::vector< uint8_t > const &salt, unsigned int iterations=min_iterations)
Derives a symmetric key using PBKDF2-SHA256 from the given password and salt.
static symmetric_key generate()
Generates a random symmetric key.
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition apply.hpp:17
std::vector< uint8_t > encrypt(std::vector< uint8_t > const &plain, public_key const &pub, bool authenticated=true)
Encrypt the plaintext to the given public key.
std::vector< uint8_t > decrypt(std::vector< uint8_t > const &chiper, private_key const &priv, bool authenticated=true)
Decrypt the ciphertext using the given private key.
bool dispatch(event_base const &ev, F &&f)
Dispatch for simple_event<> based events to simple functors.
Definition event_handler.hpp:199
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.