DIMA/trial3/layer2.c
2020-07-28 11:53:26 +02:00

82 lines
1.2 KiB
C

#include "layer2.h"
//RIOT core
void ROMprotocol(void)
{
printf("Hello function!\n");
//readUDS function
uint8_t * CDIKEY = calloc(1, sizeof(uint8_t)*CDI_KEY_SIZE);
_calcCDIKEY(CDIKEY);
for(int i = 0; i < CDI_KEY_SIZE; i++)
printf("%x",CDIKEY[i]);
printf(" : CDIKEY main\n");
printf("USE_ECC %d\n", USE_ECC);
deriveDeviceIDKeyPair(CDIKEY, USE_ECC);
deriveDeviceIDKeyPair(CDIKEY, !USE_ECC);
printf("pass 100\n");
return;
}
void seedRNGSource(uint8_t * CDIKEY)
{
//srand(); lib fun call //https://stackoverflow.com/questions/55927662/generate-every-time-same-rsa-key-with-c
//ctr_drbg //programs/test/benchmark.c:705
//hmac_drbg
//seed rng with CDIKEY
//init
//drbg seed
return;
}
void deriveDeviceIDKeyPair(uint8_t * CDIKEY, int isECC)
{
//firt generate ECC/RA key.
//check for deterministic consistency
//seed RNGs with CDI
//let's see how it goes
//add entropy source?
//seed RNG
//create ctx
//init
//gen keypair
if(isECC)
{
mbedtls_mpi secret;
mbedtls_mpi_init(&secret);
mbedtls_ecp_point Public;
mbedtls_ecp_point_init(&Public);
deriveECCKeyPair(&secret, &Public);
return;
}
else
{
deriveRSAKeyPair();
return;
}
}