ECC key to string
This commit is contained in:
parent
eca211d2de
commit
c422a95a43
@ -28,11 +28,11 @@ int readUDS(uint8_t* UDSdigest)
|
||||
|
||||
|
||||
for (int i = 0; i < UDS_SIZE; i++)
|
||||
printf("%x", UDSbuf[i]);
|
||||
printf("%hhx", UDSbuf[i]);
|
||||
printf(" : fuse secret\n" );
|
||||
|
||||
for (int i = 0; i < UDS_DGST_SIZE; i++)
|
||||
printf("%x", UDSdigest[i]);
|
||||
printf("%hhx", UDSdigest[i]);
|
||||
printf(" : UDS ID\n" );
|
||||
|
||||
free(UDSbuf);
|
||||
@ -78,7 +78,7 @@ int readFWID(uint8_t* FW_M)
|
||||
//printf("File contnts : %s\n", source);
|
||||
|
||||
for(int i = 0; i < FW_DGST_SIZE; i++)
|
||||
printf("%x",FW_M[i]);
|
||||
printf("%hhx",FW_M[i]);
|
||||
printf(" : FW digest\n");
|
||||
|
||||
//free(source);
|
||||
@ -133,7 +133,7 @@ int _calcCDID(uint8_t * CDID)
|
||||
}
|
||||
|
||||
for(int i = 0; i < CDI_DGST_SIZE; i++)
|
||||
printf("%x",CDID[i]);
|
||||
printf("%hhx",CDID[i]);
|
||||
printf(" : CDID\n");
|
||||
|
||||
free(UDS_ID);
|
||||
@ -154,7 +154,7 @@ int _calcCDIKEY(uint8_t * CDIKEY)
|
||||
_calcCDID(KEYIN);
|
||||
|
||||
for(int i = 0; i < SHA256_DGST_SIZE; i++)
|
||||
printf("%x",KEYIN[i]);
|
||||
printf("%hhx",KEYIN[i]);
|
||||
printf(" : CDID main\n");
|
||||
|
||||
const mbedtls_md_info_t * md_info;
|
||||
@ -174,7 +174,7 @@ int _calcCDIKEY(uint8_t * CDIKEY)
|
||||
//mbedtls_hkdf_extract( md_info, salt, sizeof(salt),KEYIN, CDI_DGST_SIZE, CDIKEY);
|
||||
|
||||
for(int i = 0; i < CDI_KEY_SIZE; i++)
|
||||
printf("%x",CDIKEY[i]);
|
||||
printf("%hhx",CDIKEY[i]);
|
||||
printf(" : CDIKEY\n");
|
||||
|
||||
free(KEYIN);
|
||||
@ -182,11 +182,32 @@ int _calcCDIKEY(uint8_t * CDIKEY)
|
||||
return RIOTSUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//firt generate ECC/RSA key. - Done ECC
|
||||
//check for deterministic consistency - inconsistent
|
||||
//seed RNGs with CDI
|
||||
//let's see how it goes
|
||||
|
||||
//add entropy source?
|
||||
//seed RNG
|
||||
//create ctx
|
||||
//init
|
||||
//gen keypair
|
||||
|
||||
|
||||
|
||||
int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK)
|
||||
{
|
||||
|
||||
printf("inside deriveECCKeyPair layer1\n\n");
|
||||
|
||||
int ret = 0;
|
||||
unsigned char pubkeybuf[100];
|
||||
size_t pubkeysize;
|
||||
char privkeybuf[100];
|
||||
size_t privkeysize;
|
||||
|
||||
mbedtls_ecp_group ecpGrp;
|
||||
mbedtls_ecp_group_init(&ecpGrp);
|
||||
mbedtls_ecp_group_load(&ecpGrp, ECC_CURVE);
|
||||
@ -204,12 +225,58 @@ int deriveECCKeyPair(mbedtls_mpi * SK, mbedtls_ecp_point * PK)
|
||||
mbedtls_ctr_drbg_init(&drbgCtx);
|
||||
|
||||
//Seed drbg with secret data now?
|
||||
//move "private" string to n param
|
||||
if(mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, &entropyCtx,
|
||||
(const unsigned char *) "Private", sizeof("Private")) < 0)
|
||||
{
|
||||
perror("drbg seed failed\v");
|
||||
return RIOTFAILURE;
|
||||
}
|
||||
|
||||
int ret = mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, &entropyCtx,
|
||||
(const unsigned char *) "Private", sizeof("Private"));
|
||||
if(mbedtls_ecp_gen_keypair(&ecpGrp, &secret, &Public,
|
||||
mbedtls_ctr_drbg_random, &drbgCtx) <0)
|
||||
{
|
||||
perror("ECP gen keypair failed\n");
|
||||
return RIOTFAILURE;
|
||||
}
|
||||
|
||||
ret = mbedtls_ecp_tls_write_point(&ecpGrp, &Public, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
&pubkeysize, pubkeybuf, sizeof(pubkeybuf));
|
||||
if(ret < 0)
|
||||
{
|
||||
perror("ECP write point failure\n");
|
||||
return RIOTFAILURE;
|
||||
}
|
||||
|
||||
//printf("%zu : pubkeysize\n", pubkeysize );
|
||||
for(int i = 0; i < pubkeysize; i++)
|
||||
printf("%hhx",pubkeybuf[i]);
|
||||
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);
|
||||
if(ret < 0)
|
||||
{
|
||||
printf("%d\n", ret);
|
||||
perror("MPI write point to string failure\n");
|
||||
return RIOTFAILURE;
|
||||
}
|
||||
|
||||
//printf("%zu : privkeysize\n", privkeysize);
|
||||
//for(int i = 0; i < privkeysize; i++)
|
||||
printf("%s : PrivKey\n",privkeybuf);
|
||||
|
||||
ret = mbedtls_ecp_gen_keypair(&ecpGrp, &secret, &Public,
|
||||
mbedtls_ctr_drbg_random, &drbgCtx);
|
||||
|
||||
mbedtls_ecp_copy(PK, &Public);
|
||||
mbedtls_mpi_copy(SK, &secret);
|
||||
@ -241,7 +308,7 @@ int deriveRSAKeyPair(void)
|
||||
mbedtls_ctr_drbg_init(&drbgCtx);
|
||||
|
||||
//Seed drbg with secret data now?
|
||||
|
||||
//move "private" string to n param
|
||||
int ret = mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, &entropyCtx,
|
||||
(const unsigned char *) "Private", sizeof("Private"));
|
||||
|
||||
|
@ -5,3 +5,17 @@ https://www.cryptopp.com/wiki/
|
||||
|
||||
/usr/include/crypto++/
|
||||
/usr/share/doc/libcrypto++-dev/Readme.txt.gz
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
adding /dev/random to entropy -
|
||||
mbedtls_entropy_add_source( &entropy, dev_random_entropy_poll,
|
||||
NULL, DEV_RANDOM_THRESHOLD,
|
||||
MBEDTLS_ENTROPY_SOURCE_STRONG ) ) != 0 )
|
||||
|
||||
|
@ -6,90 +6,9 @@
|
||||
</df>
|
||||
<df name="keys">
|
||||
</df>
|
||||
<df name="lib">
|
||||
</df>
|
||||
<df name="mbedtls">
|
||||
<in>aes.h</in>
|
||||
<in>aesni.h</in>
|
||||
<in>arc4.h</in>
|
||||
<in>aria.h</in>
|
||||
<in>asn1.h</in>
|
||||
<in>asn1write.h</in>
|
||||
<in>base64.h</in>
|
||||
<in>bignum.h</in>
|
||||
<in>blowfish.h</in>
|
||||
<in>bn_mul.h</in>
|
||||
<in>camellia.h</in>
|
||||
<in>ccm.h</in>
|
||||
<in>certs.h</in>
|
||||
<in>chacha20.h</in>
|
||||
<in>chachapoly.h</in>
|
||||
<in>check_config.h</in>
|
||||
<in>cipher.h</in>
|
||||
<in>cipher_internal.h</in>
|
||||
<in>cmac.h</in>
|
||||
<in>compat-1.3.h</in>
|
||||
<in>config.h</in>
|
||||
<in>ctr_drbg.h</in>
|
||||
<in>debug.h</in>
|
||||
<in>des.h</in>
|
||||
<in>dhm.h</in>
|
||||
<in>ecdh.h</in>
|
||||
<in>ecdsa.h</in>
|
||||
<in>ecjpake.h</in>
|
||||
<in>ecp.h</in>
|
||||
<in>ecp_internal.h</in>
|
||||
<in>entropy.h</in>
|
||||
<in>entropy_poll.h</in>
|
||||
<in>error.h</in>
|
||||
<in>gcm.h</in>
|
||||
<in>havege.h</in>
|
||||
<in>hkdf.h</in>
|
||||
<in>hmac_drbg.h</in>
|
||||
<in>md.h</in>
|
||||
<in>md2.h</in>
|
||||
<in>md4.h</in>
|
||||
<in>md5.h</in>
|
||||
<in>md_internal.h</in>
|
||||
<in>memory_buffer_alloc.h</in>
|
||||
<in>net.h</in>
|
||||
<in>net_sockets.h</in>
|
||||
<in>nist_kw.h</in>
|
||||
<in>oid.h</in>
|
||||
<in>padlock.h</in>
|
||||
<in>pem.h</in>
|
||||
<in>pk.h</in>
|
||||
<in>pk_internal.h</in>
|
||||
<in>pkcs11.h</in>
|
||||
<in>pkcs12.h</in>
|
||||
<in>pkcs5.h</in>
|
||||
<in>platform.h</in>
|
||||
<in>platform_time.h</in>
|
||||
<in>platform_util.h</in>
|
||||
<in>poly1305.h</in>
|
||||
<in>ripemd160.h</in>
|
||||
<in>rsa.h</in>
|
||||
<in>rsa_internal.h</in>
|
||||
<in>sha1.h</in>
|
||||
<in>sha256.h</in>
|
||||
<in>sha512.h</in>
|
||||
<in>ssl.h</in>
|
||||
<in>ssl_cache.h</in>
|
||||
<in>ssl_ciphersuites.h</in>
|
||||
<in>ssl_cookie.h</in>
|
||||
<in>ssl_internal.h</in>
|
||||
<in>ssl_ticket.h</in>
|
||||
<in>threading.h</in>
|
||||
<in>timing.h</in>
|
||||
<in>version.h</in>
|
||||
<in>x509.h</in>
|
||||
<in>x509_crl.h</in>
|
||||
<in>x509_crt.h</in>
|
||||
<in>x509_csr.h</in>
|
||||
<in>xtea.h</in>
|
||||
</df>
|
||||
<df name="out">
|
||||
</df>
|
||||
<in>ECCtrial.c</in>
|
||||
<in>defines.h</in>
|
||||
<in>layer1.c</in>
|
||||
<in>layer1.h</in>
|
||||
|
@ -7,4 +7,14 @@
|
||||
<activeConfTypeElem>0</activeConfTypeElem>
|
||||
<activeConfIndexElem>0</activeConfIndexElem>
|
||||
</data>
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/layer2.c</file>
|
||||
<file>file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/layer1.c</file>
|
||||
<file>file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/nbproject/private/launcher.properties</file>
|
||||
<file>file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/makefile</file>
|
||||
<file>file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/main.c</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
BIN
trial3/out/main
BIN
trial3/out/main
Binary file not shown.
Loading…
Reference in New Issue
Block a user