move key derivatin to layer1
This commit is contained in:
parent
6cd9bed88d
commit
4214e472f9
@ -181,3 +181,48 @@ int _calcCDIKEY(uint8_t * CDIKEY)
|
||||
|
||||
return RIOTSUCCESS;
|
||||
}
|
||||
|
||||
int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK)
|
||||
{
|
||||
|
||||
printf("inside deriveECCKeyPair layer1\n\n");
|
||||
|
||||
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);
|
||||
|
||||
//Seed drbg with secret data now?
|
||||
|
||||
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_ecp_copy(PK, &Public);
|
||||
mbedtls_mpi_copy(SK, &secret);
|
||||
|
||||
mbedtls_mpi_free(&secret);
|
||||
mbedtls_ecp_point_free(&Public);
|
||||
mbedtls_ecp_group_free(&ecpGrp);
|
||||
mbedtls_entropy_free(&entropyCtx);
|
||||
mbedtls_ctr_drbg_free(&drbgCtx);
|
||||
|
||||
printf("leaving deriveECCKeyPair layer1\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int deriveRSAKeyPair(void){return 0;}
|
@ -1,11 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#include <mbedtls/hkdf.h>
|
||||
#include <mbedtls/bignum.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/hmac_drbg.h>
|
||||
#include <mbedtls/ecp.h>
|
||||
#include <mbedtls/ecdh.h>
|
||||
#include <mbedtls/ecdsa.h>
|
||||
#include <mbedtls/hkdf.h>
|
||||
#include <mbedtls/md.h>
|
||||
#include <mbedtls/aes.h>
|
||||
#include <mbedtls/sha1.h>
|
||||
#include <mbedtls/sha256.h>
|
||||
|
||||
@ -18,3 +23,5 @@ int readUDS(uint8_t* UDSdigest);
|
||||
int readFWID(uint8_t * FW_M);
|
||||
int _calcCDID(uint8_t * CDID);
|
||||
int _calcCDIKEY(uint8_t * CDIKEY);
|
||||
int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK);
|
||||
int deriveRSAKeyPair(void);
|
@ -60,9 +60,28 @@ void deriveDeviceIDKeyPair(uint8_t * CDIKEY, int isECC)
|
||||
{
|
||||
|
||||
|
||||
mbedtls_ecp_group ecpGrp;
|
||||
mbedtls_ecp_group_init(&ecpGrp);
|
||||
mbedtls_ecp_group_load(&ecpGrp, ECC_CURVE);
|
||||
// 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);
|
||||
@ -70,20 +89,7 @@ void deriveDeviceIDKeyPair(uint8_t * CDIKEY, int isECC)
|
||||
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);
|
||||
|
||||
|
||||
deriveECCKeyPair(&secret, &Public);b
|
||||
|
||||
return;
|
||||
}
|
||||
|
BIN
trial3/out/main
BIN
trial3/out/main
Binary file not shown.
Loading…
Reference in New Issue
Block a user