More adjustments for ephemeral encryption

yamux
John Jones 2017-02-06 17:28:11 -05:00
parent 783855fe26
commit f9ba2f6c0f
5 changed files with 8 additions and 6 deletions

View File

@ -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:

View File

@ -1,5 +1,7 @@
#pragma once
#include <stdint.h>
/**
* 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);

View File

@ -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];
};

View File

@ -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();

View File

@ -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;