2024-09-16 14:11:01 +02:00
|
|
|
#ifndef KEY_H_
|
|
|
|
#define KEY_H_
|
|
|
|
|
|
|
|
#include <sodium.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#define TIME_SIZE sizeof(time_t)
|
|
|
|
#define SIGN_SIZE crypto_sign_BYTES
|
2024-09-20 18:04:16 +02:00
|
|
|
#define PK_RAW_SIZE crypto_kx_PUBLICKEYBYTES
|
|
|
|
#define SK_RAW_SIZE crypto_sign_SECRETKEYBYTES
|
2024-09-16 14:11:01 +02:00
|
|
|
#define METADATA_SIZE MAX_NAME + TIME_SIZE
|
2024-09-20 18:04:16 +02:00
|
|
|
#define PK_SIZE PK_RAW_SIZE + METADATA_SIZE + SIGN_SIZE
|
|
|
|
#define SK_SIZE SK_RAW_SIZE + METADATA_SIZE + SIGN_SIZE
|
|
|
|
#define SHARED_KEY_SIZE crypto_kx_SESSIONKEYBYTES
|
2024-09-16 14:11:01 +02:00
|
|
|
|
|
|
|
typedef struct public_key {
|
2024-09-20 18:04:16 +02:00
|
|
|
uint8_t raw[PK_RAW_SIZE];
|
2024-09-16 14:11:01 +02:00
|
|
|
uint8_t username[MAX_NAME];
|
|
|
|
time_t creation;
|
|
|
|
uint8_t signature[SIGN_SIZE];
|
2024-09-20 18:04:16 +02:00
|
|
|
uint8_t full[PK_SIZE];
|
2024-09-16 14:11:01 +02:00
|
|
|
} public_key;
|
|
|
|
|
|
|
|
typedef struct secret_key {
|
2024-09-20 18:04:16 +02:00
|
|
|
uint8_t raw[SK_RAW_SIZE];
|
2024-09-16 14:11:01 +02:00
|
|
|
uint8_t username[MAX_NAME];
|
|
|
|
time_t creation;
|
|
|
|
uint8_t signature[SIGN_SIZE];
|
2024-09-20 18:04:16 +02:00
|
|
|
uint8_t full[SK_SIZE];
|
2024-09-16 14:11:01 +02:00
|
|
|
} secret_key;
|
|
|
|
|
2024-09-20 18:04:16 +02:00
|
|
|
typedef struct keypair_t {
|
2024-09-16 14:11:01 +02:00
|
|
|
public_key pk;
|
|
|
|
secret_key sk;
|
2024-09-20 18:04:16 +02:00
|
|
|
} keypair_t;
|
2024-09-16 14:11:01 +02:00
|
|
|
|
2024-09-20 18:04:16 +02:00
|
|
|
keypair_t *create_keypair(char *username);
|
|
|
|
keypair_t *get_keypair(char *username);
|
2024-09-16 14:11:01 +02:00
|
|
|
|
|
|
|
#endif
|