2019-01-26 15:40:58 +00:00
|
|
|
#include <crypto/crypto_libsodium.hpp>
|
2018-10-23 12:57:57 +00:00
|
|
|
#include <sodium/crypto_generichash.h>
|
|
|
|
#include <sodium/crypto_sign.h>
|
|
|
|
#include <sodium/crypto_scalarmult.h>
|
2018-07-27 02:34:09 +00:00
|
|
|
#include <sodium/crypto_stream_xchacha20.h>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/mem.hpp>
|
|
|
|
|
|
|
|
#include <assert.h>
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-10-23 12:57:57 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
extern int
|
|
|
|
sodium_init(void);
|
|
|
|
}
|
|
|
|
|
2019-03-20 14:51:10 +00:00
|
|
|
#include "ec.hpp"
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace sodium
|
|
|
|
{
|
|
|
|
static bool
|
2019-01-02 01:04:03 +00:00
|
|
|
dh(llarp::SharedSecret &out, const PubKey &client_pk,
|
2019-01-02 01:04:04 +00:00
|
|
|
const PubKey &server_pk, const uint8_t *themPub, const SecretKey &usSec)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-06-12 11:57:14 +00:00
|
|
|
llarp::SharedSecret shared;
|
2018-05-22 15:54:19 +00:00
|
|
|
crypto_generichash_state h;
|
2018-05-23 20:37:43 +00:00
|
|
|
|
2019-01-02 01:04:08 +00:00
|
|
|
if(crypto_scalarmult_curve25519(shared.data(), usSec.data(), themPub))
|
2019-01-26 15:40:58 +00:00
|
|
|
{
|
2018-05-22 15:54:19 +00:00
|
|
|
return false;
|
2019-01-26 15:40:58 +00:00
|
|
|
}
|
2019-01-13 16:30:07 +00:00
|
|
|
crypto_generichash_blake2b_init(&h, nullptr, 0U, shared.size());
|
2019-01-02 01:04:04 +00:00
|
|
|
crypto_generichash_blake2b_update(&h, client_pk.data(), 32);
|
|
|
|
crypto_generichash_blake2b_update(&h, server_pk.data(), 32);
|
|
|
|
crypto_generichash_blake2b_update(&h, shared.data(), 32);
|
2019-01-13 16:30:07 +00:00
|
|
|
crypto_generichash_blake2b_final(&h, out.data(), shared.size());
|
2018-05-22 15:54:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
static bool
|
2019-01-26 15:40:58 +00:00
|
|
|
dh_client_priv(llarp::SharedSecret &shared, const PubKey &pk,
|
|
|
|
const SecretKey &sk, const TunnelNonce &n)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-06-12 11:57:14 +00:00
|
|
|
llarp::SharedSecret dh_result;
|
2018-08-13 08:47:24 +00:00
|
|
|
|
2019-01-02 01:04:08 +00:00
|
|
|
if(dh(dh_result, sk.toPublic(), pk, pk.data(), sk))
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-01-02 01:04:08 +00:00
|
|
|
return crypto_generichash_blake2b(shared.data(), 32, n.data(), 32,
|
2019-01-02 01:04:04 +00:00
|
|
|
dh_result.data(), 32)
|
2018-10-23 11:29:37 +00:00
|
|
|
!= -1;
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-08-13 08:47:24 +00:00
|
|
|
llarp::LogWarn("crypto::dh_client - dh failed");
|
2018-05-22 15:54:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-18 16:08:47 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
static bool
|
2019-01-26 15:40:58 +00:00
|
|
|
dh_server_priv(llarp::SharedSecret &shared, const PubKey &pk,
|
|
|
|
const SecretKey &sk, const TunnelNonce &n)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-06-12 11:57:14 +00:00
|
|
|
llarp::SharedSecret dh_result;
|
2019-01-02 01:04:08 +00:00
|
|
|
if(dh(dh_result, pk, sk.toPublic(), pk.data(), sk))
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-01-02 01:04:08 +00:00
|
|
|
return crypto_generichash_blake2b(shared.data(), 32, n.data(), 32,
|
2019-01-02 01:04:04 +00:00
|
|
|
dh_result.data(), 32)
|
2018-10-23 11:29:37 +00:00
|
|
|
!= -1;
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-08-13 08:47:24 +00:00
|
|
|
llarp::LogWarn("crypto::dh_server - dh failed");
|
2018-05-22 15:54:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-18 16:08:47 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
CryptoLibSodium::CryptoLibSodium()
|
|
|
|
{
|
|
|
|
if(sodium_init() == -1)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("sodium_init() returned -1");
|
|
|
|
}
|
|
|
|
char *avx2 = std::getenv("AVX2_FORCE_DISABLE");
|
|
|
|
if(avx2 && std::string(avx2) == "1")
|
|
|
|
{
|
|
|
|
ntru_init(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ntru_init(0);
|
|
|
|
}
|
|
|
|
int seed = 0;
|
2019-05-28 19:45:09 +00:00
|
|
|
randombytes(reinterpret_cast< unsigned char * >(&seed), sizeof(seed));
|
2019-01-26 15:40:58 +00:00
|
|
|
srand(seed);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
CryptoLibSodium::xchacha20(const llarp_buffer_t &buff,
|
|
|
|
const SharedSecret &k, const TunnelNonce &n)
|
2019-01-26 15:40:58 +00:00
|
|
|
{
|
|
|
|
return crypto_stream_xchacha20_xor(buff.base, buff.base, buff.sz,
|
|
|
|
n.data(), k.data())
|
|
|
|
== 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
CryptoLibSodium::xchacha20_alt(const llarp_buffer_t &out,
|
|
|
|
const llarp_buffer_t &in,
|
2019-01-26 15:40:58 +00:00
|
|
|
const SharedSecret &k, const byte_t *n)
|
|
|
|
{
|
|
|
|
if(in.sz > out.sz)
|
|
|
|
return false;
|
|
|
|
return crypto_stream_xchacha20_xor(out.base, in.base, in.sz, n, k.data())
|
|
|
|
== 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CryptoLibSodium::dh_client(llarp::SharedSecret &shared, const PubKey &pk,
|
|
|
|
const SecretKey &sk, const TunnelNonce &n)
|
|
|
|
{
|
|
|
|
return dh_client_priv(shared, pk, sk, n);
|
|
|
|
}
|
|
|
|
/// path dh relay side
|
|
|
|
bool
|
|
|
|
CryptoLibSodium::dh_server(llarp::SharedSecret &shared, const PubKey &pk,
|
|
|
|
const SecretKey &sk, const TunnelNonce &n)
|
|
|
|
{
|
|
|
|
return dh_server_priv(shared, pk, sk, n);
|
|
|
|
}
|
|
|
|
/// transport dh client side
|
|
|
|
bool
|
|
|
|
CryptoLibSodium::transport_dh_client(llarp::SharedSecret &shared,
|
|
|
|
const PubKey &pk, const SecretKey &sk,
|
|
|
|
const TunnelNonce &n)
|
|
|
|
{
|
|
|
|
return dh_client_priv(shared, pk, sk, n);
|
|
|
|
}
|
|
|
|
/// transport dh server side
|
|
|
|
bool
|
|
|
|
CryptoLibSodium::transport_dh_server(llarp::SharedSecret &shared,
|
|
|
|
const PubKey &pk, const SecretKey &sk,
|
|
|
|
const TunnelNonce &n)
|
|
|
|
{
|
|
|
|
return dh_server_priv(shared, pk, sk, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
CryptoLibSodium::shorthash(ShortHash &result, const llarp_buffer_t &buff)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-01-02 01:04:08 +00:00
|
|
|
return crypto_generichash_blake2b(result.data(), ShortHash::SIZE,
|
|
|
|
buff.base, buff.sz, nullptr, 0)
|
2018-05-22 15:54:19 +00:00
|
|
|
!= -1;
|
|
|
|
}
|
2018-01-19 16:51:27 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
CryptoLibSodium::hmac(byte_t *result, const llarp_buffer_t &buff,
|
2019-01-26 15:40:58 +00:00
|
|
|
const SharedSecret &secret)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-10-23 11:29:37 +00:00
|
|
|
return crypto_generichash_blake2b(result, HMACSIZE, buff.base, buff.sz,
|
2019-01-02 01:04:04 +00:00
|
|
|
secret.data(), HMACSECSIZE)
|
2018-05-22 15:54:19 +00:00
|
|
|
!= -1;
|
|
|
|
}
|
2018-01-19 16:51:27 +00:00
|
|
|
|
2019-03-20 14:51:10 +00:00
|
|
|
using ec_scalar = AlignedBuffer< 32 >;
|
|
|
|
|
|
|
|
struct s_comm final
|
|
|
|
: public AlignedBuffer< LongHash::SIZE + (ec_scalar::SIZE * 2) >
|
|
|
|
{
|
|
|
|
byte_t *
|
|
|
|
H()
|
|
|
|
{
|
|
|
|
return data();
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_t *
|
|
|
|
K()
|
|
|
|
{
|
|
|
|
return data() + LongHash::SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_t *
|
|
|
|
C()
|
|
|
|
{
|
|
|
|
return data() + LongHash::SIZE + ec_scalar::SIZE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
IsNonZero(const byte_t *s)
|
|
|
|
{
|
|
|
|
return (((int)(s[0] | s[1] | s[2] | s[3] | s[4] | s[5] | s[6] | s[7]
|
|
|
|
| s[8] | s[9] | s[10] | s[11] | s[12] | s[13] | s[14]
|
|
|
|
| s[15] | s[16] | s[17] | s[18] | s[19] | s[20] | s[21]
|
|
|
|
| s[22] | s[23] | s[24] | s[25] | s[26] | s[27] | s[28]
|
|
|
|
| s[29] | s[30] | s[31])
|
|
|
|
- 1)
|
|
|
|
>> 8)
|
|
|
|
+ 1;
|
|
|
|
}
|
|
|
|
|
2019-03-28 19:15:20 +00:00
|
|
|
static inline bool
|
|
|
|
less32(const unsigned char *k0, const unsigned char *k1)
|
|
|
|
{
|
|
|
|
for(int n = 31; n >= 0; --n)
|
|
|
|
{
|
|
|
|
if(k0[n] < k1[n])
|
|
|
|
return true;
|
|
|
|
if(k0[n] > k1[n])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rand32_unbais(byte_t *k)
|
|
|
|
{
|
|
|
|
// l = 2^252 + 27742317777372353535851937790883648493.
|
|
|
|
// it fits 15 in 32 bytes
|
|
|
|
static const unsigned char limit[32] = {
|
|
|
|
0xe3, 0x6a, 0x67, 0x72, 0x8b, 0xce, 0x13, 0x29, 0x8f, 0x30, 0x82,
|
|
|
|
0x8c, 0x0b, 0xa4, 0x10, 0x39, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0};
|
|
|
|
do
|
|
|
|
{
|
|
|
|
randombytes(k, 32);
|
|
|
|
} while(!IsNonZero(k) && !less32(k, limit));
|
|
|
|
sc25519_reduce32(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
check_key(const byte_t *k)
|
|
|
|
{
|
|
|
|
ge25519_p3 p;
|
|
|
|
return ge25519_frombytes_vartime(&p, k) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template < typename T, size_t outsz = ec_scalar::SIZE >
|
|
|
|
static inline bool
|
|
|
|
hash_to_scalar(const T &in, byte_t *out)
|
|
|
|
{
|
|
|
|
if(crypto_generichash_blake2b(out, outsz, in.data(), in.size(), nullptr,
|
|
|
|
0)
|
|
|
|
== -1)
|
|
|
|
return false;
|
|
|
|
sc25519_reduce32(out);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-28 19:45:09 +00:00
|
|
|
static bool
|
|
|
|
hash(uint8_t *result, const llarp_buffer_t &buff)
|
|
|
|
{
|
|
|
|
return crypto_generichash_blake2b(result, HASHSIZE, buff.base, buff.sz,
|
|
|
|
nullptr, 0)
|
|
|
|
!= -1;
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
bool
|
2019-03-20 14:51:10 +00:00
|
|
|
CryptoLibSodium::sign(Signature &sig, const SecretKey &secret,
|
|
|
|
const llarp_buffer_t &buf)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-03-28 19:15:20 +00:00
|
|
|
s_comm tmp;
|
|
|
|
if(!hash(tmp.H(), buf))
|
2019-03-20 14:51:10 +00:00
|
|
|
return false;
|
|
|
|
ge25519_p3 tmp3;
|
2019-03-28 19:15:20 +00:00
|
|
|
ec_scalar K;
|
|
|
|
const PubKey pk = secret.toPublic();
|
|
|
|
std::copy_n(pk.begin(), pk.size(), tmp.K());
|
2019-03-20 14:51:10 +00:00
|
|
|
do
|
|
|
|
{
|
2019-03-28 19:15:20 +00:00
|
|
|
rand32_unbais(K.data());
|
|
|
|
if(((const uint32_t *)(K.data()))[7]
|
2019-03-20 14:51:10 +00:00
|
|
|
== 0) // we don't want tiny numbers here
|
|
|
|
continue;
|
2019-03-28 19:15:20 +00:00
|
|
|
ge25519_scalarmult_base(&tmp3, K.data());
|
2019-03-20 14:51:10 +00:00
|
|
|
ge25519_p3_tobytes(tmp.C(), &tmp3);
|
|
|
|
hash_to_scalar(tmp, sig.C());
|
|
|
|
if(!IsNonZero(sig.C()))
|
|
|
|
continue;
|
2019-03-28 19:15:20 +00:00
|
|
|
sc25519_mulsub(sig.R(), sig.C(), secret.data(), K.data());
|
2019-03-20 14:51:10 +00:00
|
|
|
if(!IsNonZero(sig.R()))
|
|
|
|
continue;
|
|
|
|
return true;
|
|
|
|
} while(true);
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-01-19 16:51:27 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
bool
|
2019-03-20 14:51:10 +00:00
|
|
|
CryptoLibSodium::verify(const PubKey &pub, const llarp_buffer_t &buf,
|
2019-01-26 15:40:58 +00:00
|
|
|
const Signature &sig)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-03-20 14:51:10 +00:00
|
|
|
s_comm tmp;
|
|
|
|
ge25519_p2 tmp2;
|
|
|
|
ge25519_p3 tmp3;
|
|
|
|
ec_scalar C;
|
2019-03-28 19:15:20 +00:00
|
|
|
std::copy_n(pub.begin(), pub.size(), tmp.K());
|
2019-03-20 14:51:10 +00:00
|
|
|
if(!hash(tmp.H(), buf))
|
|
|
|
return false;
|
|
|
|
if(ge25519_frombytes_vartime(&tmp3, pub.data()) != 0)
|
|
|
|
return false;
|
|
|
|
if(sc25519_check(sig.C()) != 0 || sc25519_check(sig.R()) != 0
|
|
|
|
|| !IsNonZero(sig.C()))
|
|
|
|
return false;
|
|
|
|
ge25519_double_scalarmult_base_vartime(&tmp2, sig.C(), &tmp3, sig.R());
|
|
|
|
ge25519_tobytes(tmp.C(), &tmp2);
|
|
|
|
static const ec_scalar infinity{{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
|
|
|
if(memcmp(tmp.C(), &infinity, 32) == 0)
|
|
|
|
return false;
|
|
|
|
hash_to_scalar(tmp, C.data());
|
|
|
|
sc25519_sub(C.data(), C.data(), sig.C());
|
2019-03-28 19:15:20 +00:00
|
|
|
return !IsNonZero(C.data());
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-01-31 19:59:26 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
bool
|
|
|
|
CryptoLibSodium::seed_to_secretkey(llarp::SecretKey &secret,
|
|
|
|
const llarp::IdentitySecret &seed)
|
2019-01-21 15:45:18 +00:00
|
|
|
{
|
2019-03-28 19:15:20 +00:00
|
|
|
if(sc25519_check(seed.data()) != 0)
|
|
|
|
return false;
|
2019-03-19 22:06:21 +00:00
|
|
|
ge25519_p3 A;
|
|
|
|
std::copy_n(seed.begin(), 32, secret.begin());
|
|
|
|
ge25519_scalarmult_base(&A, seed.data());
|
2019-03-20 14:51:10 +00:00
|
|
|
byte_t *pub = secret.data() + 32;
|
2019-03-19 22:06:21 +00:00
|
|
|
ge25519_p3_tobytes(pub, &A);
|
|
|
|
return true;
|
2019-01-21 15:45:18 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
void
|
2019-02-01 01:58:06 +00:00
|
|
|
CryptoLibSodium::randomize(const llarp_buffer_t &buff)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
|
|
|
randombytes((unsigned char *)buff.base, buff.sz);
|
|
|
|
}
|
2018-01-31 19:59:26 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
void
|
2019-05-28 19:45:09 +00:00
|
|
|
CryptoLibSodium::randbytes(byte_t *ptr, size_t sz)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
|
|
|
randombytes((unsigned char *)ptr, sz);
|
|
|
|
}
|
2018-02-01 22:34:04 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
void
|
|
|
|
CryptoLibSodium::identity_keygen(llarp::SecretKey &keys)
|
2018-05-23 20:37:43 +00:00
|
|
|
{
|
2019-03-20 14:51:10 +00:00
|
|
|
llarp::IdentitySecret seed;
|
2019-03-28 19:15:20 +00:00
|
|
|
rand32_unbais(seed.data());
|
2019-03-20 14:51:10 +00:00
|
|
|
seed_to_secretkey(keys, seed);
|
2018-05-23 20:37:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
void
|
|
|
|
CryptoLibSodium::encryption_keygen(llarp::SecretKey &keys)
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-01-02 01:04:04 +00:00
|
|
|
auto d = keys.data();
|
2019-03-28 19:15:20 +00:00
|
|
|
rand32_unbais(d);
|
2019-01-02 01:04:03 +00:00
|
|
|
crypto_scalarmult_curve25519_base(d + 32, d);
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-08-13 23:22:31 +00:00
|
|
|
bool
|
2019-01-26 15:40:58 +00:00
|
|
|
CryptoLibSodium::pqe_encrypt(PQCipherBlock &ciphertext,
|
|
|
|
SharedSecret &sharedkey,
|
|
|
|
const PQPubKey &pubkey)
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2019-01-02 01:04:08 +00:00
|
|
|
return crypto_kem_enc(ciphertext.data(), sharedkey.data(), pubkey.data())
|
2019-01-02 01:04:03 +00:00
|
|
|
!= -1;
|
2018-08-13 23:22:31 +00:00
|
|
|
}
|
|
|
|
bool
|
2019-01-26 15:40:58 +00:00
|
|
|
CryptoLibSodium::pqe_decrypt(const PQCipherBlock &ciphertext,
|
|
|
|
SharedSecret &sharedkey,
|
|
|
|
const byte_t *secretkey)
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2019-01-02 01:04:08 +00:00
|
|
|
return crypto_kem_dec(sharedkey.data(), ciphertext.data(), secretkey)
|
2019-01-02 01:04:03 +00:00
|
|
|
!= -1;
|
2018-08-13 23:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-26 15:40:58 +00:00
|
|
|
CryptoLibSodium::pqe_keygen(PQKeyPair &keypair)
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2019-01-02 01:04:04 +00:00
|
|
|
auto d = keypair.data();
|
2019-01-02 01:04:03 +00:00
|
|
|
crypto_kem_keypair(d + PQ_SECRETKEYSIZE, d);
|
2018-08-13 23:22:31 +00:00
|
|
|
}
|
2019-01-26 15:40:58 +00:00
|
|
|
} // namespace sodium
|
|
|
|
|
|
|
|
const byte_t *
|
|
|
|
seckey_topublic(const SecretKey &sec)
|
|
|
|
{
|
|
|
|
return sec.data() + 32;
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
|
|
|
|
const byte_t *
|
2019-01-02 01:04:04 +00:00
|
|
|
pq_keypair_to_public(const PQKeyPair &k)
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2019-01-02 01:04:04 +00:00
|
|
|
return k.data() + PQ_SECRETKEYSIZE;
|
2018-06-10 14:05:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 23:22:31 +00:00
|
|
|
const byte_t *
|
2019-01-02 01:04:04 +00:00
|
|
|
pq_keypair_to_secret(const PQKeyPair &k)
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2019-01-02 01:04:04 +00:00
|
|
|
return k.data();
|
2018-08-13 23:22:31 +00:00
|
|
|
}
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-12-13 16:14:44 +00:00
|
|
|
uint64_t
|
|
|
|
randint()
|
|
|
|
{
|
|
|
|
uint64_t i;
|
|
|
|
randombytes((byte_t *)&i, sizeof(i));
|
|
|
|
return i;
|
|
|
|
}
|
2018-12-11 00:53:11 +00:00
|
|
|
|
|
|
|
} // namespace llarp
|