diff --git a/trial3/layer1.c b/trial3/layer1.c
index 258f5f7..a489eaf 100644
--- a/trial3/layer1.c
+++ b/trial3/layer1.c
@@ -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"));
diff --git a/trial3/links.txt b/trial3/links.txt
index 5613042..fad64b9 100644
--- a/trial3/links.txt
+++ b/trial3/links.txt
@@ -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 )
+
+
\ No newline at end of file
diff --git a/trial3/nbproject/private/configurations.xml b/trial3/nbproject/private/configurations.xml
index a6a3f89..4eb20b6 100644
--- a/trial3/nbproject/private/configurations.xml
+++ b/trial3/nbproject/private/configurations.xml
@@ -6,90 +6,9 @@
-
-
-
- aes.h
- aesni.h
- arc4.h
- aria.h
- asn1.h
- asn1write.h
- base64.h
- bignum.h
- blowfish.h
- bn_mul.h
- camellia.h
- ccm.h
- certs.h
- chacha20.h
- chachapoly.h
- check_config.h
- cipher.h
- cipher_internal.h
- cmac.h
- compat-1.3.h
- config.h
- ctr_drbg.h
- debug.h
- des.h
- dhm.h
- ecdh.h
- ecdsa.h
- ecjpake.h
- ecp.h
- ecp_internal.h
- entropy.h
- entropy_poll.h
- error.h
- gcm.h
- havege.h
- hkdf.h
- hmac_drbg.h
- md.h
- md2.h
- md4.h
- md5.h
- md_internal.h
- memory_buffer_alloc.h
- net.h
- net_sockets.h
- nist_kw.h
- oid.h
- padlock.h
- pem.h
- pk.h
- pk_internal.h
- pkcs11.h
- pkcs12.h
- pkcs5.h
- platform.h
- platform_time.h
- platform_util.h
- poly1305.h
- ripemd160.h
- rsa.h
- rsa_internal.h
- sha1.h
- sha256.h
- sha512.h
- ssl.h
- ssl_cache.h
- ssl_ciphersuites.h
- ssl_cookie.h
- ssl_internal.h
- ssl_ticket.h
- threading.h
- timing.h
- version.h
- x509.h
- x509_crl.h
- x509_crt.h
- x509_csr.h
- xtea.h
-
+ ECCtrial.c
defines.h
layer1.c
layer1.h
diff --git a/trial3/nbproject/private/private.xml b/trial3/nbproject/private/private.xml
index 4f3fdc6..89b112f 100644
--- a/trial3/nbproject/private/private.xml
+++ b/trial3/nbproject/private/private.xml
@@ -7,4 +7,14 @@
0
0
+
+
+
+ file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/layer2.c
+ file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/layer1.c
+ file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/nbproject/private/launcher.properties
+ file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/makefile
+ file:/home/atul/Projects/GIT/RIoT/openSSL-DICE/trial3/main.c
+
+
diff --git a/trial3/out/main b/trial3/out/main
index d6d2d27..0024400 100755
Binary files a/trial3/out/main and b/trial3/out/main differ