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_async.h

178 lines
4.2 KiB
C

7 years ago
#ifndef LLARP_CRYPTO_ASYNC_H_
#define LLARP_CRYPTO_ASYNC_H_
#include <llarp/crypto.h>
#include <llarp/ev.h>
#include <llarp/logic.h>
#include <llarp/threadpool.h>
7 years ago
6 years ago
/**
* crypto_async.h
*
* asynchronous crypto functions
*/
7 years ago
#ifdef __cplusplus
extern "C" {
#endif
6 years ago
/// defined in crypto_async.cpp
struct llarp_async_iwp;
6 years ago
/// allocator
struct llarp_async_iwp *
llarp_async_iwp_new(struct llarp_crypto *crypto, struct llarp_logic *logic,
struct llarp_threadpool *worker);
6 years ago
/// deallocator
6 years ago
void
llarp_async_iwp_free(struct llarp_async_iwp *iwp);
struct iwp_async_keygen;
6 years ago
/// define functor for keygen
typedef void (*iwp_keygen_hook)(struct iwp_async_keygen *);
6 years ago
/// key generation request
struct iwp_async_keygen
{
6 years ago
/// internal wire protocol async configuration
struct llarp_async_iwp *iwp;
6 years ago
/// a customizable pointer to pass data to iteration functor
void *user;
6 years ago
/// destination key buffer
uint8_t *keybuf;
6 years ago
/// iteration functor
iwp_keygen_hook hook;
};
6 years ago
/// 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);
struct iwp_async_intro;
6 years ago
/// iwp_async_intro functor
6 years ago
typedef void (*iwp_intro_hook)(struct iwp_async_intro *);
6 years ago
/// iwp_async_intro request
struct iwp_async_intro
{
struct llarp_async_iwp *iwp;
void *user;
uint8_t *buf;
size_t sz;
6 years ago
/// nonce paramter
uint8_t *nonce;
6 years ago
/// remote public key
uint8_t *remote_pubkey;
6 years ago
/// local private key
uint8_t *secretkey;
6 years ago
/// callback
6 years ago
iwp_intro_hook hook;
};
6 years ago
/// introduce internal wire protocol "iwp" using "intro" request
void
iwp_call_async_gen_intro(struct llarp_async_iwp *iwp,
struct iwp_async_intro *intro);
void
iwp_call_async_verify_intro(struct llarp_async_iwp *iwp,
struct iwp_async_intro *info);
struct iwp_async_introack;
6 years ago
/// introduction acknowledgement functor
6 years ago
typedef void (*iwp_introack_hook)(struct iwp_async_introack *);
6 years ago
/// introduction acknowledgement request
struct iwp_async_introack
{
struct llarp_async_iwp *iwp;
void *user;
uint8_t *buf;
size_t sz;
6 years ago
/// nonce paramter
uint8_t *nonce;
6 years ago
/// token paramter
uint8_t *token;
6 years ago
/// remote public key
uint8_t *remote_pubkey;
6 years ago
/// local private key
uint8_t *secretkey;
6 years ago
/// callback
6 years ago
iwp_introack_hook hook;
};
6 years ago
/// generate introduction acknowledgement "iwp" using "introack" request
void
iwp_call_async_gen_introack(struct llarp_async_iwp *iwp,
struct iwp_async_introack *introack);
6 years ago
/// verify introduction acknowledgement "iwp" using "introack" request
void
iwp_call_async_verify_introack(struct llarp_async_iwp *iwp,
struct iwp_async_introack *introack);
6 years ago
struct iwp_async_session_start;
6 years ago
/// start session functor
6 years ago
typedef void (*iwp_session_start_hook)(struct iwp_async_session_start *);
6 years ago
/// start session request
6 years ago
struct iwp_async_session_start
{
struct llarp_async_iwp *iwp;
void *user;
uint8_t *buf;
size_t sz;
uint8_t *nonce;
uint8_t *token;
uint8_t *sessionkey;
uint8_t *secretkey;
uint8_t *remote_pubkey;
6 years ago
iwp_session_start_hook hook;
};
6 years ago
6 years ago
/// 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);
6 years ago
6 years ago
/// 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);
6 years ago
struct iwp_async_frame;
6 years ago
/// internal wire protocol frame request
typedef void (*iwp_async_frame_hook)(struct iwp_async_frame *);
6 years ago
struct iwp_async_frame
{
bool success;
struct llarp_async_iwp *iwp;
void *user;
uint8_t *sessionkey;
6 years ago
size_t sz;
iwp_async_frame_hook hook;
uint8_t buf[1500];
};
6 years ago
/// decrypt iwp frame "iwp" using "frame" request
void
iwp_call_async_frame_decrypt(struct llarp_async_iwp *iwp,
struct iwp_async_frame *frame);
6 years ago
6 years ago
/// encrypt iwp frame "iwp" using "frame" request
void
iwp_call_async_frame_encrypt(struct llarp_async_iwp *iwp,
struct iwp_async_frame *frame);
6 years ago
7 years ago
#ifdef __cplusplus
}
#endif
#endif