You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/include/llarp/crypto.h

110 lines
2.9 KiB
C

7 years ago
#ifndef LLARP_CRYPTO_H_
#define LLARP_CRYPTO_H_
#include <llarp/buffer.h>
7 years ago
#include <llarp/common.h>
7 years ago
#include <stdbool.h>
7 years ago
#include <stdint.h>
6 years ago
/**
* crypto.h
*
* libsodium abstraction layer
* potentially allow libssl support in the future
*/
7 years ago
#define PUBKEYSIZE 32
7 years ago
#define SECKEYSIZE 64
#define NONCESIZE 24
7 years ago
#define SHAREDKEYSIZE 32
#define HASHSIZE 64
6 years ago
#define SHORTHASHSIZE 32
7 years ago
#define HMACSECSIZE 32
#define SIGSIZE 64
#define TUNNONCESIZE 32
#define HMACSIZE 32
#define PATHIDSIZE 16
7 years ago
/*
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];
*/
6 years ago
/// label functors
6 years ago
/// PKE(result, publickey, secretkey, nonce)
typedef bool (*llarp_path_dh_func)(byte_t *, byte_t *, byte_t *, byte_t *);
/// TKE(result, publickey, secretkey, nonce)
typedef bool (*llarp_transport_dh_func)(byte_t *, byte_t *, byte_t *, byte_t *);
6 years ago
6 years ago
/// SD/SE(buffer, key, nonce)
typedef bool (*llarp_sym_cipher_func)(llarp_buffer_t, const byte_t *,
const byte_t *);
7 years ago
6 years ago
/// H(result, body)
typedef bool (*llarp_hash_func)(byte_t *, llarp_buffer_t);
7 years ago
6 years ago
/// SH(result, body)
typedef bool (*llarp_shorthash_func)(byte_t *, llarp_buffer_t);
6 years ago
6 years ago
/// MDS(result, body, shared_secret)
typedef bool (*llarp_hmac_func)(byte_t *, llarp_buffer_t, const byte_t *);
7 years ago
6 years ago
/// S(sig, secretkey, body)
typedef bool (*llarp_sign_func)(byte_t *, const byte_t *, llarp_buffer_t);
7 years ago
6 years ago
/// V(sig, body, secretkey)
typedef bool (*llarp_verify_func)(const byte_t *, llarp_buffer_t,
const byte_t *);
7 years ago
6 years ago
/// library crypto configuration
struct llarp_crypto
{
6 years ago
/// xchacha symettric cipher
7 years ago
llarp_sym_cipher_func xchacha20;
6 years ago
/// path dh creator's side
llarp_path_dh_func dh_client;
6 years ago
/// path dh relay side
llarp_path_dh_func dh_server;
6 years ago
/// transport dh client side
6 years ago
llarp_transport_dh_func transport_dh_client;
6 years ago
/// transport dh server side
6 years ago
llarp_transport_dh_func transport_dh_server;
6 years ago
/// blake2b 512 bit
7 years ago
llarp_hash_func hash;
6 years ago
/// blake2b 256 bit
6 years ago
llarp_shorthash_func shorthash;
6 years ago
/// blake2s 256 bit hmac
7 years ago
llarp_hmac_func hmac;
6 years ago
/// ed25519 sign
7 years ago
llarp_sign_func sign;
6 years ago
/// ed25519 verify
7 years ago
llarp_verify_func verify;
6 years ago
/// randomize buffer
7 years ago
void (*randomize)(llarp_buffer_t);
6 years ago
/// randomizer memory
7 years ago
void (*randbytes)(void *, size_t);
6 years ago
/// generate signing keypair
void (*identity_keygen)(byte_t *);
6 years ago
/// generate encryption keypair
void (*encryption_keygen)(byte_t *);
7 years ago
};
7 years ago
6 years ago
/// set crypto function pointers to use libsodium
void
llarp_crypto_libsodium_init(struct llarp_crypto *c);
6 years ago
/// check for initialize crypto
bool
llarp_crypto_initialized(struct llarp_crypto *c);
7 years ago
#endif