More adjustments for ephemeral encryption
This commit is contained in:
parent
783855fe26
commit
f9ba2f6c0f
5 changed files with 8 additions and 6 deletions
|
@ -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)
|
if (mbedtls_ecdsa_genkey(&ctx, selected_curve, mbedtls_ctr_drbg_random, &ctr_drbg) != 0)
|
||||||
goto exit;
|
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;
|
retVal = 1;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General helpers for ephemeral keys
|
* General helpers for ephemeral keys
|
||||||
*/
|
*/
|
||||||
|
@ -20,4 +22,4 @@ struct EphemeralPrivateKey {
|
||||||
* @param private_key where to store the private key
|
* @param private_key where to store the private key
|
||||||
* @reutrns true(1) on success, otherwise false(0)
|
* @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);
|
||||||
|
|
|
@ -22,9 +22,9 @@ struct SecureSession {
|
||||||
char* chosen_curve;
|
char* chosen_curve;
|
||||||
char* chosen_cipher;
|
char* chosen_cipher;
|
||||||
char* chosen_hash;
|
char* chosen_hash;
|
||||||
unsigned char* ephemeral_public_key;
|
unsigned char* ephemeral_public_key; // bytes of x and y
|
||||||
size_t ephemeral_public_key_size;
|
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;
|
size_t shared_key_size;
|
||||||
char nonce[16];
|
char nonce[16];
|
||||||
};
|
};
|
||||||
|
|
|
@ -344,7 +344,7 @@ int libp2p_secio_handshake(struct SecureSession* local_session, struct RsaPrivat
|
||||||
remote_session.chosen_hash = local_session->chosen_hash;
|
remote_session.chosen_hash = local_session->chosen_hash;
|
||||||
|
|
||||||
// generate EphemeralPubKey
|
// generate EphemeralPubKey
|
||||||
struct EphemeralPrivateKey e_private_key;
|
struct EphemeralPrivateKey* e_private_key;
|
||||||
libp2p_crypto_ephemeral_key_generate(local_session->chosen_curve, &e_private_key);
|
libp2p_crypto_ephemeral_key_generate(local_session->chosen_curve, &e_private_key);
|
||||||
// build buffer to sign
|
// build buffer to sign
|
||||||
char_buffer = libp2p_utils_vector_new();
|
char_buffer = libp2p_utils_vector_new();
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* Try to generate an ephemeral private key
|
* Try to generate an ephemeral private key
|
||||||
*/
|
*/
|
||||||
int test_ephemeral_key_generate() {
|
int test_ephemeral_key_generate() {
|
||||||
struct EphemeralPrivateKey private_key;
|
struct EphemeralPrivateKey* private_key;
|
||||||
int retVal = libp2p_crypto_ephemeral_key_generate("P-256", &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)
|
if (retVal && private_key->secret_key > 0 && private_key->public_key->x > 0 && private_key->public_key->y > 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue