From 90f9e7f5b7d73a6b2db9b5aa9a5e773e7aa81294 Mon Sep 17 00:00:00 2001 From: "atul.jha" Date: Mon, 3 Aug 2020 18:41:15 +0200 Subject: [PATCH] minor changes. derive ECC still working --- trial3/layer1.c | 142 ++++++++++---------- trial3/layer2.c | 2 +- trial3/nbproject/private/configurations.xml | 82 ++++++++++- trial3/out/main | Bin 19024 -> 19024 bytes 4 files changed, 149 insertions(+), 77 deletions(-) diff --git a/trial3/layer1.c b/trial3/layer1.c index 5fd4c78..16bc9be 100644 --- a/trial3/layer1.c +++ b/trial3/layer1.c @@ -250,11 +250,8 @@ int seedRNGSource(void *data, unsigned char *output, size_t len) if(memcpy(output, p_ent -> accumulator.buffer + ACCUM_BUFF_OFFSET , ENTROPY_LEN) < 0) return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); - for(int i = 0; i < ENTROPY_LEN; i++) - printf("0x%hhx,",output[i]); - printf(" : CDIKEY\n"); len = ENTROPY_LEN; - printf("%d\n", (int)len ); + return 0; @@ -280,108 +277,105 @@ int deriveECCKeyPair(KeyDrv_context * KD_ctx) printf("inside deriveECCKeyPair layer1\n\n"); int ret = 0; - unsigned char pubkeybuf[100]; - size_t pubkeysize; - char privkeybuf[100]; - size_t privkeysize; - char privkeybuf2[100]; - size_t privkey2size; + unsigned char pubkeybuf[100]; + size_t pubkeysize; + char privkeybuf[100]; + size_t privkeysize; + char privkeybuf2[100]; + size_t privkey2size; + 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_group ecpGrp; - mbedtls_ecp_group_init(&ecpGrp); - mbedtls_ecp_group_load(&ecpGrp, ECC_CURVE); + mbedtls_ecp_point Public; + mbedtls_ecp_point_init(&Public); - mbedtls_mpi secret; - mbedtls_mpi_init(&secret); + mbedtls_entropy_context entropyCtx; + mbedtls_entropy_init(&entropyCtx); - mbedtls_ecp_point Public; - mbedtls_ecp_point_init(&Public); + mbedtls_ctr_drbg_context drbgCtx; + mbedtls_ctr_drbg_init(&drbgCtx); - mbedtls_entropy_context entropyCtx; - mbedtls_entropy_init(&entropyCtx); + + if (KD_ctx->ENT_MODE == HW_TRNG) //HW RNG + { + printf("using /dev/random.... this may take a moment\n"); + mbedtls_entropy_add_source( &entropyCtx, use_dev_random, + NULL, ENTROPY_LEN, MBEDTLS_ENTROPY_SOURCE_STRONG ); + + mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, + &entropyCtx, + (const unsigned char *) KD_ctx->phrase , + strlen(KD_ctx->phrase) + ); + } - mbedtls_ctr_drbg_context drbgCtx; - mbedtls_ctr_drbg_init(&drbgCtx); - - - if (KD_ctx->ENT_MODE == HW_TRNG) //HW RNG + else if (KD_ctx->ENT_MODE == DETERM) // Deterministic derviation with seed + { + printf("Seeding entropy accumulator....\n"); + if(mbedtls_entropy_update_manual(&entropyCtx, KD_ctx->seed, ENTROPY_LEN) < 0) { - printf("using /dev/random.... this may take a moment\n"); - mbedtls_entropy_add_source( &entropyCtx, use_dev_random, - NULL, ENTROPY_LEN, MBEDTLS_ENTROPY_SOURCE_STRONG ); - - mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, - &entropyCtx, - (const unsigned char *) KD_ctx->phrase , - strlen(KD_ctx->phrase) - ); + perror("Accumulator seed failed\n"); + return RIOTFAILURE; } - else if (KD_ctx->ENT_MODE == DETERM) // Deterministic derviation with seed - { - printf("Seeding entropy accumulator....\n"); - if(mbedtls_entropy_update_manual(&entropyCtx, KD_ctx->seed, ENTROPY_LEN) < 0) - { - perror("Accumulator seed failed\n"); - return RIOTFAILURE; - } - - if(mbedtls_ctr_drbg_seed(&drbgCtx, seedRNGSource, &entropyCtx, - (const unsigned char *) KD_ctx->phrase, sizeof(&KD_ctx->phrase)) < 0) - { - perror("drbg seed failed\v"); - return RIOTFAILURE; - } + if(mbedtls_ctr_drbg_seed(&drbgCtx, seedRNGSource, &entropyCtx, + (const unsigned char *) KD_ctx->phrase, sizeof(&KD_ctx->phrase)) < 0) + { + perror("drbg seed failed\v"); + return RIOTFAILURE; + } } - else //regular key derivation + else //regular SW accumulator used for key derivation { printf("Accumulating entropy ...\n"); mbedtls_entropy_update_manual(&entropyCtx, KD_ctx->seed, ENTROPY_LEN); - mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, - &entropyCtx, + mbedtls_ctr_drbg_seed(&drbgCtx, mbedtls_entropy_func, &entropyCtx, (const unsigned char *) KD_ctx->phrase , strlen(KD_ctx->phrase) ); } - if(mbedtls_ecp_gen_keypair(&ecpGrp, &secret, &Public, - mbedtls_ctr_drbg_random, &drbgCtx) <0) - { - perror("ECP gen keypair failed\n"); - return RIOTFAILURE; - } + 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; - } + 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 ); + //printf("%zu : pubkeysize\n", pubkeysize ); for(int i = 0; i < pubkeysize; i++) printf("%hhx",pubkeybuf[i]); printf(" : PubKey\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; - } + 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("%s : PrivKey\n",privkeybuf); //copy keys to parent function - mbedtls_ecp_copy(&KD_ctx->Public, &Public); - mbedtls_mpi_copy(&KD_ctx->secret, &secret); /* Make SK NULL for Identitiy key generation */ + mbedtls_ecp_copy(&KD_ctx->Public, &Public); + mbedtls_mpi_copy(&KD_ctx->secret, &secret); /* Make SK NULL for Identitiy key generation */ diff --git a/trial3/layer2.c b/trial3/layer2.c index 1a379d1..7ac4b12 100644 --- a/trial3/layer2.c +++ b/trial3/layer2.c @@ -19,7 +19,7 @@ void ROMprotocol(void) deriveDeviceIDKeyPair(CDIKEY, USE_ECC); - deriveDeviceIDKeyPair(CDIKEY, USE_ECC); + //deriveDeviceIDKeyPair(CDIKEY, USE_ECC); printf("pass 100\n"); diff --git a/trial3/nbproject/private/configurations.xml b/trial3/nbproject/private/configurations.xml index 4eb20b6..7534ff3 100644 --- a/trial3/nbproject/private/configurations.xml +++ b/trial3/nbproject/private/configurations.xml @@ -3,6 +3,86 @@ + + 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 + @@ -42,8 +122,6 @@ - - diff --git a/trial3/out/main b/trial3/out/main index 553fea7fe04338079e52bf14b1fb2616a036e7e8..91719018c9e3dab1c588bef259e1fb61410381fb 100755 GIT binary patch delta 1999 zcmY*a3rtgI6u$rE(N-QU3YKEw-cpLTAc#~zpa#^!Wx8ZW(M{dvBF@*$oNt#XXk|%L z8=1!$wqy^D+0Yp$>4HcAJIQny;;PwnW@f<+v*MFtQGDK=|K7IFo7{W;bN=tV|MOqp z0pdGAntZC%97cLlKfQJ)$vR19A{362Ka<;U1TA~VmhSw@H>t(?_p@yyoeS1_n%U+U z674Ba-iTM;QZtO;PS^-(DUZg9i45ak_)HZ2+5{@LJxzqH@l*JIlp}YYZs)!bMZszJ z3XUCKX7hLyUrdBe<6B4(q-)a%4<%Z2dH~hiX*~WzPesvT?<9^Lo!m|zqHiU@PVI88 zNp|2u;{O^wqRAFC*&>^)+@CtCUmPDcGUf?2as-VWk&Uc|WZfb5_c%DED`$U}{P=z2r}?FeX>0c+vC2|Rfdc279Y z_NZWr-p1Zk!iRbt*#J)c3T2g2DuxCg>d%f{ij4ni|G}dG zmSp58GAYIu1b2q^gV`gPs=M(dM%5ifHJs=D4XBQ?3Y1YcAhXLt>|t3$gLS04o(Hml z$1+<-cU_IC2zFI0bBvPB+c1c31$sOU8ZKS`&vO}Qq*i61;Hp?pP4z8x%$X|`%=V5q_%Tk?E%OPBa{k$pdqY(G_rThJ{XvG|aOT3M&0kt6| z_6;ie6)c8=`1#S{UPleXN`pZWL-)!8u+LyxG%zfR&c<9UkE4rzneF*5iFKaCw9dtZ zRrdxkIJd0}1%3@WmXkOprDksuBy>*%{SL%s>gz92olrvV&*b)9p@m&FM2$rn+KVwD z8*b<=$(3{jD7Z}C4fnTP);$^O?>dRKRnfQ#a4p3pxLzNv6XFWvO?2ir#rT_{H8XR@ zWC|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