lokinet/include/llarp/crypto_async.h

178 lines
4.2 KiB
C
Raw Normal View History

2018-01-31 19:59:26 +00:00
#ifndef LLARP_CRYPTO_ASYNC_H_
#define LLARP_CRYPTO_ASYNC_H_
#include <llarp/crypto.h>
#include <llarp/ev.h>
2018-05-18 20:08:57 +00:00
#include <llarp/logic.h>
#include <llarp/threadpool.h>
2018-01-31 19:59:26 +00:00
2018-05-25 09:17:08 +00:00
/**
* crypto_async.h
*
* asynchronous crypto functions
*/
2018-01-31 19:59:26 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2018-05-25 09:17:08 +00:00
/// defined in crypto_async.cpp
2018-05-18 20:08:57 +00:00
struct llarp_async_iwp;
2018-05-25 09:17:08 +00:00
/// allocator
struct llarp_async_iwp *
llarp_async_iwp_new(struct llarp_alloc *mem, struct llarp_crypto *crypto,
struct llarp_logic *logic, struct llarp_threadpool *worker);
2018-05-25 09:17:08 +00:00
/// deallocator
2018-05-22 19:19:06 +00:00
void
llarp_async_iwp_free(struct llarp_async_iwp *iwp);
2018-05-18 20:08:57 +00:00
struct iwp_async_keygen;
2018-05-25 09:17:08 +00:00
/// define functor for keygen
2018-05-18 20:08:57 +00:00
typedef void (*iwp_keygen_hook)(struct iwp_async_keygen *);
2018-05-25 09:17:08 +00:00
/// key generation request
2018-05-18 20:08:57 +00:00
struct iwp_async_keygen
{
2018-05-25 09:17:08 +00:00
/// internal wire protocol async configuration
struct llarp_async_iwp *iwp;
2018-05-25 09:17:08 +00:00
/// a customizable pointer to pass data to iteration functor
void *user;
2018-05-25 09:17:08 +00:00
/// destination key buffer
uint8_t *keybuf;
2018-05-25 09:17:08 +00:00
/// iteration functor
2018-05-18 20:08:57 +00:00
iwp_keygen_hook hook;
};
2018-05-25 09:17:08 +00:00
/// generate a key by iterating on "iwp" using "keygen" request
void
iwp_call_async_keygen(struct llarp_async_iwp *iwp,
struct iwp_async_keygen *keygen);
2018-05-18 20:08:57 +00:00
2018-05-19 13:36:42 +00:00
struct iwp_async_intro;
2018-05-25 09:17:08 +00:00
/// iwp_async_intro functor
2018-05-19 17:21:56 +00:00
typedef void (*iwp_intro_hook)(struct iwp_async_intro *);
2018-05-25 09:17:08 +00:00
/// iwp_async_intro request
2018-05-19 13:36:42 +00:00
struct iwp_async_intro
2018-05-18 20:08:57 +00:00
{
struct llarp_async_iwp *iwp;
void *user;
uint8_t *buf;
2018-05-18 20:08:57 +00:00
size_t sz;
2018-05-25 09:17:08 +00:00
/// nonce paramter
uint8_t *nonce;
2018-05-25 09:17:08 +00:00
/// remote public key
uint8_t *remote_pubkey;
2018-05-25 09:17:08 +00:00
/// local private key
uint8_t *secretkey;
2018-05-25 09:17:08 +00:00
/// callback
2018-05-19 17:21:56 +00:00
iwp_intro_hook hook;
2018-05-18 20:08:57 +00:00
};
2018-05-25 09:17:08 +00:00
/// introduce internal wire protocol "iwp" using "intro" request
void
iwp_call_async_gen_intro(struct llarp_async_iwp *iwp,
struct iwp_async_intro *intro);
2018-05-18 20:08:57 +00:00
2018-05-23 20:37:43 +00:00
void
iwp_call_async_verify_intro(struct llarp_async_iwp *iwp,
struct iwp_async_intro *info);
2018-05-19 13:36:42 +00:00
struct iwp_async_introack;
2018-05-25 09:17:08 +00:00
/// introduction acknowledgement functor
2018-05-19 17:21:56 +00:00
typedef void (*iwp_introack_hook)(struct iwp_async_introack *);
2018-05-25 09:17:08 +00:00
/// introduction acknowledgement request
2018-05-19 13:36:42 +00:00
struct iwp_async_introack
2018-05-18 20:08:57 +00:00
{
struct llarp_async_iwp *iwp;
void *user;
uint8_t *buf;
2018-05-18 20:08:57 +00:00
size_t sz;
2018-05-25 09:17:08 +00:00
/// nonce paramter
uint8_t *nonce;
2018-05-25 09:17:08 +00:00
/// token paramter
uint8_t *token;
2018-05-25 09:17:08 +00:00
/// remote public key
uint8_t *remote_pubkey;
2018-05-25 09:17:08 +00:00
/// local private key
uint8_t *secretkey;
2018-05-25 09:17:08 +00:00
/// callback
2018-05-19 17:21:56 +00:00
iwp_introack_hook hook;
2018-05-18 20:08:57 +00:00
};
2018-05-25 09:17:08 +00:00
/// generate introduction acknowledgement "iwp" using "introack" request
void
iwp_call_async_gen_introack(struct llarp_async_iwp *iwp,
struct iwp_async_introack *introack);
2018-05-18 20:08:57 +00:00
2018-05-25 09:17:08 +00:00
/// verify introduction acknowledgement "iwp" using "introack" request
void
iwp_call_async_verify_introack(struct llarp_async_iwp *iwp,
struct iwp_async_introack *introack);
2018-05-19 17:21:56 +00:00
struct iwp_async_session_start;
2018-05-25 09:17:08 +00:00
/// start session functor
2018-05-19 17:21:56 +00:00
typedef void (*iwp_session_start_hook)(struct iwp_async_session_start *);
2018-05-25 09:17:08 +00:00
/// start session request
2018-05-19 17:21:56 +00:00
struct iwp_async_session_start
2018-05-19 13:36:42 +00:00
{
struct llarp_async_iwp *iwp;
void *user;
uint8_t *buf;
2018-05-19 13:36:42 +00:00
size_t sz;
uint8_t *nonce;
uint8_t *token;
uint8_t *sessionkey;
uint8_t *secretkey;
uint8_t *remote_pubkey;
2018-05-19 17:21:56 +00:00
iwp_session_start_hook hook;
2018-05-19 13:36:42 +00:00
};
2018-05-19 17:21:56 +00:00
2018-05-25 09:17:08 +00:00
/// generate session start "iwp" using "start" request
void
iwp_call_async_gen_session_start(struct llarp_async_iwp *iwp,
struct iwp_async_session_start *start);
2018-05-19 17:21:56 +00:00
2018-05-25 09:17:08 +00:00
/// verify session start "iwp" using "start" request
void
iwp_call_async_verify_session_start(struct llarp_async_iwp *iwp,
struct iwp_async_session_start *start);
2018-05-19 17:21:56 +00:00
struct iwp_async_frame;
2018-05-25 09:17:08 +00:00
/// internal wire protocol frame request
typedef void (*iwp_async_frame_hook)(struct iwp_async_frame *);
2018-05-19 17:21:56 +00:00
struct iwp_async_frame
{
bool success;
struct llarp_async_iwp *iwp;
void *user;
uint8_t *sessionkey;
2018-05-19 17:21:56 +00:00
size_t sz;
iwp_async_frame_hook hook;
uint8_t buf[1500];
};
2018-05-25 09:17:08 +00:00
/// decrypt iwp frame "iwp" using "frame" request
void
iwp_call_async_frame_decrypt(struct llarp_async_iwp *iwp,
struct iwp_async_frame *frame);
2018-05-19 17:21:56 +00:00
2018-05-25 09:17:08 +00:00
/// encrypt iwp frame "iwp" using "frame" request
void
iwp_call_async_frame_encrypt(struct llarp_async_iwp *iwp,
struct iwp_async_frame *frame);
2018-05-19 17:21:56 +00:00
2018-01-31 19:59:26 +00:00
#ifdef __cplusplus
}
#endif
#endif