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 553fea7..9171901 100755 Binary files a/trial3/out/main and b/trial3/out/main differ