public key cryptography (ECC) with libgcrypt More...
#include "platform.h"
#include "gnunet_common.h"
#include <gcrypt.h>
#include <sodium.h>
#include "gnunet_util_lib.h"
#include "benchmark.h"
#include "sodium/crypto_scalarmult.h"
#include "sodium/crypto_scalarmult_curve25519.h"
#include "sodium/utils.h"
Go to the source code of this file.
Macros | |
#define | EXTRA_CHECKS 0 |
#define | CURVE "Ed25519" |
IMPLEMENTATION NOTICE: | |
#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) |
#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). | |
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. | |
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. | |
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. | |
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. | |
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. | |
char * | GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
Convert a public key to a string. | |
char * | GNUNET_CRYPTO_eddsa_public_key_to_string (const struct GNUNET_CRYPTO_EddsaPublicKey *pub) |
Convert a public key to a string. | |
char * | GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) |
Convert a private key to a string. | |
char * | GNUNET_CRYPTO_ecdsa_private_key_to_string (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) |
Convert a private key to a 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. | |
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. | |
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. | |
static void | buffer_clear (void *buf, size_t len) |
void | GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
Clear memory that was used to store a private key. | |
void | GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) |
Clear memory that was used to store a private key. | |
void | GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
Clear memory that was used to store a private key. | |
void | GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
Create a new private key. | |
void | GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) |
Create a new private key. | |
void | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
Create a new private key. | |
const struct GNUNET_CRYPTO_EcdsaPrivateKey * | GNUNET_CRYPTO_ecdsa_key_get_anonymous () |
Get the shared private key we use for anonymous users. | |
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. | |
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. | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_sign_raw (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *data, size_t size, struct GNUNET_CRYPTO_EddsaSignature *sig) |
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. | |
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. | |
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. | |
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. | |
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. | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_x25519_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *sk, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *dh) |
Derive key material from a ECDH public key and a private X25519 key. | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdh_x25519 (const struct GNUNET_CRYPTO_EcdhePrivateKey *sk, const struct GNUNET_CRYPTO_EcdhePublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *dh) |
Derive key material from a EdDSA public key and a private ECDH key. | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material) |
HPKE END. | |
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. | |
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. | |
public key cryptography (ECC) with libgcrypt
Definition in file crypto_ecc.c.
#define EXTRA_CHECKS 0 |
Definition at line 37 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 verify 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 62 of file crypto_ecc.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__) |
Definition at line 64 of file crypto_ecc.c.
#define LOG_STRERROR | ( | kind, | |
syscall | |||
) | GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall) |
Definition at line 66 of file crypto_ecc.c.
#define LOG_STRERROR_FILE | ( | kind, | |
syscall, | |||
filename | |||
) |
Definition at line 69 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 78 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 100 of file crypto_ecc.c.
References list.
Referenced by GNUNET_CRYPTO_ecdsa_sign_().
|
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 158 of file crypto_ecc.c.
References CURVE, d, GNUNET_CRYPTO_EcdsaPrivateKey::d, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, LOG_GCRY, and result.
Referenced by GNUNET_CRYPTO_ecdsa_sign_().
|
static |
Definition at line 418 of file crypto_ecc.c.
References p.
Referenced by GNUNET_CRYPTO_ecdhe_key_clear(), GNUNET_CRYPTO_ecdsa_key_clear(), and GNUNET_CRYPTO_eddsa_key_clear().
|
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 531 of file crypto_ecc.c.
References data, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_ERROR, LOG_GCRY, and GNUNET_CRYPTO_EccSignaturePurpose::size.
Referenced by GNUNET_CRYPTO_ecdsa_sign_(), and GNUNET_CRYPTO_ecdsa_verify_().