|
|
@ -15,10 +15,15 @@
|
|
|
|
extern "C" {
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// context for doing asynchronous crpytography for iwp
|
|
|
|
|
|
|
|
/// with a worker threadpool
|
|
|
|
/// defined in crypto_async.cpp
|
|
|
|
/// defined in crypto_async.cpp
|
|
|
|
struct llarp_async_iwp;
|
|
|
|
struct llarp_async_iwp;
|
|
|
|
|
|
|
|
|
|
|
|
/// allocator
|
|
|
|
/// allocator
|
|
|
|
|
|
|
|
/// use crypto as cryptograph implementation
|
|
|
|
|
|
|
|
/// use logic as the callback handler thread
|
|
|
|
|
|
|
|
/// use worker as threadpool that does the heavy lifting
|
|
|
|
struct llarp_async_iwp *
|
|
|
|
struct llarp_async_iwp *
|
|
|
|
llarp_async_iwp_new(struct llarp_crypto *crypto, struct llarp_logic *logic,
|
|
|
|
llarp_async_iwp_new(struct llarp_crypto *crypto, struct llarp_logic *logic,
|
|
|
|
struct llarp_threadpool *worker);
|
|
|
|
struct llarp_threadpool *worker);
|
|
|
@ -41,11 +46,11 @@ struct iwp_async_keygen
|
|
|
|
void *user;
|
|
|
|
void *user;
|
|
|
|
/// destination key buffer
|
|
|
|
/// destination key buffer
|
|
|
|
uint8_t *keybuf;
|
|
|
|
uint8_t *keybuf;
|
|
|
|
/// iteration functor
|
|
|
|
/// result handler callback
|
|
|
|
iwp_keygen_hook hook;
|
|
|
|
iwp_keygen_hook hook;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// generate a key by iterating on "iwp" using "keygen" request
|
|
|
|
/// generate an encryption keypair asynchronously
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_keygen(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_keygen(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_keygen *keygen);
|
|
|
|
struct iwp_async_keygen *keygen);
|
|
|
@ -72,11 +77,12 @@ struct iwp_async_intro
|
|
|
|
iwp_intro_hook hook;
|
|
|
|
iwp_intro_hook hook;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// introduce internal wire protocol "iwp" using "intro" request
|
|
|
|
/// asynchronously generate an intro packet
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_gen_intro(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_gen_intro(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_intro *intro);
|
|
|
|
struct iwp_async_intro *intro);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// asynchronously verify an intro packet
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_verify_intro(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_verify_intro(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_intro *info);
|
|
|
|
struct iwp_async_intro *info);
|
|
|
@ -105,12 +111,12 @@ struct iwp_async_introack
|
|
|
|
iwp_introack_hook hook;
|
|
|
|
iwp_introack_hook hook;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// generate introduction acknowledgement "iwp" using "introack" request
|
|
|
|
/// generate introduction acknowledgement packet asynchronously
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_gen_introack(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_gen_introack(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_introack *introack);
|
|
|
|
struct iwp_async_introack *introack);
|
|
|
|
|
|
|
|
|
|
|
|
/// verify introduction acknowledgement "iwp" using "introack" request
|
|
|
|
/// verify introduction acknowledgement packet asynchronously
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_verify_introack(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_verify_introack(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_introack *introack);
|
|
|
|
struct iwp_async_introack *introack);
|
|
|
@ -127,20 +133,26 @@ struct iwp_async_session_start
|
|
|
|
void *user;
|
|
|
|
void *user;
|
|
|
|
uint8_t *buf;
|
|
|
|
uint8_t *buf;
|
|
|
|
size_t sz;
|
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
/// nonce parameter
|
|
|
|
uint8_t *nonce;
|
|
|
|
uint8_t *nonce;
|
|
|
|
|
|
|
|
/// token parameter
|
|
|
|
uint8_t *token;
|
|
|
|
uint8_t *token;
|
|
|
|
|
|
|
|
/// memory to write session key to
|
|
|
|
uint8_t *sessionkey;
|
|
|
|
uint8_t *sessionkey;
|
|
|
|
|
|
|
|
/// local secrkey key
|
|
|
|
uint8_t *secretkey;
|
|
|
|
uint8_t *secretkey;
|
|
|
|
|
|
|
|
/// remote public encryption key
|
|
|
|
uint8_t *remote_pubkey;
|
|
|
|
uint8_t *remote_pubkey;
|
|
|
|
|
|
|
|
/// result callback handler
|
|
|
|
iwp_session_start_hook hook;
|
|
|
|
iwp_session_start_hook hook;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// generate session start "iwp" using "start" request
|
|
|
|
/// generate session start packet asynchronously
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_gen_session_start(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_gen_session_start(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_session_start *start);
|
|
|
|
struct iwp_async_session_start *start);
|
|
|
|
|
|
|
|
|
|
|
|
/// verify session start "iwp" using "start" request
|
|
|
|
/// verify session start packet asynchronously
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_verify_session_start(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_verify_session_start(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_session_start *start);
|
|
|
|
struct iwp_async_session_start *start);
|
|
|
@ -152,21 +164,26 @@ typedef void (*iwp_async_frame_hook)(struct iwp_async_frame *);
|
|
|
|
|
|
|
|
|
|
|
|
struct iwp_async_frame
|
|
|
|
struct iwp_async_frame
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// true if decryption succeded
|
|
|
|
bool success;
|
|
|
|
bool success;
|
|
|
|
struct llarp_async_iwp *iwp;
|
|
|
|
struct llarp_async_iwp *iwp;
|
|
|
|
void *user;
|
|
|
|
void *user;
|
|
|
|
|
|
|
|
/// current session key
|
|
|
|
uint8_t *sessionkey;
|
|
|
|
uint8_t *sessionkey;
|
|
|
|
|
|
|
|
/// size of the frame
|
|
|
|
size_t sz;
|
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
/// result handler
|
|
|
|
iwp_async_frame_hook hook;
|
|
|
|
iwp_async_frame_hook hook;
|
|
|
|
|
|
|
|
/// memory holding the entire frame
|
|
|
|
uint8_t buf[1500];
|
|
|
|
uint8_t buf[1500];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// decrypt iwp frame "iwp" using "frame" request
|
|
|
|
/// decrypt iwp frame asynchronously
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_frame_decrypt(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_frame_decrypt(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_frame *frame);
|
|
|
|
struct iwp_async_frame *frame);
|
|
|
|
|
|
|
|
|
|
|
|
/// encrypt iwp frame "iwp" using "frame" request
|
|
|
|
/// encrypt iwp frame asynchronously
|
|
|
|
void
|
|
|
|
void
|
|
|
|
iwp_call_async_frame_encrypt(struct llarp_async_iwp *iwp,
|
|
|
|
iwp_call_async_frame_encrypt(struct llarp_async_iwp *iwp,
|
|
|
|
struct iwp_async_frame *frame);
|
|
|
|
struct iwp_async_frame *frame);
|
|
|
|