2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-01-26 15:40:58 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "crypto.hpp"
|
2019-01-26 15:40:58 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace sodium
|
|
|
|
{
|
|
|
|
struct CryptoLibSodium final : public Crypto
|
|
|
|
{
|
|
|
|
CryptoLibSodium();
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
~CryptoLibSodium() override = default;
|
2019-01-26 15:40:58 +00:00
|
|
|
|
2020-09-17 19:18:08 +00:00
|
|
|
/// decrypt cipherText given the key generated from name
|
|
|
|
std::optional<AlignedBuffer<32>>
|
|
|
|
maybe_decrypt_name(
|
|
|
|
std::string_view ciphertext, SymmNonce nounce, std::string_view name) override;
|
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
/// xchacha symmetric cipher
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
xchacha20(const llarp_buffer_t&, const SharedSecret&, const TunnelNonce&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
|
|
|
|
/// xchacha symmetric cipher (multibuffer)
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
xchacha20_alt(
|
|
|
|
const llarp_buffer_t&,
|
|
|
|
const llarp_buffer_t&,
|
|
|
|
const SharedSecret&,
|
|
|
|
const byte_t*) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
|
|
|
|
/// path dh creator's side
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
dh_client(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// path dh relay side
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
dh_server(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// transport dh client side
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
transport_dh_client(
|
|
|
|
SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// transport dh server side
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
transport_dh_server(
|
|
|
|
SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// blake2b 256 bit
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
shorthash(ShortHash&, const llarp_buffer_t&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// blake2s 256 bit hmac
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
hmac(byte_t*, const llarp_buffer_t&, const SharedSecret&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// ed25519 sign
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
sign(Signature&, const SecretKey&, const llarp_buffer_t&) override;
|
2020-01-31 04:27:13 +00:00
|
|
|
/// ed25519 sign (custom with derived keys)
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
sign(Signature&, const PrivateKey&, const llarp_buffer_t&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// ed25519 verify
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
verify(const PubKey&, const llarp_buffer_t&, const Signature&) override;
|
2019-10-23 12:43:37 +00:00
|
|
|
|
2020-01-31 21:05:50 +00:00
|
|
|
/// derive sub keys for public keys. hash is really only intended for
|
|
|
|
/// testing and overrides key_n if given.
|
2020-01-27 21:30:41 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
derive_subkey(
|
|
|
|
PubKey& derived,
|
|
|
|
const PubKey& root,
|
|
|
|
uint64_t key_n,
|
|
|
|
const AlignedBuffer<32>* hash = nullptr) override;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2020-01-31 21:05:50 +00:00
|
|
|
/// derive sub keys for private keys. hash is really only intended for
|
|
|
|
/// testing and overrides key_n if given.
|
2020-01-27 21:30:41 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
derive_subkey_private(
|
|
|
|
PrivateKey& derived,
|
|
|
|
const SecretKey& root,
|
|
|
|
uint64_t key_n,
|
|
|
|
const AlignedBuffer<32>* hash = nullptr) override;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
/// seed to secretkey
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
seed_to_secretkey(llarp::SecretKey&, const llarp::IdentitySecret&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// randomize buffer
|
2019-02-01 01:58:06 +00:00
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
randomize(const llarp_buffer_t&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// randomizer memory
|
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
randbytes(byte_t*, size_t) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// generate signing keypair
|
2019-10-28 14:16:00 +00:00
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
identity_keygen(SecretKey&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// generate encryption keypair
|
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
encryption_keygen(SecretKey&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// generate post quantum encrytion key
|
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
pqe_keygen(PQKeyPair&) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// post quantum decrypt (buffer, sharedkey_dst, sec)
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
pqe_decrypt(const PQCipherBlock&, SharedSecret&, const byte_t*) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
/// post quantum encrypt (buffer, sharedkey_dst, pub)
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
pqe_encrypt(PQCipherBlock&, SharedSecret&, const PQPubKey&) override;
|
2019-11-27 01:40:55 +00:00
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
check_identity_privkey(const SecretKey&) override;
|
2022-04-01 16:52:25 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
check_passwd_hash(std::string pwhash, std::string challenge) override;
|
2019-01-26 15:40:58 +00:00
|
|
|
};
|
|
|
|
} // namespace sodium
|
|
|
|
|
|
|
|
} // namespace llarp
|