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;
50 static public_key from_base64(std::string_view
const& base64);
51 static public_key from_base64(std::wstring_view
const& base64);
53 std::vector<uint8_t> key_;
54 std::vector<uint8_t> salt_;
74 min_iterations = 100000
81 static private_key from_password(std::vector<uint8_t>
const& password, std::vector<uint8_t>
const& salt,
unsigned int iterations = min_iterations);
82 static private_key from_password(std::string_view
const& password, std::vector<uint8_t>
const& salt,
unsigned int iterations = min_iterations)
84 return from_password(std::vector<uint8_t>(password.begin(), password.end()), salt, 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;
102 static private_key from_base64(std::string_view
const& base64);
105 std::vector<uint8_t> key_;
106 std::vector<uint8_t> salt_;
130 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(std::vector<uint8_t>
const& plain,
public_key const& pub,
bool authenticated =
true);
131 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(std::string_view
const& plain,
public_key const& pub,
bool authenticated =
true);
132 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(uint8_t
const* plain,
size_t size,
public_key const& pub,
bool authenticated =
true);
133 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(std::vector<uint8_t>
const& plain,
public_key const& pub, std::vector<uint8_t>
const& authenticated_data);
134 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(std::string_view
const& plain,
public_key const& pub, std::string_view
const& authenticated_data);
135 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(uint8_t
const* plain,
size_t size,
public_key const& pub, uint8_t
const* authenticated_data,
size_t authenticated_data_size);
162 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(std::vector<uint8_t>
const& chiper,
private_key const& priv,
bool authenticated =
true);
163 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(std::string_view
const& chiper,
private_key const& priv,
bool authenticated =
true);
164 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(uint8_t
const* cipher,
size_t size,
private_key const& priv,
bool authenticated =
true);
165 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(std::vector<uint8_t>
const& cipher,
private_key const& priv, std::vector<uint8_t>
const& authenticated_data);
166 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(std::string_view
const& cipher,
private_key const& priv, std::string_view
const& authenticated_data);
167 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(uint8_t
const* cipher,
size_t size,
private_key const& priv, uint8_t
const* authenticated_data,
size_t authenticated_data_size);
185 min_iterations = 100000
192 static symmetric_key from_password(std::vector<uint8_t>
const& password, std::vector<uint8_t>
const& salt,
unsigned int iterations = min_iterations);
193 static symmetric_key from_password(std::string_view
const& password, std::vector<uint8_t>
const& salt,
unsigned int iterations = min_iterations)
195 return from_password(std::vector<uint8_t>(password.begin(), password.end()), salt, iterations);
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);
211 static symmetric_key decrypt_key(std::vector<uint8_t>
const& encrypted,
fz::private_key const& kek);
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_;
224 return !(lhs == rhs);
242 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(std::string_view
const& plain,
symmetric_key const& key);
243 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(uint8_t
const* plain,
size_t size,
symmetric_key const& key);
244 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(std::vector<uint8_t>
const& plain,
symmetric_key const& key, std::vector<uint8_t>
const& authenticated_data);
245 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(std::string_view
const& plain,
symmetric_key const& key, std::string_view
const& authenticated_data);
246 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
encrypt(uint8_t
const* plain,
size_t size,
symmetric_key const& key, uint8_t
const* authenticated_data,
size_t authenticated_data_size);
268 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(std::string_view
const& chiper,
symmetric_key const& key);
269 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(uint8_t
const* cipher,
size_t size,
symmetric_key const& key);
270 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(std::vector<uint8_t>
const& cipher,
symmetric_key const& key, std::vector<uint8_t>
const& authenticated_data);
271 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(std::string_view
const& cipher,
symmetric_key const& key, std::string_view
const& authenticated_data);
272 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
decrypt(uint8_t
const* cipher,
size_t size,
symmetric_key const& key, uint8_t
const* authenticated_data,
size_t authenticated_data_size);
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 > decrypt(std::vector< uint8_t > const &chiper, private_key const &priv, bool authenticated=true)
Decrypt the ciphertext using the given private key.
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.
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.