2018-01-25 16:24:33 +00:00
|
|
|
#ifndef LLARP_CRYPTO_H_
|
|
|
|
#define LLARP_CRYPTO_H_
|
|
|
|
#include <llarp/buffer.h>
|
2018-04-05 14:43:16 +00:00
|
|
|
#include <llarp/common.h>
|
2018-01-25 16:24:33 +00:00
|
|
|
#include <stdbool.h>
|
2018-01-29 14:27:24 +00:00
|
|
|
#include <stdint.h>
|
2018-01-25 16:24:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PUBKEYSIZE 32
|
2018-02-01 22:04:58 +00:00
|
|
|
#define SECKEYSIZE 64
|
2018-05-22 15:54:19 +00:00
|
|
|
#define NONCESIZE 24
|
2018-01-25 16:24:33 +00:00
|
|
|
#define SHAREDKEYSIZE 32
|
|
|
|
#define HASHSIZE 64
|
2018-05-18 16:08:47 +00:00
|
|
|
#define SHORTHASHSIZE 32
|
2018-01-25 16:24:33 +00:00
|
|
|
#define HMACSECSIZE 32
|
|
|
|
#define SIGSIZE 64
|
2018-05-22 15:54:19 +00:00
|
|
|
#define TUNNONCESIZE 32
|
2018-05-20 13:43:42 +00:00
|
|
|
#define HMACSIZE 32
|
2018-01-25 16:24:33 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
typedef byte_t llarp_pubkey_t[PUBKEYSIZE];
|
|
|
|
typedef byte_t llarp_seckey_t[SECKEYSIZE];
|
|
|
|
typedef byte_t llarp_nonce_t[NONCESIZE];
|
|
|
|
typedef byte_t llarp_sharedkey_t[SHAREDKEYSIZE];
|
|
|
|
typedef byte_t llarp_hash_t[HASHSIZE];
|
|
|
|
typedef byte_t llarp_shorthash_t[SHORTHASHSIZE];
|
|
|
|
typedef byte_t llarp_hmac_t[HMACSIZE];
|
|
|
|
typedef byte_t llarp_hmacsec_t[HMACSECSIZE];
|
|
|
|
typedef byte_t llarp_sig_t[SIGSIZE];
|
|
|
|
typedef byte_t llarp_tunnel_nonce_t[TUNNONCESIZE];
|
|
|
|
|
|
|
|
byte_t *
|
|
|
|
llarp_seckey_topublic(byte_t *secret);
|
2018-02-01 22:34:04 +00:00
|
|
|
|
2018-02-01 13:21:00 +00:00
|
|
|
typedef bool (*llarp_dh_func)(llarp_sharedkey_t *, llarp_pubkey_t,
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_tunnel_nonce_t, llarp_seckey_t);
|
|
|
|
|
|
|
|
typedef bool (*llarp_transport_dh_func)(byte_t *, byte_t *, byte_t *, byte_t *);
|
2018-05-18 16:08:47 +00:00
|
|
|
|
2018-02-01 22:34:04 +00:00
|
|
|
typedef bool (*llarp_sym_cipher_func)(llarp_buffer_t, llarp_sharedkey_t,
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_nonce_t);
|
2018-02-01 22:04:58 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
typedef bool (*llarp_hash_func)(byte_t *, llarp_buffer_t);
|
2018-02-01 22:04:58 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
typedef bool (*llarp_shorthash_func)(byte_t *, llarp_buffer_t);
|
2018-05-18 16:08:47 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
typedef bool (*llarp_hmac_func)(byte_t *, llarp_buffer_t, const byte_t *);
|
2018-02-01 22:34:04 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
typedef bool (*llarp_sign_func)(byte_t *, const byte_t *, llarp_buffer_t);
|
2018-01-31 19:59:26 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
typedef bool (*llarp_verify_func)(const byte_t *, llarp_buffer_t,
|
|
|
|
const byte_t *);
|
2018-02-01 22:34:04 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_crypto
|
|
|
|
{
|
2018-02-01 22:04:58 +00:00
|
|
|
llarp_sym_cipher_func xchacha20;
|
2018-01-31 19:59:26 +00:00
|
|
|
llarp_dh_func dh_client;
|
|
|
|
llarp_dh_func dh_server;
|
2018-05-18 16:08:47 +00:00
|
|
|
llarp_transport_dh_func transport_dh_client;
|
|
|
|
llarp_transport_dh_func transport_dh_server;
|
2018-02-01 22:04:58 +00:00
|
|
|
llarp_hash_func hash;
|
2018-05-18 16:08:47 +00:00
|
|
|
llarp_shorthash_func shorthash;
|
2018-02-01 22:04:58 +00:00
|
|
|
llarp_hmac_func hmac;
|
|
|
|
llarp_sign_func sign;
|
|
|
|
llarp_verify_func verify;
|
2018-01-31 19:59:26 +00:00
|
|
|
void (*randomize)(llarp_buffer_t);
|
2018-02-01 22:04:58 +00:00
|
|
|
void (*randbytes)(void *, size_t);
|
2018-05-22 15:54:19 +00:00
|
|
|
void (*keygen)(byte_t *);
|
2018-01-29 14:27:24 +00:00
|
|
|
};
|
2018-01-25 16:24:33 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_crypto_libsodium_init(struct llarp_crypto *c);
|
|
|
|
|
|
|
|
bool
|
|
|
|
llarp_crypto_initialized(struct llarp_crypto *c);
|
2018-01-25 16:24:33 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-01-25 16:24:33 +00:00
|
|
|
#endif
|