From f9ba2f6c0f5dbb878053bfa018a9f17098ea27df Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 6 Feb 2017 17:28:11 -0500 Subject: [PATCH] More adjustments for ephemeral encryption --- crypto/ephemeral.c | 2 +- include/libp2p/crypto/ephemeral.h | 4 +++- include/libp2p/secio/secio.h | 4 ++-- secio/secio.c | 2 +- test/crypto/test_ephemeral.h | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crypto/ephemeral.c b/crypto/ephemeral.c index 1e15e34..896c304 100644 --- a/crypto/ephemeral.c +++ b/crypto/ephemeral.c @@ -64,7 +64,7 @@ int libp2p_crypto_ephemeral_key_generate(char* curve, struct EphemeralPrivateKey if (mbedtls_ecdsa_genkey(&ctx, selected_curve, mbedtls_ctr_drbg_random, &ctr_drbg) != 0) goto exit; - *private_key = libp2p_crypto_ephemeral_key_new(*ctx.d->p, *ctx.Q->X.p, *ctx.Q->Y.p); + *private_key = libp2p_crypto_ephemeral_key_new(*ctx.d.p, *ctx.Q.X.p, *ctx.Q.Y.p); retVal = 1; exit: diff --git a/include/libp2p/crypto/ephemeral.h b/include/libp2p/crypto/ephemeral.h index 44210e1..04c273c 100644 --- a/include/libp2p/crypto/ephemeral.h +++ b/include/libp2p/crypto/ephemeral.h @@ -1,5 +1,7 @@ #pragma once +#include + /** * General helpers for ephemeral keys */ @@ -20,4 +22,4 @@ struct EphemeralPrivateKey { * @param private_key where to store the private key * @reutrns true(1) on success, otherwise false(0) */ -int libp2p_crypto_ephemeral_key_generate(char* curve, struct EphemeralPrivateKey* private_key); +int libp2p_crypto_ephemeral_key_generate(char* curve, struct EphemeralPrivateKey** private_key); diff --git a/include/libp2p/secio/secio.h b/include/libp2p/secio/secio.h index 2c20673..015e159 100644 --- a/include/libp2p/secio/secio.h +++ b/include/libp2p/secio/secio.h @@ -22,9 +22,9 @@ struct SecureSession { char* chosen_curve; char* chosen_cipher; char* chosen_hash; - unsigned char* ephemeral_public_key; + unsigned char* ephemeral_public_key; // bytes of x and y size_t ephemeral_public_key_size; - unsigned char* shared_key; + unsigned char* shared_key; // a shared key based off of the ephemeral private key size_t shared_key_size; char nonce[16]; }; diff --git a/secio/secio.c b/secio/secio.c index 37fca59..95c2111 100644 --- a/secio/secio.c +++ b/secio/secio.c @@ -344,7 +344,7 @@ int libp2p_secio_handshake(struct SecureSession* local_session, struct RsaPrivat remote_session.chosen_hash = local_session->chosen_hash; // generate EphemeralPubKey - struct EphemeralPrivateKey e_private_key; + struct EphemeralPrivateKey* e_private_key; libp2p_crypto_ephemeral_key_generate(local_session->chosen_curve, &e_private_key); // build buffer to sign char_buffer = libp2p_utils_vector_new(); diff --git a/test/crypto/test_ephemeral.h b/test/crypto/test_ephemeral.h index 0b7769c..2a43999 100644 --- a/test/crypto/test_ephemeral.h +++ b/test/crypto/test_ephemeral.h @@ -5,7 +5,7 @@ * Try to generate an ephemeral private key */ int test_ephemeral_key_generate() { - struct EphemeralPrivateKey private_key; + struct EphemeralPrivateKey* private_key; int retVal = libp2p_crypto_ephemeral_key_generate("P-256", &private_key); if (retVal && private_key->secret_key > 0 && private_key->public_key->x > 0 && private_key->public_key->y > 0) return 1;