c-libp2p/include/libp2p/crypto/ephemeral.h

53 lines
1.2 KiB
C
Raw Normal View History

#pragma once
#include <stdint.h>
/**
* General helpers for ephemeral keys
*/
2017-02-08 16:08:05 +00:00
struct StretchedKey {
char* iv;
size_t iv_size;
char* cipher_key;
size_t cipher_size;
char* mac_key;
size_t mac_size;
};
struct EphemeralPublicKey {
size_t num_bits;
uint64_t x;
uint64_t y;
2017-02-08 16:08:05 +00:00
unsigned char* bytes; // a public key in bytes (the combination of X and Y)
size_t bytes_size;
unsigned char* shared_key;
size_t shared_key_size;
};
struct EphemeralPrivateKey {
size_t num_bits;
uint64_t secret_key;
struct EphemeralPublicKey* public_key;
};
/**
* Generate a Ephemeral Public Key as well as a shared key
* @param curve the curve to use (P-256, P-384, or P-521)
* @param private_key where to store the private key
* @reutrns true(1) on success, otherwise false(0)
*/
int libp2p_crypto_ephemeral_keypair_generate(char* curve, struct EphemeralPrivateKey** private_key);
2017-02-08 16:08:05 +00:00
2017-02-08 17:32:41 +00:00
/***
* Remove resources used by generation of ephemeral private key
* @param in the key to destroy
*/
void libp2p_crypto_ephemeral_key_free( struct EphemeralPrivateKey* in);
2017-02-08 16:08:05 +00:00
/**
* Routines to help with the StretchedKey struct
*/
struct StretchedKey* libp2p_crypto_ephemeral_stretched_key_new();
void libp2p_crypto_ephemeral_stretched_key_free(struct StretchedKey* in);