DIMA/ch-resp-self/Stage2.h
2021-02-09 11:06:40 +01:00

116 lines
2.5 KiB
C

#ifndef STAGE2_HEADERS_SEEN
//check header file for re-def conflicts
#define STAGE2_HEADERS_SEEN
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mbedtls/config.h"
#include "mbedtls/aes.h"
#include "mbedtls/bignum.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ecp.h"
#include "mbedtls/ecdh.h"
#include "mbedtls/ecdsa.h"
#include "mbedtls/hmac_drbg.h"
#include "mbedtls/hkdf.h"
#include "mbedtls/md.h"
#include "mbedtls/pk.h"
#include "mbedtls/rsa.h"
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include "mbedtls/net_sockets.h"
#include "defines.h"
#define SERVER_PORT "11999"
#define PLAINTEXT "==Hello there!=="
#define SERVER_ID "0001"
#define CLIENT_ID "0002"
////////typedefs
typedef struct
{
/*
Use this struct to load, store and update client info on server side
or both ways if mutual attestation is possible
*/
const char * cli_ID;
const char * pub_file;
mbedtls_ecp_point * pub_key;
int Cli_STATUS;
int Cli_CAP;
const uint8_t * NONCE;
mbedtls_net_context * cli_fd;
} Client_info;
typedef struct
{
/*
Use this struct to load, store and update info about server on client
*/
const char * ser_ID;
const char * pub_file;
mbedtls_ecp_point * pub_key;
mbedtls_net_context * ser_fd;
} Server_info;
typedef struct
{
//Use this struct to maintain uniformity between client and sever
const char * cli_ID;
const uint8_t * NONCE;
const uint8_t * sign;
const size_t sig_len;
} Chall_context;
typedef struct
{
//Use this struct to maintain uniformity between client and sever
const char * cli_ID;
const uint8_t * NONCE;
const uint8_t * sign;
const size_t sig_len;
} Resp_context;
///////////functions
DIMASTATUS load_nodes(Client_info * Cl_list);
DIMASTATUS genNONCE( Client_info * Cl_ctx);
DIMASTATUS challengeCl( mbedtls_pk_context * pk_ctx, Client_info * Cl_ctx, uint8_t *sign, size_t *signlen);
//DIMASTATUS challengeCTX( mbedtls_pk_context * pk_ctx, Client_info * Cl_ctx, Chall_context * ch_ctx);
DIMASTATUS verifyCl( mbedtls_pk_context * pk_ctx, Client_info * Cl_ctx, uint8_t *sign, size_t signlen);
//DIMASTATUS responseCTX( mbedtls_pk_context * pk_ctx, Client_info * Cl_ctx, Resp_context * resp_ctx);
DIMASTATUS responSer( mbedtls_pk_context * pk_ctx, Resp_context * Res_ctx, uint8_t *sign, size_t *signlen);
DIMASTATUS IIStepSend(unsigned char * outBuff, mbedtls_net_context * net_fd);
DIMASTATUS IIStepRecv(unsigned char * inBuff, mbedtls_net_context * net_fd);
#endif