![]() |
GNUnet
0.11.x
|
public key cryptography (ECC) with libgcrypt More...
#include "platform.h"
#include <gcrypt.h>
#include <sodium.h>
#include "gnunet_crypto_lib.h"
#include "gnunet_strings_lib.h"
#include "benchmark.h"
Go to the source code of this file.
Macros | |
#define | EXTRA_CHECKS 0 |
#define | CURVE "Ed25519" |
IMPLEMENTATION NOTICE: More... | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__) |
#define | LOG_STRERROR(kind, syscall) GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall) |
#define | LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename) |
#define | LOG_GCRY(level, cmd, rc) |
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by gcry_strerror(rc). More... | |
Functions | |
static int | key_from_sexp (gcry_mpi_t *array, gcry_sexp_t sexp, const char *topname, const char *elems) |
Extract values from an S-expression. More... | |
static gcry_sexp_t | decode_private_ecdsa_key (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) |
Convert the given private key from the network format to the S-expression that can be used by libgcrypt. More... | |
void | GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
Extract the public key for the given private key. More... | |
void | GNUNET_CRYPTO_eddsa_key_get_public (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub) |
Extract the public key for the given private key. More... | |
void | GNUNET_CRYPTO_ecdhe_key_get_public (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub) |
Extract the public key for the given private key. More... | |
char * | GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
Convert a public key to a string. More... | |
char * | GNUNET_CRYPTO_eddsa_public_key_to_string (const struct GNUNET_CRYPTO_EddsaPublicKey *pub) |
Convert a public key to a string. More... | |
char * | GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) |
Convert a private key to a string. More... | |
char * | GNUNET_CRYPTO_ecdsa_private_key_to_string (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) |
Convert a private key to a string. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdsa_public_key_from_string (const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
Convert a string representing a public key to a public key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub) |
Convert a string representing a public key to a public key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPrivateKey *priv) |
Convert a string representing a private key to a private key. More... | |
void | GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
Clear memory that was used to store a private key. More... | |
void | GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) |
Clear memory that was used to store a private key. More... | |
void | GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
Clear memory that was used to store a private key. More... | |
void | GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
Create a new private key. More... | |
void | GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) |
Create a new private key. More... | |
void | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
Create a new private key. More... | |
const struct GNUNET_CRYPTO_EcdsaPrivateKey * | GNUNET_CRYPTO_ecdsa_key_get_anonymous () |
Get the shared private key we use for anonymous users. More... | |
static gcry_sexp_t | data_to_ecdsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose) |
Convert the data specified in the given purpose argument to an S-expression suitable for signature operations. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdsa_sign_ (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig) |
ECDSA Sign a given block. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_sign_ (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig) |
EdDSA sign a given block. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdsa_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
Verify ECDSA signature. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub) |
Verify EdDSA signature. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material) |
Derive key material from a public and a private ECC key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material) |
Derive key material from a ECDH public key and a private EdDSA key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material) |
Derive key material from a ECDH public key and a private ECDSA key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material) |
Derive key material from a EdDSA public key and a private ECDH key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, struct GNUNET_HashCode *key_material) |
Derive key material from a EcDSA public key and a private ECDH key. More... | |
public key cryptography (ECC) with libgcrypt
Definition in file crypto_ecc.c.
#define EXTRA_CHECKS 0 |
Definition at line 34 of file crypto_ecc.c.
#define CURVE "Ed25519" |
IMPLEMENTATION NOTICE:
ECDSA: We use a non-standard curve for ECDSA: Ed25519. For performance reasons, we use cryptographic operations from libsodium wherever we can get away with it, even though libsodium itself does not support ECDSA. This is why the sign and verifiy functionality from libgcrypt is required and used.
EdDSA: We use a standard EdDSA construction. (We still use libgcrypt for hashing and RNG, but not EC)
ECDHE: For both EdDSA and ECDSA keys, we use libsodium for ECDHE due to performance benefits over libgcrypt. Name of the curve we are using. Note that we have hard-coded structs that use 256 bits, so using a bigger curve will require changes that break stuff badly. The name of the curve given here must be agreed by all peers and be supported by libgcrypt.
Definition at line 59 of file crypto_ecc.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__) |
Definition at line 61 of file crypto_ecc.c.
#define LOG_STRERROR | ( | kind, | |
syscall | |||
) | GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall) |
Definition at line 63 of file crypto_ecc.c.
#define LOG_STRERROR_FILE | ( | kind, | |
syscall, | |||
filename | |||
) | GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename) |
Definition at line 66 of file crypto_ecc.c.
#define LOG_GCRY | ( | level, | |
cmd, | |||
rc | |||
) |
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by gcry_strerror(rc).
Definition at line 74 of file crypto_ecc.c.
|
static |
Extract values from an S-expression.
array | where to store the result(s) |
sexp | S-expression to parse |
topname | top-level name in the S-expression that is of interest |
elems | names of the elements to extract |
Definition at line 96 of file crypto_ecc.c.
References list.
|
static |
Convert the given private key from the network format to the S-expression that can be used by libgcrypt.
priv | private key to decode |
Definition at line 154 of file crypto_ecc.c.
References CURVE, GNUNET_CRYPTO_EcdsaPrivateKey::d, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, LOG_GCRY, and result.
char* GNUNET_CRYPTO_ecdsa_public_key_to_string | ( | const struct GNUNET_CRYPTO_EcdsaPublicKey * | pub | ) |
Convert a public key to a string.
pub | key to convert |
Definition at line 224 of file crypto_ecc.c.
References end, GNUNET_free, GNUNET_malloc, GNUNET_STRINGS_data_to_string(), and pub.
Referenced by get_ego().
char* GNUNET_CRYPTO_eddsa_public_key_to_string | ( | const struct GNUNET_CRYPTO_EddsaPublicKey * | pub | ) |
Convert a public key to a string.
pub | key to convert |
Definition at line 251 of file crypto_ecc.c.
References end, GNUNET_free, GNUNET_malloc, GNUNET_STRINGS_data_to_string(), and pub.
Referenced by conversation_value_to_string(), create_keys(), GCP_2s(), GNUNET_FRIENDS_write(), GNUNET_HELLO_compose_uri(), GNUNET_i2s(), GNUNET_i2s2(), GNUNET_i2s_full(), main(), messenger_value_to_string(), print_key(), run(), and uri_loc_to_string().
char* GNUNET_CRYPTO_eddsa_private_key_to_string | ( | const struct GNUNET_CRYPTO_EddsaPrivateKey * | priv | ) |
Convert a private key to a string.
priv | key to convert |
Definition at line 278 of file crypto_ecc.c.
References end, GNUNET_free, GNUNET_malloc, and GNUNET_STRINGS_data_to_string().
Referenced by run().
char* GNUNET_CRYPTO_ecdsa_private_key_to_string | ( | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | priv | ) |
Convert a private key to a string.
priv | key to convert |
Definition at line 305 of file crypto_ecc.c.
References end, GNUNET_free, GNUNET_malloc, and GNUNET_STRINGS_data_to_string().
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_public_key_from_string | ( | const char * | enc, |
size_t | enclen, | ||
struct GNUNET_CRYPTO_EcdsaPublicKey * | pub | ||
) |
Convert a string representing a public key to a public key.
enc | encoded public key |
enclen | number of bytes in enc (without 0-terminator) |
pub | where to store the public key |
Definition at line 305 of file crypto_ecc.c.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string | ( | const char * | enc, |
size_t | enclen, | ||
struct GNUNET_CRYPTO_EddsaPublicKey * | pub | ||
) |
Convert a string representing a public key to a public key.
enc | encoded public key |
enclen | number of bytes in enc (without 0-terminator) |
pub | where to store the public key |
Definition at line 305 of file crypto_ecc.c.
Referenced by blacklist_cfg_iter(), conversation_string_to_value(), create_keys(), gns_string_to_value(), GNUNET_FRIENDS_parse(), hosts_directory_scan_callback(), messenger_string_to_value(), on_identity(), run(), s2i_full(), server_parse_url(), show_peer(), and uri_loc_parse().
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_private_key_from_string | ( | const char * | enc, |
size_t | enclen, | ||
struct GNUNET_CRYPTO_EddsaPrivateKey * | pub | ||
) |
Convert a string representing a private key to a private key.
enc | encoded public key |
enclen | number of bytes in enc (without 0-terminator) |
priv | where to store the private key |
Definition at line 305 of file crypto_ecc.c.
|
static |
Convert the data specified in the given purpose argument to an S-expression suitable for signature operations.
purpose | data to convert |
Definition at line 512 of file crypto_ecc.c.