lokinet/include/llarp/crypto.h

83 lines
2.3 KiB
C
Raw Normal View History

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-01-25 16:24:33 +00:00
#define NOUNCESIZE 24
#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
#define TUNNOUNCESIZE 32
2018-02-01 22:04:58 +00:00
#define HMACSIZE 64
2018-01-25 16:24:33 +00:00
2018-01-29 14:27:24 +00:00
typedef uint8_t llarp_pubkey_t[PUBKEYSIZE];
typedef uint8_t llarp_seckey_t[SECKEYSIZE];
typedef uint8_t llarp_nounce_t[NOUNCESIZE];
typedef uint8_t llarp_sharedkey_t[SHAREDKEYSIZE];
typedef uint8_t llarp_hash_t[HASHSIZE];
2018-05-18 16:08:47 +00:00
typedef uint8_t llarp_shorthash_t[SHORTHASHSIZE];
2018-02-01 22:04:58 +00:00
typedef uint8_t llarp_hmac_t[HMACSIZE];
2018-01-29 14:27:24 +00:00
typedef uint8_t llarp_hmacsec_t[HMACSECSIZE];
typedef uint8_t llarp_sig_t[SIGSIZE];
typedef uint8_t llarp_tunnel_nounce_t[TUNNOUNCESIZE];
2018-01-25 16:24:33 +00:00
2018-04-04 16:10:27 +00:00
static INLINE uint8_t *llarp_seckey_topublic(llarp_seckey_t k) {
2018-02-01 22:04:58 +00:00
return k + 32;
}
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,
llarp_tunnel_nounce_t, llarp_seckey_t);
2018-05-18 16:08:47 +00:00
typedef bool (*llarp_transport_dh_func)(llarp_sharedkey_t *, llarp_pubkey_t,
llarp_seckey_t, uint8_t *);
2018-02-01 22:34:04 +00:00
typedef bool (*llarp_sym_cipher_func)(llarp_buffer_t, llarp_sharedkey_t,
llarp_nounce_t);
2018-02-01 22:04:58 +00:00
typedef bool (*llarp_hash_func)(llarp_hash_t *, llarp_buffer_t);
2018-05-18 16:08:47 +00:00
typedef bool (*llarp_shorthash_func)(llarp_shorthash_t *, llarp_buffer_t);
2018-02-01 22:34:04 +00:00
typedef bool (*llarp_hmac_func)(llarp_hmac_t *, llarp_buffer_t,
llarp_hmacsec_t);
2018-05-18 16:08:47 +00:00
typedef bool (*llarp_sign_func)(uint8_t *, llarp_seckey_t, llarp_buffer_t);
2018-01-31 19:59:26 +00:00
2018-02-01 22:04:58 +00:00
typedef bool (*llarp_verify_func)(llarp_pubkey_t, llarp_buffer_t, llarp_sig_t);
2018-02-01 22:34:04 +00:00
2018-01-29 14:27:24 +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);
void (*keygen)(llarp_seckey_t *);
2018-01-29 14:27:24 +00:00
};
2018-01-25 16:24:33 +00:00
2018-01-29 14:27:24 +00:00
void llarp_crypto_libsodium_init(struct llarp_crypto *c);
2018-01-25 16:24:33 +00:00
2018-05-18 16:08:47 +00:00
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