105 lines
1.9 KiB
C
105 lines
1.9 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);
|
|
|
|
|
|
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_ecp_group ecpGrp;
|
|
// mbedtls_ecp_group_init(&ecpGrp);
|
|
// mbedtls_ecp_group_load(&ecpGrp, ECC_CURVE);
|
|
|
|
// mbedtls_mpi secret;
|
|
// mbedtls_mpi_init(&secret);
|
|
|
|
// mbedtls_ecp_point Public;
|
|
// mbedtls_ecp_point_init(&Public);
|
|
|
|
// mbedtls_entropy_context entropyCtx;
|
|
// mbedtls_entropy_init(&entropyCtx);
|
|
|
|
// mbedtls_ctr_drbg_context drbgCtx;
|
|
// mbedtls_ctr_drbg_init(&drbgCtx);
|
|
|
|
// int ret = mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, &entropyCtx,
|
|
// (const unsigned char *) "Private", sizeof("Private"));
|
|
|
|
// ret = mbedtls_ecp_gen_keypair(&ecpGrp, &secret, &Public,
|
|
// mbedtls_ctr_drbg_random, &drbgCtx);
|
|
|
|
|
|
mbedtls_mpi secret;
|
|
mbedtls_mpi_init(&secret);
|
|
|
|
mbedtls_ecp_point Public;
|
|
mbedtls_ecp_point_init(&Public);
|
|
|
|
deriveECCKeyPair(&secret, &Public);b
|
|
|
|
return;
|
|
}
|
|
|
|
else
|
|
{
|
|
|
|
printf("RSA is not yet implemented\n");
|
|
return;
|
|
}
|
|
|
|
|
|
} |