Convert llarp_crypto to be a true C++ class

pull/125/head
Michael 6 years ago
parent 6dc2222e11
commit 7be452092c
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -263,7 +263,7 @@ main(int argc, char *argv[])
if(verifyMode) if(verifyMode)
{ {
llarp_crypto crypto; llarp::Crypto crypto;
llarp_crypto_init(&crypto); llarp_crypto_init(&crypto);
if(!rc.Read(rcfname)) if(!rc.Read(rcfname))
{ {
@ -329,7 +329,7 @@ main(int argc, char *argv[])
// this is the only one... // this is the only one...
if(listMode) if(listMode)
{ {
llarp_crypto crypto; llarp::Crypto crypto;
llarp_crypto_init(&crypto); llarp_crypto_init(&crypto);
auto nodedb = llarp_nodedb_new(&crypto); auto nodedb = llarp_nodedb_new(&crypto);
llarp_nodedb_iter itr; llarp_nodedb_iter itr;
@ -350,7 +350,7 @@ main(int argc, char *argv[])
std::cout << "no file to import" << std::endl; std::cout << "no file to import" << std::endl;
return 1; return 1;
} }
llarp_crypto crypto; llarp::Crypto crypto;
llarp_crypto_init(&crypto); llarp_crypto_init(&crypto);
auto nodedb = llarp_nodedb_new(&crypto); auto nodedb = llarp_nodedb_new(&crypto);
if(!llarp_nodedb_ensure_dir(nodesdir)) if(!llarp_nodedb_ensure_dir(nodesdir))
@ -391,7 +391,7 @@ main(int argc, char *argv[])
// set updated timestamp // set updated timestamp
rc.last_updated = llarp::time_now_ms(); rc.last_updated = llarp::time_now_ms();
// load longterm identity // load longterm identity
llarp_crypto crypt; llarp::Crypto crypt;
llarp_crypto_init(&crypt); llarp_crypto_init(&crypt);
// which is in daemon.ini config: router.encryption-privkey (defaults // which is in daemon.ini config: router.encryption-privkey (defaults
@ -440,7 +440,7 @@ main(int argc, char *argv[])
// set updated timestamp // set updated timestamp
rc.last_updated = llarp::time_now_ms(); rc.last_updated = llarp::time_now_ms();
// load longterm identity // load longterm identity
llarp_crypto crypt; llarp::Crypto crypt;
// no longer used? // no longer used?
// llarp_crypto_libsodium_init(&crypt); // llarp_crypto_libsodium_init(&crypt);
@ -469,7 +469,7 @@ main(int argc, char *argv[])
if(listMode) if(listMode)
{ {
llarp_crypto crypto; llarp::Crypto crypto;
// no longer used? // no longer used?
// llarp_crypto_libsodium_init(&crypto); // llarp_crypto_libsodium_init(&crypto);
llarp_crypto_init(&crypto); llarp_crypto_init(&crypto);

@ -1,12 +1,13 @@
#ifndef LLARP_HPP #ifndef LLARP_HPP
#define LLARP_HPP #define LLARP_HPP
#include <llarp.h>
#include <iostream> #include <iostream>
#include <llarp.h>
#include <llarp/crypto.h>
#include <llarp/threading.hpp> #include <llarp/threading.hpp>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <llarp/crypto.h>
struct llarp_config; struct llarp_config;
struct llarp_config_iterator; struct llarp_config_iterator;
@ -19,7 +20,7 @@ namespace llarp
int num_nethreads = 1; int num_nethreads = 1;
bool singleThreaded = false; bool singleThreaded = false;
llarp_crypto crypto; std::unique_ptr<llarp::Crypto> crypto;
llarp::Router *router = nullptr; llarp::Router *router = nullptr;
llarp_threadpool *worker = nullptr; llarp_threadpool *worker = nullptr;
llarp::Logic *logic = nullptr; llarp::Logic *logic = nullptr;

@ -2,6 +2,7 @@
#define LLARP_CRYPTO_H_ #define LLARP_CRYPTO_H_
#include <llarp/buffer.h> #include <llarp/buffer.h>
#include <llarp/common.hpp> #include <llarp/common.hpp>
#include <functional>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -12,17 +13,17 @@
* potentially allow libssl support in the future * potentially allow libssl support in the future
*/ */
#define PUBKEYSIZE 32 static constexpr uint32_t PUBKEYSIZE = 32;
#define SECKEYSIZE 64 static constexpr uint32_t SECKEYSIZE = 64;
#define NONCESIZE 24 static constexpr uint32_t NONCESIZE = 24;
#define SHAREDKEYSIZE 32 static constexpr uint32_t SHAREDKEYSIZE = 32;
#define HASHSIZE 64 static constexpr uint32_t HASHSIZE = 64;
#define SHORTHASHSIZE 32 static constexpr uint32_t SHORTHASHSIZE = 32;
#define HMACSECSIZE 32 static constexpr uint32_t HMACSECSIZE = 32;
#define SIGSIZE 64 static constexpr uint32_t SIGSIZE = 64;
#define TUNNONCESIZE 32 static constexpr uint32_t TUNNONCESIZE = 32;
#define HMACSIZE 32 static constexpr uint32_t HMACSIZE = 32;
#define PATHIDSIZE 16 static constexpr uint32_t PATHIDSIZE = 16;
#include <libntrup/ntru.h> #include <libntrup/ntru.h>
@ -31,85 +32,86 @@
#define PQ_SECRETKEYSIZE crypto_kem_SECRETKEYBYTES #define PQ_SECRETKEYSIZE crypto_kem_SECRETKEYBYTES
#define PQ_KEYPAIRSIZE (PQ_SECRETKEYSIZE + PQ_PUBKEYSIZE) #define PQ_KEYPAIRSIZE (PQ_SECRETKEYSIZE + PQ_PUBKEYSIZE)
namespace llarp
{
/// label functors /// label functors
/// PKE(result, publickey, secretkey, nonce) /// PKE(result, publickey, secretkey, nonce)
typedef bool (*llarp_path_dh_func)(byte_t *, const byte_t *, const byte_t *, using path_dh_func = std::function<bool(byte_t *, const byte_t *, const byte_t *,
const byte_t *); const byte_t *)>;
/// TKE(result, publickey, secretkey, nonce) /// TKE(result, publickey, secretkey, nonce)
typedef bool (*llarp_transport_dh_func)(byte_t *, const byte_t *, using transport_dh_func = std::function<bool(byte_t *, const byte_t *,
const byte_t *, const byte_t *); const byte_t *, const byte_t *)>;
/// SD/SE(buffer, key, nonce) /// SD/SE(buffer, key, nonce)
typedef bool (*llarp_sym_cipher_func)(llarp_buffer_t, const byte_t *, using sym_cipher_func = std::function<bool(llarp_buffer_t, const byte_t *,
const byte_t *); const byte_t *)>;
/// H(result, body) /// H(result, body)
typedef bool (*llarp_hash_func)(byte_t *, llarp_buffer_t); using hash_func = std::function<bool(byte_t *, llarp_buffer_t)>;
/// SH(result, body) /// SH(result, body)
typedef bool (*llarp_shorthash_func)(byte_t *, llarp_buffer_t); using shorthash_func = std::function<bool(byte_t *, llarp_buffer_t)>;
/// MDS(result, body, shared_secret) /// MDS(result, body, shared_secret)
typedef bool (*llarp_hmac_func)(byte_t *, llarp_buffer_t, const byte_t *); using hmac_func = std::function<bool(byte_t *, llarp_buffer_t, const byte_t *)>;
/// S(sig, secretkey, body) /// S(sig, secretkey, body)
typedef bool (*llarp_sign_func)(byte_t *, const byte_t *, llarp_buffer_t); using sign_func = std::function<bool(byte_t *, const byte_t *, llarp_buffer_t)>;
/// V(pubkey, body, sig) /// V(pubkey, body, sig)
typedef bool (*llarp_verify_func)(const byte_t *, llarp_buffer_t, using verify_func = std::function<bool(const byte_t *, llarp_buffer_t,
const byte_t *); const byte_t *)>;
/// library crypto configuration /// library crypto configuration
struct llarp_crypto struct Crypto
{ {
/// xchacha symettric cipher /// xchacha symettric cipher
llarp_sym_cipher_func xchacha20; sym_cipher_func xchacha20;
/// path dh creator's side /// path dh creator's side
llarp_path_dh_func dh_client; path_dh_func dh_client;
/// path dh relay side /// path dh relay side
llarp_path_dh_func dh_server; path_dh_func dh_server;
/// transport dh client side /// transport dh client side
llarp_transport_dh_func transport_dh_client; transport_dh_func transport_dh_client;
/// transport dh server side /// transport dh server side
llarp_transport_dh_func transport_dh_server; transport_dh_func transport_dh_server;
/// blake2b 512 bit /// blake2b 512 bit
llarp_hash_func hash; hash_func hash;
/// blake2b 256 bit /// blake2b 256 bit
llarp_shorthash_func shorthash; shorthash_func shorthash;
/// blake2s 256 bit hmac /// blake2s 256 bit hmac
llarp_hmac_func hmac; hmac_func hmac;
/// ed25519 sign /// ed25519 sign
llarp_sign_func sign; sign_func sign;
/// ed25519 verify /// ed25519 verify
llarp_verify_func verify; verify_func verify;
/// randomize buffer /// randomize buffer
void (*randomize)(llarp_buffer_t); std::function<void(llarp_buffer_t)> randomize;
/// randomizer memory /// randomizer memory
void (*randbytes)(void *, size_t); std::function<void(void *, size_t)> randbytes;
/// generate signing keypair /// generate signing keypair
void (*identity_keygen)(byte_t *); std::function<void(byte_t *)> identity_keygen;
/// generate encryption keypair /// generate encryption keypair
void (*encryption_keygen)(byte_t *); std::function<void(byte_t *)> encryption_keygen;
/// generate post quantum encrytion key /// generate post quantum encrytion key
void (*pqe_keygen)(byte_t *); std::function<void(byte_t *)> pqe_keygen;
/// post quantum decrypt (buffer, sharedkey_dst, sec) /// post quantum decrypt (buffer, sharedkey_dst, sec)
bool (*pqe_decrypt)(const byte_t *, byte_t *, const byte_t *); std::function<bool(const byte_t *, byte_t *, const byte_t *)> pqe_decrypt;
/// post quantum encrypt (buffer, sharedkey_dst, pub) /// post quantum encrypt (buffer, sharedkey_dst, pub)
bool (*pqe_encrypt)(byte_t *, byte_t *, const byte_t *); std::function<bool(byte_t *, byte_t *, const byte_t *)> pqe_encrypt;
};
/// initialize crypto subsystem // Give a basic type tag for the constructor to pick libsodium
void struct sodium {};
llarp_crypto_init(struct llarp_crypto *c);
/// check for initialize crypto Crypto(Crypto::sodium tag);
bool };
llarp_crypto_initialized(struct llarp_crypto *c);
/// return random 64bit unsigned interger /// return random 64bit unsigned interger
uint64_t uint64_t
llarp_randint(); randint();
}
#endif #endif

@ -36,7 +36,7 @@ namespace llarp
} }
if(candidates.size() == 0) if(candidates.size() == 0)
return false; return false;
result = candidates[llarp_randint() % candidates.size()]; result = candidates[llarp::randint() % candidates.size()];
return true; return true;
} }
@ -79,7 +79,7 @@ namespace llarp
while(N) while(N)
{ {
auto itr = nodes.begin(); auto itr = nodes.begin();
std::advance(itr, llarp_randint() % sz); std::advance(itr, llarp::randint() % sz);
if(result.insert(itr->first).second) if(result.insert(itr->first).second)
--N; --N;
} }

@ -138,7 +138,7 @@ namespace llarp
Context(); Context();
~Context(); ~Context();
llarp_crypto* llarp::Crypto*
Crypto(); Crypto();
/// on behalf of whoasked request introset for target from dht router with /// on behalf of whoasked request introset for target from dht router with

@ -7,8 +7,8 @@ namespace llarp
{ {
bool bool
DecryptInPlace(const byte_t* symkey, const byte_t* nonce, DecryptInPlace(const byte_t* symkey, const byte_t* nonce,
llarp_crypto* crypto); llarp::Crypto* crypto);
}; };
} // namespace llarp } // namespace llarp
#endif #endif

@ -39,11 +39,11 @@ namespace llarp
} }
bool bool
DecryptInPlace(const byte_t* seckey, llarp_crypto* crypto); DecryptInPlace(const byte_t* seckey, llarp::Crypto* crypto);
bool bool
EncryptInPlace(const byte_t* seckey, const byte_t* other, EncryptInPlace(const byte_t* seckey, const byte_t* other,
llarp_crypto* crypto); llarp::Crypto* crypto);
}; };
/// TOOD: can only handle 1 frame at a time /// TOOD: can only handle 1 frame at a time
@ -66,14 +66,14 @@ namespace llarp
} }
} }
llarp_crypto* crypto; llarp::Crypto* crypto;
byte_t* secretkey; byte_t* secretkey;
EncryptHandler handler; EncryptHandler handler;
EncryptedFrame* frame; EncryptedFrame* frame;
User* user; User* user;
byte_t* otherKey; byte_t* otherKey;
AsyncFrameEncrypter(llarp_crypto* c, byte_t* seckey, EncryptHandler h) AsyncFrameEncrypter(llarp::Crypto* c, byte_t* seckey, EncryptHandler h)
: crypto(c), secretkey(seckey), handler(h) : crypto(c), secretkey(seckey), handler(h)
{ {
} }
@ -114,7 +114,7 @@ namespace llarp
ctx->result(nullptr, ctx->context); ctx->result(nullptr, ctx->context);
} }
AsyncFrameDecrypter(llarp_crypto* c, const byte_t* secretkey, AsyncFrameDecrypter(llarp::Crypto* c, const byte_t* secretkey,
DecryptHandler h) DecryptHandler h)
: result(h), crypto(c), seckey(secretkey) : result(h), crypto(c), seckey(secretkey)
{ {
@ -122,7 +122,7 @@ namespace llarp
DecryptHandler result; DecryptHandler result;
User* context; User* context;
llarp_crypto* crypto; llarp::Crypto* crypto;
const byte_t* seckey; const byte_t* seckey;
EncryptedFrame* target; EncryptedFrame* target;

@ -47,7 +47,7 @@ namespace llarp
llarp_time_t llarp_time_t
Now() const; Now() const;
llarp_crypto* llarp::Crypto*
Crypto(); Crypto();
template < typename Stats > template < typename Stats >

@ -10,7 +10,7 @@ namespace llarp {
struct llarp_iwp_args struct llarp_iwp_args
{ {
struct llarp_crypto* crypto; struct llarp::Crypto* crypto;
llarp::Logic* logic; llarp::Logic* logic;
struct llarp_threadpool* cryptoworker; struct llarp_threadpool* cryptoworker;
struct llarp::Router* router; struct llarp::Router* router;

@ -32,10 +32,10 @@ namespace llarp
/// populates I and signs /// populates I and signs
bool bool
Sign(llarp_crypto* c, const llarp::SecretKey& sk); Sign(llarp::Crypto* c, const llarp::SecretKey& sk);
bool bool
Verify(llarp_crypto* c) const; Verify(llarp::Crypto* c) const;
bool bool
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
@ -68,10 +68,10 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
bool bool
Sign(llarp_crypto* c, const llarp::SecretKey& sk); Sign(llarp::Crypto* c, const llarp::SecretKey& sk);
bool bool
Verify(llarp_crypto* c, const llarp::PubKey& pk) const; Verify(llarp::Crypto* c, const llarp::PubKey& pk) const;
bool bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override; DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
@ -101,10 +101,10 @@ namespace llarp
operator=(const RejectExitMessage& other); operator=(const RejectExitMessage& other);
bool bool
Sign(llarp_crypto* c, const llarp::SecretKey& sk); Sign(llarp::Crypto* c, const llarp::SecretKey& sk);
bool bool
Verify(llarp_crypto* c, const llarp::PubKey& pk) const; Verify(llarp::Crypto* c, const llarp::PubKey& pk) const;
bool bool
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
@ -135,10 +135,10 @@ namespace llarp
operator=(const UpdateExitVerifyMessage& other); operator=(const UpdateExitVerifyMessage& other);
bool bool
Sign(llarp_crypto* c, const llarp::SecretKey& sk); Sign(llarp::Crypto* c, const llarp::SecretKey& sk);
bool bool
Verify(llarp_crypto* c, const llarp::PubKey& pk) const; Verify(llarp::Crypto* c, const llarp::PubKey& pk) const;
bool bool
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
@ -170,10 +170,10 @@ namespace llarp
operator=(const UpdateExitMessage& other); operator=(const UpdateExitMessage& other);
bool bool
Sign(llarp_crypto* c, const llarp::SecretKey& sk); Sign(llarp::Crypto* c, const llarp::SecretKey& sk);
bool bool
Verify(llarp_crypto* c, const llarp::PubKey& pk) const; Verify(llarp::Crypto* c, const llarp::PubKey& pk) const;
bool bool
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
@ -213,10 +213,10 @@ namespace llarp
HandleMessage(IMessageHandler* h, llarp::Router* r) const override; HandleMessage(IMessageHandler* h, llarp::Router* r) const override;
bool bool
Sign(llarp_crypto* c, const llarp::SecretKey& sk); Sign(llarp::Crypto* c, const llarp::SecretKey& sk);
bool bool
Verify(llarp_crypto* c, const llarp::PubKey& pk) const; Verify(llarp::Crypto* c, const llarp::PubKey& pk) const;
}; };
} // namespace routing } // namespace routing

@ -38,10 +38,10 @@ namespace llarp
HandleMessage(llarp::Router* router) const; HandleMessage(llarp::Router* router) const;
bool bool
Sign(llarp_crypto* c, const SecretKey& signKeySecret); Sign(llarp::Crypto* c, const SecretKey& signKeySecret);
bool bool
Verify(llarp_crypto* c) const; Verify(llarp::Crypto* c) const;
}; };
} // namespace llarp } // namespace llarp

@ -28,7 +28,7 @@ struct llarp_nodedb_iter
struct llarp_nodedb struct llarp_nodedb
{ {
llarp_nodedb(llarp_crypto *c) : crypto(c) llarp_nodedb(llarp::Crypto *c) : crypto(c)
{ {
} }
@ -37,7 +37,7 @@ struct llarp_nodedb
Clear(); Clear();
} }
llarp_crypto *crypto; llarp::Crypto *crypto;
llarp::util::Mutex access; llarp::util::Mutex access;
std::unordered_map< llarp::RouterID, llarp::RouterContact, std::unordered_map< llarp::RouterID, llarp::RouterContact,
llarp::RouterID::Hash > llarp::RouterID::Hash >
@ -118,7 +118,7 @@ struct llarp_async_verify_rc
struct llarp_nodedb *nodedb; struct llarp_nodedb *nodedb;
// llarp::Logic for queue_job // llarp::Logic for queue_job
llarp::Logic *logic; // includes a llarp_threadpool llarp::Logic *logic; // includes a llarp_threadpool
// struct llarp_crypto *crypto; // probably don't need this because we have // struct llarp::Crypto *crypto; // probably don't need this because we have
// it in the nodedb // it in the nodedb
struct llarp_threadpool *cryptoworker; struct llarp_threadpool *cryptoworker;
struct llarp_threadpool *diskworker; struct llarp_threadpool *diskworker;

@ -627,7 +627,7 @@ namespace llarp
llarp_threadpool* llarp_threadpool*
Worker(); Worker();
llarp_crypto* llarp::Crypto*
Crypto(); Crypto();
llarp::Logic* llarp::Logic*

@ -17,7 +17,7 @@ namespace llarp
~PoW(); ~PoW();
bool bool
IsValid(llarp_shorthash_func hashfunc, llarp_time_t now) const; IsValid(shorthash_func hashfunc, llarp_time_t now) const;
bool bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* val) override; DecodeKey(llarp_buffer_t k, llarp_buffer_t* val) override;

@ -85,10 +85,10 @@ namespace llarp
SetNick(const std::string &nick); SetNick(const std::string &nick);
bool bool
Verify(llarp_crypto *crypto) const; Verify(llarp::Crypto *crypto) const;
bool bool
Sign(llarp_crypto *crypto, const llarp::SecretKey &secret); Sign(llarp::Crypto *crypto, const llarp::SecretKey &secret);
bool bool
OtherIsNewer(const RouterContact &other) const OtherIsNewer(const RouterContact &other) const
@ -104,7 +104,7 @@ namespace llarp
private: private:
bool bool
VerifySignature(llarp_crypto *crypto) const; VerifySignature(llarp::Crypto *crypto) const;
}; };
} // namespace llarp } // namespace llarp

@ -26,7 +26,7 @@ namespace llarp
// regenerate secret keys // regenerate secret keys
void void
RegenerateKeys(llarp_crypto* c); RegenerateKeys(llarp::Crypto* c);
// load from file // load from file
bool bool
@ -36,20 +36,20 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
bool bool
EnsureKeys(const std::string& fpath, llarp_crypto* c); EnsureKeys(const std::string& fpath, llarp::Crypto* c);
bool bool
KeyExchange(llarp_path_dh_func dh, byte_t* sharedkey, KeyExchange(llarp::path_dh_func dh, byte_t* sharedkey,
const ServiceInfo& other, const byte_t* N) const; const ServiceInfo& other, const byte_t* N) const;
bool bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override; DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
bool bool
SignIntroSet(IntroSet& i, llarp_crypto* c, llarp_time_t now) const; SignIntroSet(IntroSet& i, llarp::Crypto* c, llarp_time_t now) const;
bool bool
Sign(llarp_crypto*, byte_t* sig, llarp_buffer_t buf) const; Sign(llarp::Crypto*, byte_t* sig, llarp_buffer_t buf) const;
}; };
} // namespace service } // namespace service
} // namespace llarp } // namespace llarp

@ -45,7 +45,7 @@ namespace llarp
} }
bool bool
Verify(llarp_crypto* crypto, llarp_buffer_t payload, Verify(llarp::Crypto* crypto, llarp_buffer_t payload,
const Signature& sig) const const Signature& sig) const
{ {
return crypto->verify(signkey, payload, sig); return crypto->verify(signkey, payload, sig);

@ -148,7 +148,7 @@ namespace llarp
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override; DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
bool bool
Verify(llarp_crypto* crypto, llarp_time_t now) const; Verify(llarp::Crypto* crypto, llarp_time_t now) const;
}; };
} // namespace service } // namespace service
} // namespace llarp } // namespace llarp

@ -58,7 +58,7 @@ namespace llarp
llarp_ev_loop* llarp_ev_loop*
EndpointNetLoop(); EndpointNetLoop();
llarp_crypto* llarp::Crypto*
Crypto(); Crypto();
llarp_threadpool* llarp_threadpool*

@ -94,17 +94,17 @@ namespace llarp
operator=(const ProtocolFrame& other); operator=(const ProtocolFrame& other);
bool bool
EncryptAndSign(llarp_crypto* c, const ProtocolMessage& msg, EncryptAndSign(llarp::Crypto* c, const ProtocolMessage& msg,
const byte_t* sharedkey, const Identity& localIdent); const byte_t* sharedkey, const Identity& localIdent);
bool bool
AsyncDecryptAndVerify(llarp::Logic* logic, llarp_crypto* c, AsyncDecryptAndVerify(llarp::Logic* logic, llarp::Crypto* c,
const PathID_t& srcpath, llarp_threadpool* worker, const PathID_t& srcpath, llarp_threadpool* worker,
const Identity& localIdent, const Identity& localIdent,
IDataHandler* handler) const; IDataHandler* handler) const;
bool bool
DecryptPayloadInto(llarp_crypto* c, const byte_t* sharedkey, DecryptPayloadInto(llarp::Crypto* c, const byte_t* sharedkey,
ProtocolMessage& into) const; ProtocolMessage& into) const;
bool bool
@ -114,7 +114,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
bool bool
Verify(llarp_crypto* c, const ServiceInfo& from) const; Verify(llarp::Crypto* c, const ServiceInfo& from) const;
bool bool
HandleMessage(llarp::routing::IMessageHandler* h, HandleMessage(llarp::routing::IMessageHandler* h,

@ -81,8 +81,8 @@ namespace llarp
int int
Context::LoadDatabase() Context::LoadDatabase()
{ {
llarp_crypto_init(&crypto); crypto = std::unique_ptr<llarp::Crypto>(new llarp::Crypto{llarp::Crypto::sodium{}});
nodedb = new llarp_nodedb(&crypto); nodedb = new llarp_nodedb(crypto.get());
if(!llarp_nodedb::ensure_dir(nodedb_dir.c_str())) if(!llarp_nodedb::ensure_dir(nodedb_dir.c_str()))
{ {

@ -173,43 +173,44 @@ namespace llarp
return k; return k;
} }
} // namespace llarp Crypto::Crypto(Crypto::sodium tag)
void
llarp_crypto_init(struct llarp_crypto *c)
{ {
(void)tag;
assert(sodium_init() != -1); assert(sodium_init() != -1);
char *avx2 = getenv("AVX2_FORCE_DISABLE"); char *avx2 = std::getenv("AVX2_FORCE_DISABLE");
if(avx2 && std::string(avx2) == "1") if(avx2 && std::string(avx2) == "1")
ntru_init(1); ntru_init(1);
else else
ntru_init(0); ntru_init(0);
c->xchacha20 = llarp::sodium::xchacha20; this->xchacha20 = llarp::sodium::xchacha20;
c->dh_client = llarp::sodium::dh_client; this->dh_client = llarp::sodium::dh_client;
c->dh_server = llarp::sodium::dh_server; this->dh_server = llarp::sodium::dh_server;
c->transport_dh_client = llarp::sodium::dh_client; this->transport_dh_client = llarp::sodium::dh_client;
c->transport_dh_server = llarp::sodium::dh_server; this->transport_dh_server = llarp::sodium::dh_server;
c->hash = llarp::sodium::hash; this->hash = llarp::sodium::hash;
c->shorthash = llarp::sodium::shorthash; this->shorthash = llarp::sodium::shorthash;
c->hmac = llarp::sodium::hmac; this->hmac = llarp::sodium::hmac;
c->sign = llarp::sodium::sign; this->sign = llarp::sodium::sign;
c->verify = llarp::sodium::verify; this->verify = llarp::sodium::verify;
c->randomize = llarp::sodium::randomize; this->randomize = llarp::sodium::randomize;
c->randbytes = llarp::sodium::randbytes; this->randbytes = llarp::sodium::randbytes;
c->identity_keygen = llarp::sodium::sigkeygen; this->identity_keygen = llarp::sodium::sigkeygen;
c->encryption_keygen = llarp::sodium::enckeygen; this->encryption_keygen = llarp::sodium::enckeygen;
c->pqe_encrypt = llarp::pq::encrypt; this->pqe_encrypt = llarp::pq::encrypt;
c->pqe_decrypt = llarp::pq::decrypt; this->pqe_decrypt = llarp::pq::decrypt;
c->pqe_keygen = llarp::pq::keygen; this->pqe_keygen = llarp::pq::keygen;
int seed; int seed = 0;
c->randbytes(&seed, sizeof(seed)); this->randbytes(&seed, sizeof(seed));
srand(seed); srand(seed);
} }
uint64_t uint64_t
llarp_randint() randint()
{ {
uint64_t i; uint64_t i;
randombytes((byte_t *)&i, sizeof(i)); randombytes((byte_t *)&i, sizeof(i));
return i; return i;
} }
} // namespace llarp

@ -149,7 +149,7 @@ namespace llarp
} }
auto itr = nodes.begin(); auto itr = nodes.begin();
// start at random middle point // start at random middle point
auto start = llarp_randint() % nodes.size(); auto start = llarp::randint() % nodes.size();
std::advance(itr, start); std::advance(itr, start);
auto end = itr; auto end = itr;
std::string tagname = tag.ToString(); std::string tagname = tag.ToString();
@ -807,7 +807,7 @@ namespace llarp
} }
} }
llarp_crypto * llarp::Crypto *
Context::Crypto() Context::Crypto()
{ {
return &router->crypto; return &router->crypto;

@ -59,7 +59,7 @@ namespace llarp
if(sz == 1) if(sz == 1)
return m_Resolvers[0]; return m_Resolvers[0];
auto itr = m_Resolvers.begin(); auto itr = m_Resolvers.begin();
std::advance(itr, llarp_randint() % sz); std::advance(itr, llarp::randint() % sz);
return *itr; return *itr;
} }

@ -41,7 +41,7 @@ namespace llarp
bool bool
EncryptedFrame::EncryptInPlace(const byte_t* ourSecretKey, EncryptedFrame::EncryptInPlace(const byte_t* ourSecretKey,
const byte_t* otherPubkey, const byte_t* otherPubkey,
llarp_crypto* crypto) llarp::Crypto* crypto)
{ {
// format of frame is // format of frame is
// <32 bytes keyed hash of following data> // <32 bytes keyed hash of following data>
@ -99,7 +99,7 @@ namespace llarp
bool bool
EncryptedFrame::DecryptInPlace(const byte_t* ourSecretKey, EncryptedFrame::DecryptInPlace(const byte_t* ourSecretKey,
llarp_crypto* crypto) llarp::Crypto* crypto)
{ {
if(size() <= size_t(EncryptedFrame::OverheadSize)) if(size() <= size_t(EncryptedFrame::OverheadSize))
{ {

@ -39,7 +39,7 @@ namespace llarp
} }
bool bool
CloseExitMessage::Verify(llarp_crypto* c, const llarp::PubKey& pk) const CloseExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
@ -53,7 +53,7 @@ namespace llarp
} }
bool bool
CloseExitMessage::Sign(llarp_crypto* c, const llarp::SecretKey& sk) CloseExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);

@ -43,7 +43,7 @@ namespace llarp
} }
bool bool
GrantExitMessage::Verify(llarp_crypto* c, const llarp::PubKey& pk) const GrantExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
@ -57,7 +57,7 @@ namespace llarp
} }
bool bool
GrantExitMessage::Sign(llarp_crypto* c, const llarp::SecretKey& sk) GrantExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);

@ -22,7 +22,7 @@ namespace llarp
} }
bool bool
ObtainExitMessage::Sign(llarp_crypto* c, const llarp::SecretKey& sk) ObtainExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{ {
byte_t tmp[1024] = {0}; byte_t tmp[1024] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
@ -35,7 +35,7 @@ namespace llarp
} }
bool bool
ObtainExitMessage::Verify(llarp_crypto* c) const ObtainExitMessage::Verify(llarp::Crypto* c) const
{ {
byte_t tmp[1024] = {0}; byte_t tmp[1024] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);

@ -64,7 +64,7 @@ namespace llarp
} }
bool bool
RejectExitMessage::Sign(llarp_crypto* c, const llarp::SecretKey& sk) RejectExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
@ -77,7 +77,7 @@ namespace llarp
} }
bool bool
RejectExitMessage::Verify(llarp_crypto* c, const llarp::PubKey& pk) const RejectExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);

@ -60,7 +60,7 @@ namespace llarp
std::placeholders::_2)); std::placeholders::_2));
llarp::routing::ObtainExitMessage obtain; llarp::routing::ObtainExitMessage obtain;
obtain.S = p->NextSeqNo(); obtain.S = p->NextSeqNo();
obtain.T = llarp_randint(); obtain.T = llarp::randint();
PopulateRequest(obtain); PopulateRequest(obtain);
if(!obtain.Sign(&router->crypto, m_ExitIdentity)) if(!obtain.Sign(&router->crypto, m_ExitIdentity))
{ {

@ -43,7 +43,7 @@ namespace llarp
} }
bool bool
UpdateExitMessage::Verify(llarp_crypto* c, const llarp::PubKey& pk) const UpdateExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
@ -70,7 +70,7 @@ namespace llarp
} }
bool bool
UpdateExitMessage::Sign(llarp_crypto* c, const llarp::SecretKey& sk) UpdateExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{ {
byte_t tmp[512] = {0}; byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);

@ -114,7 +114,7 @@ namespace llarp
return m_Router; return m_Router;
} }
llarp_crypto * llarp::Crypto *
ExitEndpoint::Crypto() ExitEndpoint::Crypto()
{ {
return &m_Router->crypto; return &m_Router->crypto;

@ -207,7 +207,7 @@ namespace llarp
// mix keys // mix keys
bool bool
DoKeyExchange(llarp_transport_dh_func dh, const KeyExchangeNonce& n, DoKeyExchange(transport_dh_func dh, const KeyExchangeNonce& n,
const PubKey& other, const byte_t* secret) const PubKey& other, const byte_t* secret)
{ {
ShortHash t_h; ShortHash t_h;

@ -122,7 +122,7 @@ namespace llarp
} }
bool bool
LinkIntroMessage::Sign(llarp_crypto* c, const SecretKey& k) LinkIntroMessage::Sign(llarp::Crypto* c, const SecretKey& k)
{ {
Z.Zero(); Z.Zero();
byte_t tmp[MaxSize] = {0}; byte_t tmp[MaxSize] = {0};
@ -135,7 +135,7 @@ namespace llarp
} }
bool bool
LinkIntroMessage::Verify(llarp_crypto* c) const LinkIntroMessage::Verify(llarp::Crypto* c) const
{ {
LinkIntroMessage copy; LinkIntroMessage copy;
copy = *this; copy = *this;

@ -360,7 +360,7 @@ llarp_nodedb::select_random_exit(llarp::RouterContact &result)
auto itr = entries.begin(); auto itr = entries.begin();
if(sz < 3) if(sz < 3)
return false; return false;
auto idx = llarp_randint() % sz; auto idx = llarp::randint() % sz;
if(idx) if(idx)
std::advance(itr, idx - 1); std::advance(itr, idx - 1);
while(itr != entries.end()) while(itr != entries.end())
@ -403,7 +403,7 @@ llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
auto itr = entries.begin(); auto itr = entries.begin();
if(sz > 1) if(sz > 1)
{ {
auto idx = llarp_randint() % sz; auto idx = llarp::randint() % sz;
if(idx) if(idx)
std::advance(itr, idx - 1); std::advance(itr, idx - 1);
} }
@ -426,7 +426,7 @@ llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
auto itr = entries.begin(); auto itr = entries.begin();
if(sz > 1) if(sz > 1)
{ {
auto idx = llarp_randint() % sz; auto idx = llarp::randint() % sz;
if(idx) if(idx)
std::advance(itr, idx - 1); std::advance(itr, idx - 1);
} }

@ -39,7 +39,7 @@ namespace llarp
return m_Router->tp; return m_Router->tp;
} }
llarp_crypto* llarp::Crypto*
PathContext::Crypto() PathContext::Crypto()
{ {
return &m_Router->crypto; return &m_Router->crypto;
@ -442,7 +442,7 @@ namespace llarp
if(dlt > 5000 && m_LastLatencyTestID == 0) if(dlt > 5000 && m_LastLatencyTestID == 0)
{ {
llarp::routing::PathLatencyMessage latency; llarp::routing::PathLatencyMessage latency;
latency.T = llarp_randint(); latency.T = llarp::randint();
m_LastLatencyTestID = latency.T; m_LastLatencyTestID = latency.T;
m_LastLatencyTestTime = now; m_LastLatencyTestTime = now;
SendRoutingMessage(&latency, r); SendRoutingMessage(&latency, r);
@ -639,7 +639,7 @@ namespace llarp
MarkActive(now); MarkActive(now);
// send path latency test // send path latency test
llarp::routing::PathLatencyMessage latency; llarp::routing::PathLatencyMessage latency;
latency.T = llarp_randint(); latency.T = llarp::randint();
m_LastLatencyTestID = latency.T; m_LastLatencyTestID = latency.T;
m_LastLatencyTestTime = now; m_LastLatencyTestTime = now;
return SendRoutingMessage(&latency, r); return SendRoutingMessage(&latency, r);

@ -23,7 +23,7 @@ namespace llarp
llarp::Router* router = nullptr; llarp::Router* router = nullptr;
llarp_threadpool* worker = nullptr; llarp_threadpool* worker = nullptr;
llarp::Logic* logic = nullptr; llarp::Logic* logic = nullptr;
llarp_crypto* crypto = nullptr; llarp::Crypto* crypto = nullptr;
LR_CommitMessage LRCM; LR_CommitMessage LRCM;
static void static void
@ -111,7 +111,7 @@ namespace llarp
} }
} }
AsyncPathKeyExchangeContext(llarp_crypto* c) : crypto(c) AsyncPathKeyExchangeContext(llarp::Crypto* c) : crypto(c)
{ {
} }

@ -317,7 +317,7 @@ namespace llarp
auto sz = established.size(); auto sz = established.size();
if(sz) if(sz)
{ {
return established[llarp_randint() % sz]; return established[llarp::randint() % sz];
} }
else else
return nullptr; return nullptr;

@ -26,7 +26,7 @@ namespace llarp
} }
bool bool
PoW::IsValid(llarp_shorthash_func hashfunc, llarp_time_t now) const PoW::IsValid(shorthash_func hashfunc, llarp_time_t now) const
{ {
if(now - timestamp > (uint64_t(extendedLifetime) * 1000)) if(now - timestamp > (uint64_t(extendedLifetime) * 1000))
return false; return false;

@ -120,7 +120,7 @@ llarp_router_try_connect(llarp::Router *router,
} }
bool bool
llarp_findOrCreateIdentity(llarp_crypto *crypto, const char *fpath, llarp_findOrCreateIdentity(llarp::Crypto *crypto, const char *fpath,
byte_t *secretkey) byte_t *secretkey)
{ {
llarp::LogDebug("find or create ", fpath); llarp::LogDebug("find or create ", fpath);
@ -148,7 +148,7 @@ llarp_findOrCreateIdentity(llarp_crypto *crypto, const char *fpath,
// C++ ... // C++ ...
bool bool
llarp_findOrCreateEncryption(llarp_crypto *crypto, const char *fpath, llarp_findOrCreateEncryption(llarp::Crypto *crypto, const char *fpath,
llarp::SecretKey &encryption) llarp::SecretKey &encryption)
{ {
llarp::LogDebug("find or create ", fpath); llarp::LogDebug("find or create ", fpath);
@ -190,12 +190,12 @@ namespace llarp
, netloop(_netloop) , netloop(_netloop)
, tp(_tp) , tp(_tp)
, logic(_logic) , logic(_logic)
, crypto(llarp::Crypto::sodium{})
, paths(this) , paths(this)
, exitContext(this) , exitContext(this)
, dht(llarp_dht_context_new(this)) , dht(llarp_dht_context_new(this))
, inbound_link_msg_parser(this) , inbound_link_msg_parser(this)
, hiddenServiceContext(this) , hiddenServiceContext(this)
{ {
// set rational defaults // set rational defaults
this->ip4addr.sin_family = AF_INET; this->ip4addr.sin_family = AF_INET;
@ -206,7 +206,6 @@ namespace llarp
#else #else
disk = llarp_init_threadpool(1, "llarp-diskio"); disk = llarp_init_threadpool(1, "llarp-diskio");
#endif #endif
llarp_crypto_init(&crypto);
} }
Router::~Router() Router::~Router()
@ -786,7 +785,7 @@ namespace llarp
{ {
auto itr = validRouters.begin(); auto itr = validRouters.begin();
if(sz > 1) if(sz > 1)
std::advance(itr, llarp_randint() % sz); std::advance(itr, llarp::randint() % sz);
result = itr->second; result = itr->second;
return true; return true;
} }
@ -1039,7 +1038,7 @@ namespace llarp
// check if we really want to // check if we really want to
if(!self->ConnectionToRouterAllowed(other.pubkey)) if(!self->ConnectionToRouterAllowed(other.pubkey))
return want > 0; return want > 0;
if(llarp_randint() % 2 == 0 if(llarp::randint() % 2 == 0
&& !(self->HasSessionTo(other.pubkey) && !(self->HasSessionTo(other.pubkey)
|| self->HasPendingConnectJob(other.pubkey))) || self->HasPendingConnectJob(other.pubkey)))
{ {

@ -33,11 +33,11 @@
#include <str.hpp> #include <str.hpp>
bool bool
llarp_findOrCreateEncryption(llarp_crypto *crypto, const char *fpath, llarp_findOrCreateEncryption(llarp::Crypto *crypto, const char *fpath,
llarp::SecretKey &encryption); llarp::SecretKey &encryption);
bool bool
llarp_findOrCreateIdentity(struct llarp_crypto *crypto, const char *path, llarp_findOrCreateIdentity(struct llarp::Crypto *crypto, const char *path,
byte_t *secretkey); byte_t *secretkey);
struct TryConnectJob; struct TryConnectJob;
@ -82,7 +82,7 @@ namespace llarp
llarp_ev_loop *netloop; llarp_ev_loop *netloop;
llarp_threadpool *tp; llarp_threadpool *tp;
llarp::Logic *logic; llarp::Logic *logic;
llarp_crypto crypto; llarp::Crypto crypto;
llarp::path::PathContext paths; llarp::path::PathContext paths;
llarp::exit::Context exitContext; llarp::exit::Context exitContext;
llarp::SecretKey identity; llarp::SecretKey identity;

@ -150,7 +150,7 @@ namespace llarp
} }
bool bool
RouterContact::Sign(llarp_crypto *crypto, const SecretKey &secretkey) RouterContact::Sign(llarp::Crypto *crypto, const SecretKey &secretkey)
{ {
pubkey = llarp::seckey_topublic(secretkey); pubkey = llarp::seckey_topublic(secretkey);
byte_t tmp[MAX_RC_SIZE] = {0}; byte_t tmp[MAX_RC_SIZE] = {0};
@ -165,7 +165,7 @@ namespace llarp
} }
bool bool
RouterContact::Verify(llarp_crypto *crypto) const RouterContact::Verify(llarp::Crypto *crypto) const
{ {
for(const auto &a : addrs) for(const auto &a : addrs)
{ {
@ -184,7 +184,7 @@ namespace llarp
} }
bool bool
RouterContact::VerifySignature(llarp_crypto *crypto) const RouterContact::VerifySignature(llarp::Crypto *crypto) const
{ {
RouterContact copy; RouterContact copy;
copy = *this; copy = *this;

@ -199,7 +199,7 @@ namespace llarp
} }
void void
Identity::RegenerateKeys(llarp_crypto* crypto) Identity::RegenerateKeys(llarp::Crypto* crypto)
{ {
crypto->encryption_keygen(enckey); crypto->encryption_keygen(enckey);
crypto->identity_keygen(signkey); crypto->identity_keygen(signkey);
@ -209,20 +209,20 @@ namespace llarp
} }
bool bool
Identity::KeyExchange(llarp_path_dh_func dh, byte_t* result, Identity::KeyExchange(path_dh_func dh, byte_t* result,
const ServiceInfo& other, const byte_t* N) const const ServiceInfo& other, const byte_t* N) const
{ {
return dh(result, other.EncryptionPublicKey(), enckey, N); return dh(result, other.EncryptionPublicKey(), enckey, N);
} }
bool bool
Identity::Sign(llarp_crypto* c, byte_t* sig, llarp_buffer_t buf) const Identity::Sign(llarp::Crypto* c, byte_t* sig, llarp_buffer_t buf) const
{ {
return c->sign(sig, signkey, buf); return c->sign(sig, signkey, buf);
} }
bool bool
Identity::EnsureKeys(const std::string& fname, llarp_crypto* c) Identity::EnsureKeys(const std::string& fname, llarp::Crypto* c)
{ {
byte_t tmp[4096]; byte_t tmp[4096];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
@ -272,7 +272,7 @@ namespace llarp
} }
bool bool
Identity::SignIntroSet(IntroSet& i, llarp_crypto* crypto, Identity::SignIntroSet(IntroSet& i, llarp::Crypto* crypto,
llarp_time_t now) const llarp_time_t now) const
{ {
if(i.I.size() == 0) if(i.I.size() == 0)
@ -297,7 +297,7 @@ namespace llarp
} }
bool bool
IntroSet::Verify(llarp_crypto* crypto, llarp_time_t now) const IntroSet::Verify(llarp::Crypto* crypto, llarp_time_t now) const
{ {
byte_t tmp[MAX_INTROSET_SIZE]; byte_t tmp[MAX_INTROSET_SIZE];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);

@ -261,7 +261,7 @@ namespace llarp
uint64_t uint64_t
Endpoint::GenTXID() Endpoint::GenTXID()
{ {
uint64_t txid = llarp_randint(); uint64_t txid = llarp::randint();
while(m_PendingLookups.find(txid) != m_PendingLookups.end()) while(m_PendingLookups.find(txid) != m_PendingLookups.end())
++txid; ++txid;
return txid; return txid;
@ -1363,7 +1363,7 @@ namespace llarp
struct AsyncKeyExchange struct AsyncKeyExchange
{ {
llarp::Logic* logic; llarp::Logic* logic;
llarp_crypto* crypto; llarp::Crypto* crypto;
SharedSecret sharedKey; SharedSecret sharedKey;
ServiceInfo remote; ServiceInfo remote;
const Identity& m_LocalIdentity; const Identity& m_LocalIdentity;
@ -1376,7 +1376,7 @@ namespace llarp
IDataHandler* handler; IDataHandler* handler;
ConvoTag tag; ConvoTag tag;
AsyncKeyExchange(llarp::Logic* l, llarp_crypto* c, const ServiceInfo& r, AsyncKeyExchange(llarp::Logic* l, llarp::Crypto* c, const ServiceInfo& r,
const Identity& localident, const Identity& localident,
const PQPubKey& introsetPubKey, const PQPubKey& introsetPubKey,
const Introduction& remote, IDataHandler* h, const Introduction& remote, IDataHandler* h,
@ -1722,7 +1722,7 @@ namespace llarp
return m_IsolatedLogic ? m_IsolatedLogic : m_Router->logic; return m_IsolatedLogic ? m_IsolatedLogic : m_Router->logic;
} }
llarp_crypto* llarp::Crypto*
Endpoint::Crypto() Endpoint::Crypto()
{ {
return &m_Router->crypto; return &m_Router->crypto;

@ -153,7 +153,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::DecryptPayloadInto(llarp_crypto* crypto, ProtocolFrame::DecryptPayloadInto(llarp::Crypto* crypto,
const byte_t* sharedkey, const byte_t* sharedkey,
ProtocolMessage& msg) const ProtocolMessage& msg) const
{ {
@ -164,7 +164,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::EncryptAndSign(llarp_crypto* crypto, ProtocolFrame::EncryptAndSign(llarp::Crypto* crypto,
const ProtocolMessage& msg, const ProtocolMessage& msg,
const byte_t* sessionKey, const byte_t* sessionKey,
const Identity& localIdent) const Identity& localIdent)
@ -208,14 +208,14 @@ namespace llarp
struct AsyncFrameDecrypt struct AsyncFrameDecrypt
{ {
llarp_crypto* crypto; llarp::Crypto* crypto;
llarp::Logic* logic; llarp::Logic* logic;
ProtocolMessage* msg; ProtocolMessage* msg;
const Identity& m_LocalIdentity; const Identity& m_LocalIdentity;
IDataHandler* handler; IDataHandler* handler;
const ProtocolFrame frame; const ProtocolFrame frame;
AsyncFrameDecrypt(llarp::Logic* l, llarp_crypto* c, AsyncFrameDecrypt(llarp::Logic* l, llarp::Crypto* c,
const Identity& localIdent, IDataHandler* h, const Identity& localIdent, IDataHandler* h,
ProtocolMessage* m, const ProtocolFrame& f) ProtocolMessage* m, const ProtocolFrame& f)
: crypto(c) : crypto(c)
@ -306,7 +306,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::AsyncDecryptAndVerify(llarp::Logic* logic, llarp_crypto* c, ProtocolFrame::AsyncDecryptAndVerify(llarp::Logic* logic, llarp::Crypto* c,
const PathID_t& srcPath, const PathID_t& srcPath,
llarp_threadpool* worker, llarp_threadpool* worker,
const Identity& localIdent, const Identity& localIdent,
@ -361,7 +361,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::Verify(llarp_crypto* crypto, const ServiceInfo& from) const ProtocolFrame::Verify(llarp::Crypto* crypto, const ServiceInfo& from) const
{ {
ProtocolFrame copy(*this); ProtocolFrame copy(*this);
// save signature // save signature

@ -7,11 +7,11 @@ using Map_t = std::unordered_map< Buffer_t, int, Buffer_t::Hash >;
struct AlignedBufferTest : public ::testing::Test struct AlignedBufferTest : public ::testing::Test
{ {
AlignedBufferTest() AlignedBufferTest()
: crypto(llarp::Crypto::sodium{})
{ {
llarp_crypto_init(&crypto);
} }
llarp_crypto crypto; llarp::Crypto crypto;
}; };
TEST_F(AlignedBufferTest, TestHash) TEST_F(AlignedBufferTest, TestHash)

@ -6,11 +6,11 @@
struct Base32Test : public ::testing::Test struct Base32Test : public ::testing::Test
{ {
Base32Test() Base32Test()
: crypto(llarp::Crypto::sodium{})
{ {
llarp_crypto_init(&crypto);
} }
llarp_crypto crypto; llarp::Crypto crypto;
}; };
TEST_F(Base32Test, Serialize) TEST_F(Base32Test, Serialize)

@ -11,12 +11,12 @@ using LRCR = llarp::LR_CommitRecord;
class FrameTest : public ::testing::Test class FrameTest : public ::testing::Test
{ {
public: public:
llarp_crypto crypto; llarp::Crypto crypto;
SecretKey alice, bob; SecretKey alice, bob;
FrameTest() FrameTest()
: crypto(llarp::Crypto::sodium{})
{ {
llarp_crypto_init(&crypto);
} }
~FrameTest() ~FrameTest()

@ -5,15 +5,15 @@
struct HiddenServiceTest : public ::testing::Test struct HiddenServiceTest : public ::testing::Test
{ {
llarp_crypto crypto; llarp::Crypto crypto;
llarp::service::Identity ident; llarp::service::Identity ident;
HiddenServiceTest() HiddenServiceTest()
: crypto(llarp::Crypto::sodium{})
{ {
llarp_crypto_init(&crypto);
} }
llarp_crypto* llarp::Crypto*
Crypto() Crypto()
{ {
return &crypto; return &crypto;

@ -6,7 +6,7 @@
struct AbyssTestBase : public ::testing::Test struct AbyssTestBase : public ::testing::Test
{ {
llarp_crypto crypto; llarp::Crypto crypto;
llarp_threadpool* threadpool = nullptr; llarp_threadpool* threadpool = nullptr;
llarp_ev_loop* loop = nullptr; llarp_ev_loop* loop = nullptr;
llarp::Logic* logic = nullptr; llarp::Logic* logic = nullptr;
@ -24,7 +24,7 @@ struct AbyssTestBase : public ::testing::Test
void void
SetUp() SetUp()
{ {
// for llarp_randint // for llarp::randint
llarp_crypto_init(&crypto); llarp_crypto_init(&crypto);
} }
@ -45,7 +45,7 @@ struct AbyssTestBase : public ::testing::Test
sockaddr_in addr; sockaddr_in addr;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons((llarp_randint() % 2000) + 2000); addr.sin_port = htons((llarp::randint() % 2000) + 2000);
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
llarp::Addr a(addr); llarp::Addr a(addr);
while(true) while(true)

@ -6,12 +6,12 @@ using ObtainExitMessage = llarp::routing::ObtainExitMessage;
class ObtainExitTest : public ::testing::Test class ObtainExitTest : public ::testing::Test
{ {
public: public:
llarp_crypto crypto; llarp::Crypto crypto;
llarp::SecretKey alice; llarp::SecretKey alice;
ObtainExitTest() ObtainExitTest()
: crypto(llarp::Crypto::sodium{})
{ {
llarp_crypto_init(&crypto);
} }
~ObtainExitTest() ~ObtainExitTest()
@ -29,11 +29,11 @@ TEST_F(ObtainExitTest, TestSignVerify)
{ {
ObtainExitMessage msg; ObtainExitMessage msg;
msg.Z.Zero(); msg.Z.Zero();
msg.S = llarp_randint(); msg.S = llarp::randint();
msg.T = llarp_randint(); msg.T = llarp::randint();
ASSERT_TRUE(msg.Sign(&crypto, alice)); ASSERT_TRUE(msg.Sign(&crypto, alice));
ASSERT_TRUE(msg.Verify(&crypto)); ASSERT_TRUE(msg.Verify(&crypto));
ASSERT_TRUE(msg.I == llarp::PubKey(llarp::seckey_topublic(alice))); ASSERT_TRUE(msg.I == llarp::PubKey(llarp::seckey_topublic(alice)));
ASSERT_FALSE(msg.version != LLARP_PROTO_VERSION); ASSERT_FALSE(msg.version != LLARP_PROTO_VERSION);
ASSERT_FALSE(msg.Z.IsZero()); ASSERT_FALSE(msg.Z.IsZero());
}; };

@ -6,15 +6,15 @@ namespace llarp
{ {
struct PQCryptoTest : public ::testing::Test struct PQCryptoTest : public ::testing::Test
{ {
llarp_crypto crypto; llarp::Crypto crypto;
PQKeyPair keys; PQKeyPair keys;
PQCryptoTest() PQCryptoTest()
: crypto(llarp::Crypto::sodium{})
{ {
llarp_crypto_init(&crypto);
} }
llarp_crypto* llarp::Crypto*
Crypto() Crypto()
{ {
return &crypto; return &crypto;

Loading…
Cancel
Save