2024-03-22 03:24:01 +04:00
|
|
|
#ifndef _CRYPT_H_
|
|
|
|
#define _CRYPT_H_
|
2024-03-21 17:50:55 +04:00
|
|
|
|
2024-03-22 04:16:43 +04:00
|
|
|
#include <stdio.h>
|
2024-03-21 17:50:55 +04:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <sodium.h>
|
|
|
|
|
2024-03-22 04:16:43 +04:00
|
|
|
#define CRYPT_PUBKEY_HEXSIZE (crypto_kx_PUBLICKEYBYTES + crypto_sign_PUBLICKEYBYTES) * 2
|
|
|
|
#define CRYPT_SECKEY_HEXSIZE (crypto_kx_SECRETKEYBYTES + crypto_sign_SECRETKEYBYTES) * 2
|
2024-03-21 17:50:55 +04:00
|
|
|
|
|
|
|
typedef struct crypt_key_t {
|
2024-03-22 03:32:40 +04:00
|
|
|
unsigned char kx_pub[crypto_kx_PUBLICKEYBYTES];
|
|
|
|
unsigned char kx_sec[crypto_kx_SECRETKEYBYTES];
|
|
|
|
unsigned char sign_pub[crypto_sign_PUBLICKEYBYTES];
|
|
|
|
unsigned char sign_sec[crypto_sign_SECRETKEYBYTES];
|
2024-03-21 17:50:55 +04:00
|
|
|
bool hasSecKey;
|
|
|
|
} crypt_key_t;
|
|
|
|
|
|
|
|
int crypt_key_gen(crypt_key_t *k);
|
|
|
|
int crypt_key_from_hex(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE], char shex[CRYPT_SECKEY_HEXSIZE]);
|
|
|
|
int crypt_key_from_hex_public(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE]);
|
|
|
|
|
|
|
|
void crypt_key_export_public(crypt_key_t *k, char hex[CRYPT_PUBKEY_HEXSIZE]);
|
|
|
|
void crypt_key_export_secret(crypt_key_t *k, char hex[CRYPT_SECKEY_HEXSIZE]);
|
|
|
|
|
2024-03-22 04:16:43 +04:00
|
|
|
void crypt_store_public_key(crypt_key_t *k, FILE *out_file);
|
|
|
|
void crypt_store_secret_key(crypt_key_t *k, FILE *out_file);
|
|
|
|
|
2024-03-21 17:50:55 +04:00
|
|
|
typedef struct crypt_session_t {
|
|
|
|
unsigned char rx[crypto_kx_SESSIONKEYBYTES];
|
|
|
|
unsigned char tx[crypto_kx_SESSIONKEYBYTES];
|
2024-03-22 03:32:40 +04:00
|
|
|
crypt_key_t *remote_key;
|
2024-03-21 17:50:55 +04:00
|
|
|
} crypt_session_t;
|
|
|
|
|
2024-03-22 03:32:40 +04:00
|
|
|
int crypt_session_init(crypt_session_t *s, crypt_key_t *own, crypt_key_t *remote, bool is_client);
|
2024-03-21 17:50:55 +04:00
|
|
|
|
2024-03-22 03:24:01 +04:00
|
|
|
#endif /* _CRYPT_H_ */
|