#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"




////////typedefs


typedef struct 
{
	/*
	Use this struct to load, store and update client info on server side
	or both ways if mutual attestation is possible
	*/
	unsigned char*			ID;
	uint8_t *				status;
	char *					pubKey_file;
	mbedtls_pk_context *	pub_key;
	mbedtls_pk_context *	priv_key;
	mbedtls_net_context *	fd;
	unsigned char*			NONCE;	
	//int 					Cli_CAP;
} Node_info;


typedef struct 
{
	/*
	Use this struct to load, store and update info about server on client
	*/
	char *			ser_ID;
	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
	unsigned char				NONCE[NONCE_SIZE];
	size_t 						siglen;
	unsigned char				sign[SIGN_SIZE];
} Chall_context;


typedef struct 
{
	//Use this struct to maintain uniformity between client and sever
	unsigned char				ID[NODE_ID_SIZE];
	size_t 						siglen;
	unsigned char				sign[SIGN_SIZE];
	
} Resp_context;


///////////functions


//MASTER

DIMASTATUS load_nodes(Node_info * nodelist);
DIMASTATUS challenge_client(Node_info * Client);
DIMASTATUS verify_client(Node_info * client, Resp_context * Rp);



//SLAVE
DIMASTATUS verify_master(Node_info * Server, Chall_context * Ch);
DIMASTATUS response_master(Node_info * Server, Resp_context  * Rp, unsigned char * NONCE);



#endif	