PK to PEM experiment failed. Moving on.
This commit is contained in:
parent
c422a95a43
commit
2585a82694
@ -207,6 +207,11 @@ int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK)
|
|||||||
size_t pubkeysize;
|
size_t pubkeysize;
|
||||||
char privkeybuf[100];
|
char privkeybuf[100];
|
||||||
size_t privkeysize;
|
size_t privkeysize;
|
||||||
|
char privkeybuf2[100];
|
||||||
|
size_t privkey2size;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mbedtls_ecp_group ecpGrp;
|
mbedtls_ecp_group ecpGrp;
|
||||||
mbedtls_ecp_group_init(&ecpGrp);
|
mbedtls_ecp_group_init(&ecpGrp);
|
||||||
@ -253,17 +258,6 @@ int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK)
|
|||||||
printf("%hhx",pubkeybuf[i]);
|
printf("%hhx",pubkeybuf[i]);
|
||||||
printf(" : PubKey\n");
|
printf(" : PubKey\n");
|
||||||
|
|
||||||
// ret = mbedtls_mpi_write_binary(&secret, privkeybuf, 100);
|
|
||||||
// if(ret < 0)
|
|
||||||
// {
|
|
||||||
// printf("%d\n", ret);
|
|
||||||
// perror("MPI write point failure\n");
|
|
||||||
// return RIOTFAILURE;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for(int i = 0; i < 100; i++)
|
|
||||||
// printf("%x",privkeybuf[i]);
|
|
||||||
// printf(" : PrivKey\n\n\n");
|
|
||||||
|
|
||||||
ret = mbedtls_mpi_write_string(&secret, 16, privkeybuf, sizeof(privkeybuf), &privkeysize);
|
ret = mbedtls_mpi_write_string(&secret, 16, privkeybuf, sizeof(privkeybuf), &privkeysize);
|
||||||
if(ret < 0)
|
if(ret < 0)
|
||||||
@ -273,16 +267,50 @@ int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK)
|
|||||||
return RIOTFAILURE;
|
return RIOTFAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("%zu : privkeysize\n", privkeysize);
|
|
||||||
//for(int i = 0; i < privkeysize; i++)
|
|
||||||
printf("%s : PrivKey\n",privkeybuf);
|
printf("%s : PrivKey\n",privkeybuf);
|
||||||
|
|
||||||
|
//copy keys to parent function
|
||||||
mbedtls_ecp_copy(PK, &Public);
|
mbedtls_ecp_copy(PK, &Public);
|
||||||
mbedtls_mpi_copy(SK, &secret);
|
mbedtls_mpi_copy(SK, &secret);
|
||||||
|
|
||||||
//what now? how to obtain the keys in PEM/DER/bin format?
|
//what now? how to obtain the keys in PEM/DER/bin format?
|
||||||
|
|
||||||
|
//following experiment better documented in ECC_trial/PKtoPEM.c
|
||||||
|
/**
|
||||||
|
mbedtls_pk_context ec_pkCtx;
|
||||||
|
mbedtls_pk_init(&ec_pkCtx);
|
||||||
|
|
||||||
|
mbedtls_pk_setup(&ec_pkCtx, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY));
|
||||||
|
mbedtls_ecp_keypair *pk_ecp = mbedtls_pk_ec( ec_pkCtx );
|
||||||
|
|
||||||
|
mbedtls_ecp_copy(&pk_ecp->Q, &Public);
|
||||||
|
mbedtls_mpi_copy(&pk_ecp->d, &secret);
|
||||||
|
|
||||||
|
mbedtls_mpi_write_string(&pk_ecp->d, 16, privkeybuf2, sizeof(privkeybuf2), &privkey2size);
|
||||||
|
printf("%s : wrapped PrivKey\n",privkeybuf2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
unsigned char privBuf[16000];
|
||||||
|
unsigned char * d_b = privBuf;
|
||||||
|
memset(privBuf, 0, 16000);
|
||||||
|
unsigned char pubBuf[16000];
|
||||||
|
unsigned char * Q_b = pubBuf;
|
||||||
|
memset(pubBuf, 0, 16000);
|
||||||
|
ret = mbedtls_pk_write_key_pem(&ec_pkCtx, privBuf, 16000);
|
||||||
|
printf("write priv pem ret value = %d\n", ret);
|
||||||
|
|
||||||
|
printf("%s\n", privBuf);
|
||||||
|
|
||||||
|
ret = mbedtls_pk_write_pubkey_pem(&ec_pkCtx, pubBuf, 16000);
|
||||||
|
printf("write pub pem ret value = %d\n", ret);
|
||||||
|
|
||||||
|
printf("%s\n", pubBuf);
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
mbedtls_mpi_free(&secret);
|
mbedtls_mpi_free(&secret);
|
||||||
mbedtls_ecp_point_free(&Public);
|
mbedtls_ecp_point_free(&Public);
|
||||||
mbedtls_ecp_group_free(&ecpGrp);
|
mbedtls_ecp_group_free(&ecpGrp);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <mbedtls/bignum.h>
|
#include <mbedtls/bignum.h>
|
||||||
#include <mbedtls/entropy.h>
|
#include <mbedtls/entropy.h>
|
||||||
@ -12,6 +13,7 @@
|
|||||||
#include <mbedtls/md.h>
|
#include <mbedtls/md.h>
|
||||||
#include <mbedtls/aes.h>
|
#include <mbedtls/aes.h>
|
||||||
#include <mbedtls/rsa.h>
|
#include <mbedtls/rsa.h>
|
||||||
|
#include <mbedtls/pk.h>
|
||||||
#include <mbedtls/sha1.h>
|
#include <mbedtls/sha1.h>
|
||||||
#include <mbedtls/sha256.h>
|
#include <mbedtls/sha256.h>
|
||||||
|
|
||||||
@ -21,8 +23,14 @@
|
|||||||
//int createUDS(); //create rand file. to be replaced with real fuse pointer
|
//int createUDS(); //create rand file. to be replaced with real fuse pointer
|
||||||
|
|
||||||
int readUDS(uint8_t* UDSdigest);
|
int readUDS(uint8_t* UDSdigest);
|
||||||
|
|
||||||
int readFWID(uint8_t * FW_M);
|
int readFWID(uint8_t * FW_M);
|
||||||
|
|
||||||
int _calcCDID(uint8_t * CDID);
|
int _calcCDID(uint8_t * CDID);
|
||||||
|
|
||||||
int _calcCDIKEY(uint8_t * CDIKEY);
|
int _calcCDIKEY(uint8_t * CDIKEY);
|
||||||
|
|
||||||
int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK);
|
int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK);
|
||||||
|
|
||||||
int deriveRSAKeyPair(void);
|
int deriveRSAKeyPair(void);
|
||||||
|
|
||||||
|
@ -57,6 +57,10 @@ void deriveDeviceIDKeyPair(uint8_t * CDIKEY, int isECC)
|
|||||||
//init
|
//init
|
||||||
//gen keypair
|
//gen keypair
|
||||||
|
|
||||||
|
|
||||||
|
//return pubkey and privkey both to L2?
|
||||||
|
|
||||||
|
|
||||||
if(isECC)
|
if(isECC)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -66,8 +70,13 @@ void deriveDeviceIDKeyPair(uint8_t * CDIKEY, int isECC)
|
|||||||
mbedtls_ecp_point Public;
|
mbedtls_ecp_point Public;
|
||||||
mbedtls_ecp_point_init(&Public);
|
mbedtls_ecp_point_init(&Public);
|
||||||
|
|
||||||
|
//return pubkey and privkey both to L2?
|
||||||
deriveECCKeyPair(&secret, &Public);
|
deriveECCKeyPair(&secret, &Public);
|
||||||
|
|
||||||
|
//secret and Public contain raw key inormation of generated keys
|
||||||
|
//Public also needs group and context to handle ECP
|
||||||
|
//Converting raw info to PEM is not easible like this
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,5 +22,15 @@
|
|||||||
|
|
||||||
|
|
||||||
void ROMprotocol(void);
|
void ROMprotocol(void);
|
||||||
void deriveDeviceIDKeyPair(uint8_t * CDIKEY, int isECC);
|
|
||||||
void seedRNGSource(uint8_t * CDIKEY);
|
void seedRNGSource(uint8_t * CDIKEY);
|
||||||
|
|
||||||
|
void deriveDeviceIDKeyPair(uint8_t * CDIKEY, int isECC);
|
||||||
|
|
||||||
|
void deriveAliasKeyPair(uint8_t * ALIKEY, int isECC);
|
||||||
|
|
||||||
|
void writePrivKeytoFile(char * filename, int isPEM);
|
||||||
|
|
||||||
|
void writePubKeytoFile(char* filename, int isPEM);
|
||||||
|
|
||||||
|
void genCertiicate();
|
BIN
trial3/out/main
BIN
trial3/out/main
Binary file not shown.
Loading…
Reference in New Issue
Block a user