GNUnet 0.28.0
 
Loading...
Searching...
No Matches
Crypto library: cryptographic operations

Provides cryptographic primitives. More...

Collaboration diagram for Crypto library: cryptographic operations:

Macros

#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
 EdDSA sign a given block.
 
#define GNUNET_CRYPTO_ecdsa_sign(priv, ps, sig)
 ECDSA sign a given block.
 
#define GNUNET_CRYPTO_edx25519_sign(priv, ps, sig)
 Edx25519 sign a given block.
 
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
 Verify EdDSA signature.
 
#define GNUNET_CRYPTO_ecdsa_verify(purp, ps, sig, pub)
 Verify ECDSA signature.
 
#define GNUNET_CRYPTO_edx25519_verify(purp, ps, sig, pub)
 Verify Edx25519 signature.
 

Functions

void GNUNET_CRYPTO_zero_keys (void *buffer, size_t length)
 Zero out buffer, securely against compiler optimizations.
 
void GNUNET_CRYPTO_random_block (void *buffer, size_t length)
 Fill block with a random values.
 
void GNUNET_CRYPTO_random_timeflake (struct GNUNET_Uuid *uuid)
 Fill UUID with a timeflake pseudo-random value.
 
uint32_t GNUNET_CRYPTO_random_u32 (uint32_t i)
 Produce a random value.
 
uint64_t GNUNET_CRYPTO_random_u64 (uint64_t max)
 Generate a random unsigned 64-bit value.
 
unsigned int * GNUNET_CRYPTO_random_permute (unsigned int n)
 Get an array with a random permutation of the numbers 0...n-1.
 
void GNUNET_CRYPTO_symmetric_create_session_key (struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Create a new random session key.
 
ssize_t GNUNET_CRYPTO_symmetric_encrypt (const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
 Encrypt a block using a symmetric sessionkey.
 
ssize_t GNUNET_CRYPTO_symmetric_decrypt (const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
 Decrypt a given block using a symmetric sessionkey.
 
void GNUNET_CRYPTO_aes_ctr (const void *in_buf, size_t in_buf_len, const unsigned char key[(256/8)], const unsigned char iv[(128/8)], void *out_buf)
 Decrypt or encrypt a given block using a symmetric key using AES in counter mode.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_decrypt (size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
 Encrypt the given data using XSalsa20-Poly1305.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_encrypt (size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
 Encrypt the given data using XSalsa20-Poly1305.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt (size_t ct_len, const unsigned char ct[ct_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, const struct GNUNET_CRYPTO_AeadMac *mac, void *pt)
 Decrypt the given data using XChaCha20-Poly1305.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt (size_t pt_len, const unsigned char pt[pt_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, void *ct, struct GNUNET_CRYPTO_AeadMac *mac)
 Encrypt the given data using XChaCha20-Poly1305.
 
void GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 Derive 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_edx25519_key_get_public (const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, struct GNUNET_CRYPTO_Edx25519PublicKey *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.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
 Create a new private key by reading it from a file.
 
struct GNUNET_CRYPTO_EddsaPrivateKeyGNUNET_CRYPTO_eddsa_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Create a new private key by reading our peer's key from the file specified in the configuration.
 
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.
 
void GNUNET_CRYPTO_edx25519_key_create (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk)
 Create a new private key.
 
void GNUNET_CRYPTO_edx25519_key_create_from_seed (const void *seed, size_t seedsize, struct GNUNET_CRYPTO_Edx25519PrivateKey *pk)
 Create a new private key for Edx25519 from a given seed.
 
void GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
 Create a new 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_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
 Clear memory that was used to store a private key.
 
void GNUNET_CRYPTO_edx25519_key_clear (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk)
 Clear memory that was used to store a private key.
 
void GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
 Clear memory that was used to store a private key.
 
void GNUNET_CRYPTO_private_key_clear (struct GNUNET_CRYPTO_BlindablePrivateKey *pk)
 Clear memory that was used to store a private key.
 
const struct GNUNET_CRYPTO_EcdsaPrivateKeyGNUNET_CRYPTO_ecdsa_key_get_anonymous (void)
 Get the shared private key we use for anonymous users.
 
const struct GNUNET_CRYPTO_EddsaPrivateKeyGNUNET_CRYPTO_eddsa_key_get_anonymous ()
 Get the shared private key we use for anonymous users.
 
void GNUNET_CRYPTO_eddsa_setup_hostkey (const char *cfg_name)
 Setup a hostkey file for a peer given the name of the configuration file (!).
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
 Retrieve the identity of the host's peer.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blinded_key_sign_by_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
 Sign a given block with a specific purpose using the host's peer identity.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity (uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
 Verify a given signature with a peer's identity.
 
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 *pk, struct GNUNET_CRYPTO_EcdhePublicKey *dh)
 Derive key material from a ECDH public key and a private X25519 key.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_decaps (const struct GNUNET_CRYPTO_HpkePrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
 Decapsulate a key for a private X25519 key.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_encaps (const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
 Encapsulate key material for a X25519 public key.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_encaps_norand (const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_HpkePrivateKey *skE, struct GNUNET_ShortHashCode *prk)
 Deterministic variant of GNUNET_CRYPTO_hpke_kem_encaps.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand (uint8_t random_tweak, const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
 Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps (const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
 Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_decaps (const struct GNUNET_CRYPTO_HpkePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
 Carries out ecdh decapsulation with own private key and the representative of the received public key.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
 Decapsulate a key for a private EdDSA key.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_encaps (const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
 Encapsulate key material for a EdDSA public 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_x25519 (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *dh)
 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.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_ (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
 EdDSA sign a given block.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_ (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
 ECDSA Sign a given block.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_edx25519_sign_ (const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_Edx25519Signature *sig)
 Edx25519 sign a given block.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
 Verify EdDSA signature.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 Verify ECDSA signature.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_edx25519_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_Edx25519Signature *sig, const struct GNUNET_CRYPTO_Edx25519PublicKey *pub)
 Verify Edx25519 signature.
 
struct GNUNET_CRYPTO_EcdsaPrivateKeyGNUNET_CRYPTO_ecdsa_private_key_derive (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const char *label, const char *context)
 Derive a private key from a given private key and a label.
 
void GNUNET_CRYPTO_ecdsa_public_key_derive (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EcdsaPublicKey *result)
 Derive a public key from a given public key and a label.
 
void GNUNET_CRYPTO_eddsa_private_key_derive (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPrivateScalar *result)
 Derive a private scalar from a given private key and a label.
 
void GNUNET_CRYPTO_eddsa_public_key_derive (const struct GNUNET_CRYPTO_EddsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPublicKey *result)
 Derive a public key from a given public key and a label.
 
void GNUNET_CRYPTO_edx25519_private_key_derive (const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, const void *seed, size_t seedsize, struct GNUNET_CRYPTO_Edx25519PrivateKey *result)
 Derive a private scalar from a given private key and a label.
 
void GNUNET_CRYPTO_edx25519_public_key_derive (const struct GNUNET_CRYPTO_Edx25519PublicKey *pub, const void *seed, size_t seedsize, struct GNUNET_CRYPTO_Edx25519PublicKey *result)
 Derive a public key from a given public key and a label.
 
void GNUNET_CRYPTO_ecdhe_elligator_decoding (struct GNUNET_CRYPTO_EcdhePublicKey *point, bool *high_y, const struct GNUNET_CRYPTO_ElligatorRepresentative *representative)
 Clears the most significant bit and second most significant bit of the serialized representaive before applying elligator direct map.
 
bool GNUNET_CRYPTO_ecdhe_elligator_encoding (uint8_t random_tweak, struct GNUNET_CRYPTO_ElligatorRepresentative *r, const struct GNUNET_CRYPTO_EcdhePublicKey *pub)
 Encodes a point on Curve25519 to a an element of the underlying finite field.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand (uint8_t random_tweak, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk, struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_ElligatorRepresentative *repr)
 Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdhe_elligator_key_get_public (const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk, struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_ElligatorRepresentative *repr)
 Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point.
 
void GNUNET_CRYPTO_ecdhe_elligator_key_create (struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk)
 Generates a private key for Curve25519.
 

Detailed Description

Provides cryptographic primitives.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_CRYPTO_eddsa_sign

#define GNUNET_CRYPTO_eddsa_sign (   priv,
  ps,
  sig 
)
Value:
do { \
/* check size is set correctly */ \
GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*ps)); \
/* check 'ps' begins with the purpose */ \
GNUNET_static_assert (((void*) (ps)) == \
((void*) &(ps)->purpose)); \
GNUNET_assert (GNUNET_OK == \
&(ps)->purpose, \
sig)); \
} while (0)
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition crypto_ecc.c:646
@ GNUNET_OK

EdDSA sign a given block.

The ps data must be a fixed-size struct for which the signature is to be created. The size field in ps->purpose must correctly indicate the number of bytes of the data structure, including its header.

Parameters
privprivate key to use for the signing
pspacked struct with what to sign, MUST begin with a purpose
[out]sigwhere to write the signature

Definition at line 2883 of file gnunet_crypto_lib.h.

2883 { \
2884 /* check size is set correctly */ \
2885 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*ps)); \
2886 /* check 'ps' begins with the purpose */ \
2887 GNUNET_static_assert (((void*) (ps)) == \
2888 ((void*) &(ps)->purpose)); \
2889 GNUNET_assert (GNUNET_OK == \
2891 &(ps)->purpose, \
2892 sig)); \
2893} while (0)

◆ GNUNET_CRYPTO_ecdsa_sign

#define GNUNET_CRYPTO_ecdsa_sign (   priv,
  ps,
  sig 
)
Value:
do { \
/* check size is set correctly */ \
GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
/* check 'ps' begins with the purpose */ \
GNUNET_static_assert (((void*) (ps)) == \
((void*) &(ps)->purpose)); \
GNUNET_assert (GNUNET_OK == \
&(ps)->purpose, \
sig)); \
} while (0)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
ECDSA Sign a given block.
Definition crypto_ecc.c:575

ECDSA sign a given block.

The ps data must be a fixed-size struct for which the signature is to be created. The size field in ps->purpose must correctly indicate the number of bytes of the data structure, including its header.

Parameters
privprivate key to use for the signing
pspacked struct with what to sign, MUST begin with a purpose
[out]sigwhere to write the signature

Definition at line 2946 of file gnunet_crypto_lib.h.

2946 { \
2947 /* check size is set correctly */ \
2948 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2949 /* check 'ps' begins with the purpose */ \
2950 GNUNET_static_assert (((void*) (ps)) == \
2951 ((void*) &(ps)->purpose)); \
2952 GNUNET_assert (GNUNET_OK == \
2954 &(ps)->purpose, \
2955 sig)); \
2956} while (0)

◆ GNUNET_CRYPTO_edx25519_sign

#define GNUNET_CRYPTO_edx25519_sign (   priv,
  ps,
  sig 
)
Value:
do { \
/* check size is set correctly */ \
GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
/* check 'ps' begins with the purpose */ \
GNUNET_static_assert (((void*) (ps)) == \
((void*) &(ps)->purpose)); \
GNUNET_assert (GNUNET_OK == \
&(ps)->purpose, \
sig)); \
} while (0)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_edx25519_sign_(const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_Edx25519Signature *sig)
Edx25519 sign a given block.

Edx25519 sign a given block.

The resulting signature is compatible with EdDSA.

The ps data must be a fixed-size struct for which the signature is to be created. The size field in ps->purpose must correctly indicate the number of bytes of the data structure, including its header.

Parameters
privprivate key to use for the signing
pspacked struct with what to sign, MUST begin with a purpose
[out]sigwhere to write the signature

Definition at line 2993 of file gnunet_crypto_lib.h.

2993 { \
2994 /* check size is set correctly */ \
2995 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2996 /* check 'ps' begins with the purpose */ \
2997 GNUNET_static_assert (((void*) (ps)) == \
2998 ((void*) &(ps)->purpose)); \
2999 GNUNET_assert (GNUNET_OK == \
3001 &(ps)->purpose, \
3002 sig)); \
3003} while (0)

◆ GNUNET_CRYPTO_eddsa_verify

#define GNUNET_CRYPTO_eddsa_verify (   purp,
  ps,
  sig,
  pub 
)
Value:
({ \
/* check size is set correctly */ \
GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
/* check 'ps' begins with the purpose */ \
GNUNET_static_assert (((void*) (ps)) == \
((void*) &(ps)->purpose)); \
GNUNET_CRYPTO_eddsa_verify_ (purp, \
&(ps)->purpose, \
sig, \
pub); \
})
static struct GNUNET_CRYPTO_EddsaPublicKey pub

Verify EdDSA signature.

The ps data must be a fixed-size struct for which the signature is to be created. The size field in ps->purpose must correctly indicate the number of bytes of the data structure, including its header.

Parameters
purppurpose of the signature, must match 'ps->purpose.purpose' (except in host byte order)
pspacked struct with what to sign, MUST begin with a purpose
sigwhere to write the signature
pubpublic key key to use for the verification

Definition at line 3046 of file gnunet_crypto_lib.h.

3046 { \
3047 /* check size is set correctly */ \
3048 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
3049 /* check 'ps' begins with the purpose */ \
3050 GNUNET_static_assert (((void*) (ps)) == \
3051 ((void*) &(ps)->purpose)); \
3052 GNUNET_CRYPTO_eddsa_verify_ (purp, \
3053 &(ps)->purpose, \
3054 sig, \
3055 pub); \
3056 })

◆ GNUNET_CRYPTO_ecdsa_verify

#define GNUNET_CRYPTO_ecdsa_verify (   purp,
  ps,
  sig,
  pub 
)
Value:
({ \
/* check size is set correctly */ \
GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
/* check 'ps' begins with the purpose */ \
GNUNET_static_assert (((void*) (ps)) == \
((void*) &(ps)->purpose)); \
GNUNET_CRYPTO_ecdsa_verify_ (purp, \
&(ps)->purpose, \
sig, \
pub); \
})

Verify ECDSA signature.

The ps data must be a fixed-size struct for which the signature is to be created. The size field in ps->purpose must correctly indicate the number of bytes of the data structure, including its header.

Parameters
purppurpose of the signature, must match 'ps->purpose.purpose' (except in host byte order)
privprivate key to use for the signing
pspacked struct with what to sign, MUST begin with a purpose
sigwhere to write the signature

Definition at line 3099 of file gnunet_crypto_lib.h.

3099 { \
3100 /* check size is set correctly */ \
3101 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
3102 /* check 'ps' begins with the purpose */ \
3103 GNUNET_static_assert (((void*) (ps)) == \
3104 ((void*) &(ps)->purpose)); \
3105 GNUNET_CRYPTO_ecdsa_verify_ (purp, \
3106 &(ps)->purpose, \
3107 sig, \
3108 pub); \
3109 })

◆ GNUNET_CRYPTO_edx25519_verify

#define GNUNET_CRYPTO_edx25519_verify (   purp,
  ps,
  sig,
  pub 
)
Value:
({ \
/* check size is set correctly */ \
GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
/* check 'ps' begins with the purpose */ \
GNUNET_static_assert (((void*) (ps)) == \
((void*) &(ps)->purpose)); \
GNUNET_CRYPTO_edx25519_verify_ (purp, \
&(ps)->purpose, \
sig, \
pub); \
})

Verify Edx25519 signature.

The ps data must be a fixed-size struct for which the signature is to be created. The size field in ps->purpose must correctly indicate the number of bytes of the data structure, including its header.

Parameters
purppurpose of the signature, must match 'ps->purpose.purpose' (except in host byte order)
privprivate key to use for the signing
pspacked struct with what to sign, MUST begin with a purpose
sigwhere to write the signature

Definition at line 3151 of file gnunet_crypto_lib.h.

3151 { \
3152 /* check size is set correctly */ \
3153 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
3154 /* check 'ps' begins with the purpose */ \
3155 GNUNET_static_assert (((void*) (ps)) == \
3156 ((void*) &(ps)->purpose)); \
3157 GNUNET_CRYPTO_edx25519_verify_ (purp, \
3158 &(ps)->purpose, \
3159 sig, \
3160 pub); \
3161 })

Function Documentation

◆ GNUNET_CRYPTO_zero_keys()

void GNUNET_CRYPTO_zero_keys ( void *  buffer,
size_t  length 
)

Zero out buffer, securely against compiler optimizations.

Used to delete key material.

Parameters
bufferthe buffer to zap
lengthbuffer length

Definition at line 87 of file crypto_random.c.

88{
89#if HAVE_MEMSET_S
90 memset_s (buffer, length, 0, length);
91#elif HAVE_EXPLICIT_BZERO
92 explicit_bzero (buffer, length);
93#else
94 volatile unsigned char *p = buffer;
95 while (length--)
96 *p++ = 0;
97#endif
98}
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38

References p.

Referenced by create_handle(), delete_store_message(), destroy_handle(), GNUNET_PILS_destroy_key_ring(), read_handle_encryption_key(), read_handle_epoch_key(), store_handle_encryption_key(), and store_handle_epoch_key().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_random_block()

void GNUNET_CRYPTO_random_block ( void *  buffer,
size_t  length 
)

◆ GNUNET_CRYPTO_random_timeflake()

void GNUNET_CRYPTO_random_timeflake ( struct GNUNET_Uuid uuid)

Fill UUID with a timeflake pseudo-random value.

Note that timeflakes use only 80 bits of randomness and 48 bits to encode a timestamp in milliseconds. So what we return here is not a completely random number.

Parameters
[out]uuidthe value to fill

Definition at line 151 of file crypto_random.c.

152{
153 struct GNUNET_TIME_Absolute now;
154 uint64_t ms;
155 uint64_t be;
156 char *base;
157
159 sizeof (struct GNUNET_Uuid));
161 ms = now.abs_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
162 be = GNUNET_htonll (ms);
163 base = (char *) &be;
164 memcpy (uuid,
165 base + 2,
166 sizeof (be) - 2);
167}
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
Time for absolute times used by GNUnet, in microseconds.
A UUID, a 128 bit "random" value.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CRYPTO_random_block(), GNUNET_htonll(), GNUNET_TIME_absolute_get(), and GNUNET_TIME_UNIT_MILLISECONDS.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_random_u32()

uint32_t GNUNET_CRYPTO_random_u32 ( uint32_t  i)

Produce a random value.

Parameters
maxthe upper limit (exclusive) for the random number
Returns
a random value in the interval [0,i) (exclusive).

Definition at line 111 of file crypto_random.c.

112{
113 GNUNET_assert (max > 0);
114
115 return randombytes_uniform (max);
116}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define max(x, y)

References GNUNET_assert, and max.

Referenced by allocate_v4_address(), allocate_v6_address(), channel_new_cb(), channel_new_cb(), channel_new_cb(), compute_rand_delay(), compute_service_response(), daemon_started(), delayed_get(), delayed_put(), download_get_url(), generate_request_id(), get_any(), get_bootstrap_server(), get_delay_randomization(), get_forward_count(), get_random_literal(), get_random_peer_from_peermap(), get_randomized_delay(), get_request_socket(), get_typed(), GNUNET_BLOCK_GROUP_bf_create(), GNUNET_CONTAINER_heap_walk_get_next(), GNUNET_CONTAINER_multihashmap_get_random(), GNUNET_CONTAINER_multipeermap_get_random(), GNUNET_CONTAINER_multishortmap_get_random(), GNUNET_CONTAINER_multiuuidmap_get_random(), GNUNET_CRYPTO_random_permute(), GNUNET_FS_search_start_probe_(), GNUNET_TUN_initialize_ipv4_header(), GSC_CLIENTS_deliver_message(), GSF_pending_request_get_message_(), handle_client_evaluate(), handle_client_evaluate(), handle_client_evaluate(), handle_dns_request(), handle_dv_learn(), handle_flow_control(), handle_p2p_get(), handle_p2p_put(), handle_resolve_result(), join_room_run(), ogg_init(), plan(), queue(), queue(), reannounce_regex(), recursive_dns_resolution(), REGEX_TEST_generate_random_regex(), REGEX_TEST_generate_random_string(), resolve_and_cache(), route_control_message_without_fc(), route_via_neighbour(), select_peer(), send_bloomfilter(), send_bloomfilter(), setup_fresh_address(), should_I_drop(), shuffle_answers(), sign_dv_init_cb(), test_run(), and try_open_exit().

◆ GNUNET_CRYPTO_random_u64()

uint64_t GNUNET_CRYPTO_random_u64 ( uint64_t  max)

◆ GNUNET_CRYPTO_random_permute()

unsigned int * GNUNET_CRYPTO_random_permute ( unsigned int  n)

Get an array with a random permutation of the numbers 0...n-1.

Parameters
nthe size of the array
Returns
the permutation array (allocated from heap)

Definition at line 120 of file crypto_random.c.

121{
122 unsigned int *ret;
123 unsigned int i;
124 unsigned int tmp;
125 uint32_t x;
126
127 GNUNET_assert (n > 0);
128 ret = GNUNET_malloc (n * sizeof(unsigned int));
129 for (i = 0; i < n; i++)
130 ret[i] = i;
131 for (i = n - 1; i > 0; i--)
132 {
133 x = GNUNET_CRYPTO_random_u32 (i + 1);
134 tmp = ret[x];
135 ret[x] = ret[i];
136 ret[i] = tmp;
137 }
138 return ret;
139}
static int ret
Final status code.
Definition gnunet-arm.c:93
uint32_t GNUNET_CRYPTO_random_u32(uint32_t max)
Produce a random value.
#define GNUNET_malloc(size)
Wrapper around malloc.

References GNUNET_assert, GNUNET_CRYPTO_random_u32(), GNUNET_malloc, and ret.

Referenced by compute_service_response(), and do_round().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_symmetric_create_session_key()

void GNUNET_CRYPTO_symmetric_create_session_key ( struct GNUNET_CRYPTO_SymmetricSessionKey key)

Create a new random session key.

Parameters
keykey to initialize

Create a new random session key.

Parameters
keysession key to initialize

Definition at line 42 of file crypto_symmetric.c.

45{
46 gcry_randomize (key->aes_key,
48 GCRY_STRONG_RANDOM);
49 gcry_randomize (key->twofish_key,
51 GCRY_STRONG_RANDOM);
52}
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_CRYPTO_AES_KEY_LENGTH
length of the sessionkey in bytes

References GNUNET_CRYPTO_AES_KEY_LENGTH, and key.

◆ GNUNET_CRYPTO_symmetric_encrypt()

ssize_t GNUNET_CRYPTO_symmetric_encrypt ( const void *  block,
size_t  size,
const struct GNUNET_CRYPTO_SymmetricSessionKey sessionkey,
const struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
void *  result 
)

Encrypt a block using a symmetric sessionkey.

Parameters
blockthe block to encrypt
sizethe size of the block
sessionkeythe key used to encrypt
ivthe initialization vector to use, use INITVALUE for streams.
Returns
the size of the encrypted block, -1 for errors

Definition at line 118 of file crypto_symmetric.c.

126{
127 gcry_cipher_hd_t handle;
128 char tmp[GNUNET_NZL (size)];
129
130 if (GNUNET_OK != setup_cipher_aes (&handle, sessionkey, iv))
131 return -1;
132 GNUNET_assert (0 == gcry_cipher_encrypt (handle, tmp, size, block, size));
133 gcry_cipher_close (handle);
134 if (GNUNET_OK != setup_cipher_twofish (&handle, sessionkey, iv))
135 return -1;
136 GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, size, tmp, size));
137 gcry_cipher_close (handle);
138 memset (tmp, 0, sizeof(tmp));
139 return size;
140}
static int setup_cipher_aes(gcry_cipher_hd_t *handle, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Initialize AES cipher.
static int setup_cipher_twofish(gcry_cipher_hd_t *handle, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Initialize TWOFISH cipher.
static int result
Global testing status.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition gnunet-vpn.c:35
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
static unsigned int size
Size of the "table".
Definition peer.c:68

References GNUNET_assert, GNUNET_NZL, GNUNET_OK, handle, result, setup_cipher_aes(), setup_cipher_twofish(), and size.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_symmetric_decrypt()

ssize_t GNUNET_CRYPTO_symmetric_decrypt ( const void *  block,
size_t  size,
const struct GNUNET_CRYPTO_SymmetricSessionKey sessionkey,
const struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
void *  result 
)

Decrypt a given block using a symmetric sessionkey.

Parameters
blockthe data to decrypt, encoded as returned by encrypt
sizehow big is the block?
sessionkeythe key used to decrypt
ivthe initialization vector to use
resultaddress to store the result at
Returns
-1 on failure, size of decrypted block on success

Definition at line 144 of file crypto_symmetric.c.

152{
153 gcry_cipher_hd_t handle;
154 char tmp[size];
155
156 if (GNUNET_OK != setup_cipher_twofish (&handle, sessionkey, iv))
157 return -1;
158 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, block, size));
159 gcry_cipher_close (handle);
160 if (GNUNET_OK != setup_cipher_aes (&handle, sessionkey, iv))
161 return -1;
162 GNUNET_assert (0 == gcry_cipher_decrypt (handle, result, size, tmp, size));
163 gcry_cipher_close (handle);
164 memset (tmp, 0, sizeof(tmp));
165 return size;
166}

References GNUNET_assert, GNUNET_OK, handle, result, setup_cipher_aes(), setup_cipher_twofish(), and size.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_aes_ctr()

void GNUNET_CRYPTO_aes_ctr ( const void *  in_buf,
size_t  in_buf_len,
const unsigned char  key[(256/8)],
const unsigned char  iv[(128/8)],
void *  out_buf 
)

Decrypt or encrypt a given block using a symmetric key using AES in counter mode.

Parameters
in_bufthe data to en/decrypt
in_buf_lenthe size if the data in bytes
keythe AES key to use
ivthe initialization vector to use
out_bufbuffer to store the result at

Referenced by block_create_ecdsa(), and block_decrypt_ecdsa().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_xsalsa20poly1305_decrypt()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_decrypt ( size_t  in_buf_len,
const unsigned char  in_buf[in_buf_len],
const struct GNUNET_CRYPTO_XSalsa20SecretKey key,
const struct GNUNET_CRYPTO_XSalsa20Nonce nonce,
void *  out_buf 
)

Encrypt the given data using XSalsa20-Poly1305.

Used only in GNS, use AEAD API instead!

Parameters
in_bufthe data to encrypt
in_buf_lenthe size if the data in bytes
keythe key to use
noncethe initialization vector to use
out_bufbuffer to store the result at
Returns
GNUNET_OK on success

Definition at line 197 of file crypto_symmetric.c.

203{
204 ssize_t ctlen = in_buf_len - crypto_secretbox_xsalsa20poly1305_MACBYTES;
205 if (ctlen < 0)
206 return GNUNET_SYSERR;
207 if (0 != crypto_secretbox_open_detached (
208 out_buf,
209 in_buf
210 + crypto_secretbox_xsalsa20poly1305_MACBYTES, // Ciphertext
211 in_buf, // Tag
212 ctlen,
213 nonce->nonce,
214 key->key))
215 {
216 return GNUNET_SYSERR;
217 }
218 return GNUNET_OK;
219
220}
@ GNUNET_SYSERR
unsigned char nonce[24]
Initialization vector.

References GNUNET_OK, GNUNET_SYSERR, key, and GNUNET_CRYPTO_XSalsa20Nonce::nonce.

Referenced by block_decrypt_eddsa().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_xsalsa20poly1305_encrypt()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_encrypt ( size_t  in_buf_len,
const unsigned char  in_buf[in_buf_len],
const struct GNUNET_CRYPTO_XSalsa20SecretKey key,
const struct GNUNET_CRYPTO_XSalsa20Nonce nonce,
void *  out_buf 
)

Encrypt the given data using XSalsa20-Poly1305.

Used only in GNS, use AEAD API instead!

Parameters
in_bufthe data to encrypt
in_buf_lenthe size if the data in bytes
keythe key to use
noncethe initialization vector to use
out_bufbuffer to store the result at
Returns
GNUNET_OK on success

Definition at line 224 of file crypto_symmetric.c.

230{
231 if (in_buf_len > crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX)
232 return GNUNET_SYSERR;
233 crypto_secretbox_detached (out_buf
234 + crypto_secretbox_xsalsa20poly1305_MACBYTES, // Ciphertext
235 out_buf, // TAG
236 in_buf,
237 in_buf_len,
238 nonce->nonce,
239 key->key);
240 return GNUNET_OK;
241}

References GNUNET_OK, GNUNET_SYSERR, key, and GNUNET_CRYPTO_XSalsa20Nonce::nonce.

Referenced by block_create_eddsa().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_aead_decrypt()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt ( size_t  ct_len,
const unsigned char  ct[ct_len],
size_t  aad_len,
const unsigned char  aad[aad_len],
const struct GNUNET_CRYPTO_AeadSecretKey key,
const struct GNUNET_CRYPTO_AeadNonce nonce,
const struct GNUNET_CRYPTO_AeadMac mac,
void *  pt 
)

Decrypt the given data using XChaCha20-Poly1305.

Parameters
ct_lenthe size of ct in bytes
ctthe data to decrypt
aad_lenthe size of additional data in bytes (may be 0)
aadthe additional data (may be NULL)
keythe key to use
noncethe initialization vector to use
macthe mac to use
ptbuffer to store the plaintext result at. Must be at least ct_len
Returns
GNUNET_OK on success, else the mac was invalid

Definition at line 245 of file crypto_symmetric.c.

254{
255 if (0 != crypto_aead_xchacha20poly1305_ietf_decrypt_detached (
256 pt,
257 NULL,
258 ct, // Tag
259 ct_len,
260 mac->mac,
261 aad,
262 aad_len,
263 nonce->npub,
264 key->k))
265 {
266 return GNUNET_SYSERR;
267 }
268 return GNUNET_OK;
269
270}
unsigned char mac[16]
Initialization vector.
unsigned char npub[24]
Initialization vector.

References GNUNET_OK, GNUNET_SYSERR, key, GNUNET_CRYPTO_AeadMac::mac, and GNUNET_CRYPTO_AeadNonce::npub.

Referenced by decaps_dv_box_cb(), decrypt_secret_message(), extract_authorization_message_key(), GNUNET_FS_ublock_decrypt_(), process_result_with_request(), read_handle_encryption_key(), read_handle_epoch_key(), t_ax_decrypt(), t_h_decrypt(), and try_old_ax_keys().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_aead_encrypt()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt ( size_t  pt_len,
const unsigned char  pt[pt_len],
size_t  aad_len,
const unsigned char  aad[aad_len],
const struct GNUNET_CRYPTO_AeadSecretKey key,
const struct GNUNET_CRYPTO_AeadNonce nonce,
void *  ct,
struct GNUNET_CRYPTO_AeadMac mac 
)

Encrypt the given data using XChaCha20-Poly1305.

Use random, independent keys for each target endpoint (and direction). Use unique nonces for each message.

This schemes allows you to choose a random nonce for every encrypted message. (Background: Some schemes require unique nonces, but their nonces are too short to choose them safely randomly (i.e. they may statistically collide).

Parameters
pt_lenthe size if the data in bytes
ptthe data to encrypt
aad_lenthe size of additional data in bytes (may be 0)
aadthe additional data (may be NULL)
keythe key to use
noncethe initialization vector to use
ctbuffer to store the ciphertext result at. Must be at least pt_len.
macbuffer to store the mac result at
Returns
GNUNET_OK on success

Definition at line 274 of file crypto_symmetric.c.

283{
284 crypto_aead_xchacha20poly1305_ietf_encrypt_detached (ct, // Ciphertext
285 mac->mac, // TAG
286 NULL,
287 pt,
288 pt_len,
289 aad,
290 aad_len,
291 NULL,
292 nonce->npub,
293 key->k);
294 return GNUNET_OK;
295}

References GNUNET_OK, key, GNUNET_CRYPTO_AeadMac::mac, and GNUNET_CRYPTO_AeadNonce::npub.

Referenced by create_message_authorization(), encapsulate_for_dv(), encrypt_existing_match(), encrypt_secret_message(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_publish_ublock_(), GNUNET_FS_tree_encoder_next(), store_handle_encryption_key(), store_handle_epoch_key(), t_ax_encrypt(), t_h_encrypt(), and try_match_block().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_key_get_public()

void GNUNET_CRYPTO_ecdsa_key_get_public ( const struct GNUNET_CRYPTO_EcdsaPrivateKey priv,
struct GNUNET_CRYPTO_EcdsaPublicKey pub 
)

Derive key.

Parameters
resultbuffer for the derived key, allocated by caller
out_lendesired length of the derived key
xtssalt
xts_lenlength of xts
skmsource key material
skm_lenlength of skm
...void * & size_t pairs for context chunks
Returns
GNUNET_YES on success

Extract the public key for the given private key.

Parameters
privthe special elligator private key
pubwhere to write the public key

Definition at line 191 of file crypto_ecc.c.

194{
195 BENCHMARK_START (ecdsa_key_get_public);
196 crypto_scalarmult_ed25519_base_noclamp (pub->q_y, priv->d);
197 BENCHMARK_END (ecdsa_key_get_public);
198}
#define BENCHMARK_START(opname)
Definition benchmark.h:57
#define BENCHMARK_END(opname)
Definition benchmark.h:58
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
unsigned char q_y[256/8]
Point Q consists of a y-value mod p (256 bits); the x-value is always positive.

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_EcdsaPrivateKey::d, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by block_create2(), GNUNET_CRYPTO_blindable_key_get_public(), and GNUNET_CRYPTO_ecdsa_private_key_derive().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_key_get_public()

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.

Parameters
privthe private key
pubwhere to write the public key

Definition at line 202 of file crypto_ecc.c.

205{
206 unsigned char pk[crypto_sign_PUBLICKEYBYTES];
207 unsigned char sk[crypto_sign_SECRETKEYBYTES];
208
209 BENCHMARK_START (eddsa_key_get_public);
210 GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
211 GNUNET_memcpy (pub->q_y, pk, crypto_sign_PUBLICKEYBYTES);
212 sodium_memzero (sk, crypto_sign_SECRETKEYBYTES);
213 BENCHMARK_END (eddsa_key_get_public);
214}
struct GNUNET_CRYPTO_BlindablePrivateKey pk
Private key from command line option, or NULL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_EddsaPrivateKey::d, GNUNET_assert, GNUNET_memcpy, pk, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by block_create2(), checkvec(), create_keys(), decrypt_block_with_keyword(), do_generate_pid(), get_update_information_directory(), GNUNET_CRYPTO_blindable_key_get_public(), GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_CRYPTO_get_peer_identity(), GNUNET_FS_publish_sks(), GNUNET_FS_publish_ublock_(), GNUNET_FS_search_start_searching_(), GNUNET_FS_unindex_do_remove_kblocks_(), GNUNET_FS_uri_loc_create(), output_vectors(), pid_change_cb(), print_key(), process_kblock_for_unindex(), run(), run(), and run().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_key_get_public()

void GNUNET_CRYPTO_edx25519_key_get_public ( const struct GNUNET_CRYPTO_Edx25519PrivateKey priv,
struct GNUNET_CRYPTO_Edx25519PublicKey pub 
)

Extract the public key for the given private key.

Parameters
privthe private key
pubwhere to write the public key

Definition at line 77 of file crypto_edx25519.c.

80{
81 crypto_scalarmult_ed25519_base_noclamp (pub->q_y,
82 priv->a);
83}
unsigned char a[256/8]
a is a value mod n, where n has at most 256 bits.

References GNUNET_CRYPTO_Edx25519PrivateKey::a, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by GNUNET_CRYPTO_edx25519_private_key_derive(), and output_vectors().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdhe_key_get_public()

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.

Parameters
privthe private key
pubwhere to write the public key

Definition at line 218 of file crypto_ecc.c.

221{
222 BENCHMARK_START (ecdhe_key_get_public);
223 GNUNET_assert (0 == crypto_scalarmult_base (pub->q_y, priv->d));
224 BENCHMARK_END (ecdhe_key_get_public);
225}
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_assert, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by cont_GCT_handle_kx_auth(), create_message_announcement(), create_message_appeal(), GCT_send(), GNUNET_CRYPTO_hpke_kem_encaps_norand(), GNUNET_CRYPTO_hpke_sk_get_public(), output_vectors(), print_examples_ecdh(), send_initiator_hello(), send_kx(), and send_kx_auth().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_key_from_file()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file ( const char *  filename,
int  do_create,
struct GNUNET_CRYPTO_EddsaPrivateKey pkey 
)

Create a new private key by reading it from a file.

If the files does not exist and do_create is set, creates a new key and write it to the file.

If the contents of the file are invalid, an error is returned.

Parameters
filenamename of file to use to store the key
do_createshould a file be created?
[out]pkeyset to the private key from filename on success
Returns
GNUNET_OK on success, GNUNET_NO if do_create was set but we found an existing file, GNUNET_SYSERR on failure

If the files does not exist and do_create is set, creates a new key and write it to the file.

If the contents of the file are invalid, an error is returned.

Parameters
filenamename of file to use to store the key
do_createshould a file be created?
[out]pkeyset to the private key from filename on success
Returns
- GNUNET_OK on success,
  • GNUNET_NO if do_create was set but we found an existing file,
  • GNUNET_SYSERR on failure or if the file didn't exist and do_create was not set

Definition at line 145 of file crypto_ecc_setup.c.

148{
150
151 if (GNUNET_OK ==
153 pkey,
154 sizeof (*pkey)))
155 {
156 /* file existed, report that we didn't create it... */
157 return (do_create) ? GNUNET_NO : GNUNET_OK;
158 }
159 else if (! do_create)
160 {
161 return GNUNET_SYSERR;
162 }
163
166 pkey,
167 sizeof (*pkey),
169 if ( (GNUNET_OK == ret) ||
170 (GNUNET_SYSERR == ret) )
171 return ret;
172 /* maybe another process succeeded in the meantime, try reading one more time */
173 if (GNUNET_OK ==
175 pkey,
176 sizeof (*pkey)))
177 {
178 /* file existed, report that *we* didn't create it... */
179 return GNUNET_NO;
180 }
181 /* give up */
182 return GNUNET_SYSERR;
183}
static enum GNUNET_GenericReturnValue read_from_file(const char *filename, void *buf, size_t buf_size)
Read file to buf.
static char * filename
static char * pkey
Public key of the zone to look in, in ASCII.
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
Definition crypto_ecc.c:479
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition disk.c:792
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO

References filename, GNUNET_CRYPTO_eddsa_key_create(), GNUNET_DISK_fn_write(), GNUNET_DISK_PERM_USER_READ, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, pkey, read_from_file(), and ret.

Referenced by GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_PILS_create_key_ring(), load_ikm(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_key_create_from_configuration()

struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration ( const struct GNUNET_CONFIGURATION_Handle cfg)

Create a new private key by reading our peer's key from the file specified in the configuration.

Parameters
cfgthe configuration to use
Returns
new private key, NULL on error (for example, permission denied); free using GNUNET_free
Parameters
cfgthe configuration to use
Returns
new private key, NULL on error (for example, permission denied)

Definition at line 195 of file crypto_ecc_setup.c.

197{
199 char *fn;
200
201 if (GNUNET_OK !=
203 "PEER",
204 "PRIVATE_KEY",
205 &fn))
206 return NULL;
210 priv))
211 {
212 GNUNET_free (fn);
213 GNUNET_free (priv);
214 return NULL;
215 }
216 GNUNET_free (fn);
217 return priv;
218}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file(const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
Create a new private key by reading it from a file.
@ GNUNET_YES
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
Private ECC key encoded for transmission.

References cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_SYSERR, and GNUNET_YES.

Referenced by GNUNET_CRYPTO_blinded_key_sign_by_peer_identity(), GNUNET_CRYPTO_get_peer_identity(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_key_create()

void GNUNET_CRYPTO_ecdsa_key_create ( struct GNUNET_CRYPTO_EcdsaPrivateKey pk)

Create a new private key.

Parameters
[out]pkprivate key to initialize

Definition at line 465 of file crypto_ecc.c.

466{
467 BENCHMARK_START (ecdsa_key_create);
469 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
470 pk->d[0] &= 248;
471 pk->d[31] &= 127;
472 pk->d[31] |= 64;
473
474 BENCHMARK_END (ecdsa_key_create);
475}
Private ECC key encoded for transmission.

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_random_block(), and pk.

Referenced by private_key_create(), and run_pkey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_key_create()

void GNUNET_CRYPTO_eddsa_key_create ( struct GNUNET_CRYPTO_EddsaPrivateKey pk)

Create a new private key.

Parameters
[out]pkprivate key to initialize

Definition at line 479 of file crypto_ecc.c.

480{
481 BENCHMARK_START (eddsa_key_create);
482 /*
483 * We do not clamp for EdDSA, since all functions that use the private key do
484 * their own clamping (just like in libsodium). What we call "private key"
485 * here, actually corresponds to the seed in libsodium.
486 *
487 * (Contrast this to ECDSA, where functions using the private key can't clamp
488 * due to properties needed for GNS. That is a worse/unsafter API, but
489 * required for the GNS constructions to work.)
490 */
492 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
493 BENCHMARK_END (eddsa_key_create);
494}

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_random_block(), and pk.

Referenced by create_keys(), GNUNET_CRYPTO_eddsa_key_from_file(), output_vectors(), private_key_create(), and run_edkey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_key_create()

void GNUNET_CRYPTO_edx25519_key_create ( struct GNUNET_CRYPTO_Edx25519PrivateKey pk)

Create a new private key.

Parameters
[out]pkprivate key to initialize

Definition at line 64 of file crypto_edx25519.c.

66{
67 char seed[256 / 8];
69 sizeof (seed));
71 sizeof(seed),
72 pk);
73}
static uint8_t seed
void GNUNET_CRYPTO_edx25519_key_create_from_seed(const void *seed, size_t seedsize, struct GNUNET_CRYPTO_Edx25519PrivateKey *pk)
Create a new private key for Edx25519 from a given seed.

References GNUNET_CRYPTO_edx25519_key_create_from_seed(), GNUNET_CRYPTO_random_block(), pk, and seed.

Referenced by output_vectors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_key_create_from_seed()

void GNUNET_CRYPTO_edx25519_key_create_from_seed ( const void *  seed,
size_t  seedsize,
struct GNUNET_CRYPTO_Edx25519PrivateKey pk 
)

Create a new private key for Edx25519 from a given seed.

After expanding the seed, the first half of the key will be clamped according to EdDSA.

Parameters
seedseed input
seedsizesize of the seed in bytes
[out]pkprivate key to initialize

Definition at line 44 of file crypto_edx25519.c.

48{
49
50 GNUNET_static_assert (sizeof(*pk) == sizeof(struct GNUNET_HashCode));
52 seedsize,
53 (struct GNUNET_HashCode *) pk);
54
55 /* Clamp the first half of the key. The second half is used in the signature
56 * process. */
57 pk->a[0] &= 248;
58 pk->a[31] &= 127;
59 pk->a[31] |= 64;
60}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
#define GNUNET_static_assert(cond)
Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime an...
A 512-bit hashcode.

References GNUNET_CRYPTO_hash(), GNUNET_static_assert, pk, and seed.

Referenced by GNUNET_CRYPTO_edx25519_key_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdhe_key_create()

void GNUNET_CRYPTO_ecdhe_key_create ( struct GNUNET_CRYPTO_EcdhePrivateKey pk)

Create a new private key.

Clear with GNUNET_CRYPTO_ecdhe_key_clear(). This is X25519 DH (RFC 7748 Section 5) and corresponds to X25519(a,9). See GNUNET_CRYPTO_ecc_ecdh for the DH function.

Parameters
[out]pkset to fresh private key;

Definition at line 455 of file crypto_ecc.c.

456{
457 BENCHMARK_START (ecdhe_key_create);
459 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
460 BENCHMARK_END (ecdhe_key_create);
461}
Private ECC key encoded for transmission.

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_random_block(), and pk.

Referenced by GCT_create_tunnel(), get_epoch_private_key(), GNUNET_CRYPTO_hpke_kem_encaps(), GNUNET_CRYPTO_hpke_sender_setup(), new_ephemeral(), output_vectors(), print_examples_ecdh(), and send_initiator_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_key_clear()

void GNUNET_CRYPTO_eddsa_key_clear ( struct GNUNET_CRYPTO_EddsaPrivateKey pk)

Clear memory that was used to store a private key.

Parameters
pklocation of the key

Definition at line 448 of file crypto_ecc.c.

449{
451}
static void buffer_clear(void *buf, size_t len)
Definition crypto_ecc.c:419

References buffer_clear(), and pk.

Referenced by GNUNET_CRYPTO_blinded_key_sign_by_peer_identity(), GNUNET_CRYPTO_private_key_clear(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_key_clear()

void GNUNET_CRYPTO_ecdsa_key_clear ( struct GNUNET_CRYPTO_EcdsaPrivateKey pk)

Clear memory that was used to store a private key.

Parameters
pklocation of the key

Definition at line 441 of file crypto_ecc.c.

442{
444}

References buffer_clear(), and pk.

Referenced by GNUNET_CRYPTO_private_key_clear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_key_clear()

void GNUNET_CRYPTO_edx25519_key_clear ( struct GNUNET_CRYPTO_Edx25519PrivateKey pk)

Clear memory that was used to store a private key.

Parameters
pklocation of the key

Definition at line 37 of file crypto_edx25519.c.

38{
39 memset (pk, 0, sizeof(struct GNUNET_CRYPTO_Edx25519PrivateKey));
40}
Private ECC key material encoded for transmission.

References pk.

◆ GNUNET_CRYPTO_ecdhe_key_clear()

void GNUNET_CRYPTO_ecdhe_key_clear ( struct GNUNET_CRYPTO_EcdhePrivateKey pk)

Clear memory that was used to store a private key.

Parameters
pklocation of the key

Definition at line 434 of file crypto_ecc.c.

435{
437}

References buffer_clear(), and pk.

Referenced by cleanup_ax(), and GNUNET_CRYPTO_hpke_sk_clear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_private_key_clear()

void GNUNET_CRYPTO_private_key_clear ( struct GNUNET_CRYPTO_BlindablePrivateKey pk)

Clear memory that was used to store a private key.

Parameters
pklocation of the key

Definition at line 49 of file crypto_pkey.c.

50{
51 switch (ntohl (key->type))
52 {
55 break;
58 break;
59 default:
60 GNUNET_break (0);
61 }
62}
void GNUNET_CRYPTO_eddsa_key_clear(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition crypto_ecc.c:448
void GNUNET_CRYPTO_ecdsa_key_clear(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition crypto_ecc.c:441
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_CRYPTO_ecdsa_key_clear(), GNUNET_CRYPTO_eddsa_key_clear(), GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, and key.

Referenced by dequeue_message_from_room(), and GNUNET_MESSENGER_set_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_key_get_anonymous()

const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_key_get_anonymous ( void  )

Get the shared private key we use for anonymous users.

Returns
"anonymous" private key; do not free

'anonymous' pseudonym (global static, d=1, public key = G (generator).

Definition at line 498 of file crypto_ecc.c.

499{
504 static struct GNUNET_CRYPTO_EcdsaPrivateKey anonymous;
505 static int once;
506
507 if (once)
508 return &anonymous;
510 sizeof(anonymous.d),
511 GCRYMPI_CONST_ONE);
512 anonymous.d[0] &= 248;
513 anonymous.d[31] &= 127;
514 anonymous.d[31] |= 64;
515
516 once = 1;
517 return &anonymous;
518}
static int once
Option -i.
Definition gnunet-pils.c:39
void GNUNET_CRYPTO_mpi_print_unsigned(void *buf, size_t size, gcry_mpi_t val)
Output the given MPI value to the given buffer in network byte order.
Definition crypto_mpi.c:79

References GNUNET_CRYPTO_EcdsaPrivateKey::d, GNUNET_CRYPTO_mpi_print_unsigned(), and once.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_eddsa_key_get_anonymous()

const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_get_anonymous ( )

Get the shared private key we use for anonymous users.

Returns
"anonymous" private key; do not free

'anonymous' pseudonym (global static, d=1, public key = G (generator).

Definition at line 522 of file crypto_ecc.c.

523{
528 static struct GNUNET_CRYPTO_EddsaPrivateKey anonymous;
529 static int once;
530
531 if (once)
532 return &anonymous;
533
534 memset (anonymous.d, 0, sizeof(anonymous.d));
535
536 // Set the first byte to 1 (Little-Endian representation of 1)
537 anonymous.d[0] = 1;
538
539 once = 1;
540 return &anonymous;
541}

References GNUNET_CRYPTO_EddsaPrivateKey::d, and once.

Referenced by decrypt_block_with_keyword(), GNUNET_FS_search_start_searching_(), GNUNET_FS_unindex_do_remove_kblocks_(), GNUNET_IDENTITY_ego_get_anonymous(), process_kblock_for_unindex(), and publish_ksk_cont().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_setup_hostkey()

void GNUNET_CRYPTO_eddsa_setup_hostkey ( const char *  cfg_name)

Setup a hostkey file for a peer given the name of the configuration file (!).

This function is used so that at a later point code can be certain that reading a hostkey is fast (for example in time-dependent testcases).

Parameters
cfg_namename of the configuration file to use

◆ GNUNET_CRYPTO_get_peer_identity()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_get_peer_identity ( const struct GNUNET_CONFIGURATION_Handle cfg,
struct GNUNET_PeerIdentity dst 
)

Retrieve the identity of the host's peer.

Parameters
cfgconfiguration to use
dstpointer to where to write the peer identity
Returns
GNUNET_OK on success, GNUNET_SYSERR if the identity could not be retrieved

Definition at line 222 of file crypto_ecc_setup.c.

224{
226
228 {
230 _ ("Could not load peer's private key\n"));
231 return GNUNET_SYSERR;
232 }
234 &dst->public_key);
235 GNUNET_free (priv);
236 return GNUNET_OK;
237}
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.
Definition crypto_ecc.c:202
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
#define _(String)
GNU gettext support macro.
Definition platform.h:179
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References _, cfg, GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and GNUNET_PeerIdentity::public_key.

Referenced by DHTU_ip_init(), get_result_iterator(), GNUNET_CONVERSATION_phone_create(), run(), run(), run(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_blinded_key_sign_by_peer_identity()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blinded_key_sign_by_peer_identity ( const struct GNUNET_CONFIGURATION_Handle cfg,
const struct GNUNET_CRYPTO_SignaturePurpose purpose,
struct GNUNET_CRYPTO_EddsaSignature sig 
)

Sign a given block with a specific purpose using the host's peer identity.

Parameters
cfgconfiguration to use
purposewhat to sign (size, purpose)
sigwhere to write the signature
Returns
GNUNET_OK on success, GNUNET_SYSERR if the identity could not be retrieved

Definition at line 241 of file crypto_ecc_setup.c.

250{
253
255 {
257 _ ("Could not load peer's private key\n"));
258 return GNUNET_SYSERR;
259 }
260
261 result = GNUNET_CRYPTO_eddsa_sign_ (priv, purpose, sig);
263 return result;
264}

References _, cfg, GNUNET_CRYPTO_eddsa_key_clear(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_sign_(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SYSERR, and result.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_verify_peer_identity()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity ( uint32_t  purpose,
const struct GNUNET_CRYPTO_SignaturePurpose validate,
const struct GNUNET_CRYPTO_EddsaSignature sig,
const struct GNUNET_PeerIdentity identity 
)

Verify a given signature with a peer's identity.

Parameters
purposewhat is the purpose that the signature should have?
validateblock to validate (size, purpose, data)
sigsignature that is being validated
identitythe peer's identity to verify
Returns
GNUNET_OK if ok, GNUNET_SYSERR if invalid

Definition at line 268 of file crypto_ecc_setup.c.

274{
275 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate, sig,
276 &identity->public_key);
277}
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition crypto_ecc.c:729

References GNUNET_CRYPTO_eddsa_verify_(), and identity.

Referenced by verify_message_by_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_ecdh()

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.

This is X25519 DH (RFC 7748 Section 5) and corresponds to H(X25519(b,X25519(a,9))) where b := priv, pub := X25519(a,9), and a := GNUNET_CRYPTO_ecdhe_key_create().

Parameters
privprivate key to use for the ECDH (x)
pubpublic key to use for the ECDH (yG)
key_materialwhere to write the key material (xyG)
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 753 of file crypto_ecc.c.

756{
757 uint8_t p[crypto_scalarmult_BYTES];
758 if (0 != crypto_scalarmult (p, priv->d, pub->q_y))
759 return GNUNET_SYSERR;
760 GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
761 return GNUNET_OK;
762}

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_CRYPTO_hash(), GNUNET_OK, GNUNET_SYSERR, p, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by checkvec(), output_vectors(), print_examples_ecdh(), t_ax_decrypt_and_validate(), t_ax_encrypt(), and update_ax_by_kx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_ecdh()

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.

Dual to #GNUNET_CRRYPTO_ecdh_eddsa. This uses the Ed25519 private seed as X25519 seed. As such, this also is a X25519 DH (see GNUNET_CRYPTO_ecc_ecdh). NOTE: Whenever you can get away with it, use separate key pairs for signing and encryption (DH)!

Parameters
privprivate key from EdDSA to use for the ECDH (x)
pubpublic key to use for the ECDH (yG)
key_materialwhere to write the key material H(h(x)yG)
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 766 of file crypto_ecc.c.

769{
770 struct GNUNET_HashCode hc;
771 uint8_t a[crypto_scalarmult_SCALARBYTES];
772 uint8_t p[crypto_scalarmult_BYTES];
773
774 GNUNET_CRYPTO_hash (priv,
775 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
776 &hc);
777 memcpy (a, &hc, sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
778 if (0 != crypto_scalarmult (p, a, pub->q_y))
779 return GNUNET_SYSERR;
781 crypto_scalarmult_BYTES,
782 key_material);
783 return GNUNET_OK;
784}

References GNUNET_CRYPTO_hash(), GNUNET_OK, GNUNET_SYSERR, p, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by handle_ecdh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_x25519_ecdh()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_x25519_ecdh ( const struct GNUNET_CRYPTO_EcdhePrivateKey sk,
const struct GNUNET_CRYPTO_EcdhePublicKey pk,
struct GNUNET_CRYPTO_EcdhePublicKey dh 
)

Derive key material from a ECDH public key and a private X25519 key.

Dual to #GNUNET_CRRYPTO_ecdh_x25519. NOTE: Whenever you can get away with it, use separate key pairs for signing and encryption (DH)!

Parameters
skprivate key from X25519 to use for the ECDH (x)
pkpublic key to use for the ECDH (yG)
additional_datathis is fed into HKDF-Extract along with the ECDH shared secret
ad_lenLength of the additional data
dhthe DH shared secret (NOTE: Derive key from this before use!)
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 788 of file crypto_ecc.c.

791{
792 uint64_t checkbyte = 0;
793 size_t num_words = sizeof *dh / sizeof (uint64_t);
794 if (0 != crypto_scalarmult_curve25519 (dh->q_y, sk->d, pub->q_y))
795 return GNUNET_SYSERR;
796 // We need to check if this is the all-zero value
797 for (int i = 0; i < num_words; i++)
798 checkbyte |= ((uint64_t*) dh)[i];
799 return (0 == checkbyte) ? GNUNET_SYSERR : GNUNET_OK;
800}
unsigned char q_y[256/8]
Q consists of an x- and a y-value, each mod p (256 bits), given here in affine coordinates and Ed2551...

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_OK, GNUNET_SYSERR, pub, GNUNET_CRYPTO_EddsaPublicKey::q_y, and GNUNET_CRYPTO_EcdhePublicKey::q_y.

Referenced by GNUNET_CRYPTO_hpke_elligator_kem_decaps(), and GNUNET_CRYPTO_hpke_kem_decaps().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_kem_decaps()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_decaps ( const struct GNUNET_CRYPTO_HpkePrivateKey priv,
const struct GNUNET_CRYPTO_HpkeEncapsulation c,
struct GNUNET_ShortHashCode prk 
)

Decapsulate a key for a private X25519 key.

Dual to GNUNET_CRYPTO_hpke_kem_encaps. Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
privprivate key from X25519 to use for the ECDH (x)
cthe encapsulated key
prkwhere to write the key material
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 262 of file crypto_hpke.c.

266{
268 uint8_t kem_context[sizeof *c + crypto_scalarmult_curve25519_BYTES];
269 uint8_t pkR[crypto_scalarmult_BYTES];
270
271 // pkE = DeserializePublicKey(enc) is a NOP, see Section 7.1.1
272 // dh = DH(skR, pkE)
273 if (GNUNET_OK !=
274 GNUNET_CRYPTO_x25519_ecdh (&skR->ecdhe_key,
276 &dh.ecdhe_key))
277 return GNUNET_SYSERR; // ValidationError
278
279 // pkRm = DeserializePublicKey(pk(skR)) is a NOP, see Section 7.1.1
280 crypto_scalarmult_curve25519_base (pkR,
281 skR->ecdhe_key.d);
282 // kem_context = concat(enc, pkRm)
283 memcpy (kem_context, c, sizeof *c);
284 memcpy (kem_context + sizeof *c, pkR, sizeof pkR);
285 // shared_secret = ExtractAndExpand(dh, kem_context)
287 &dh.ecdhe_key, sizeof dh.ecdhe_key,
288 "HPKE-v1",
289 "HPKE-v1",
290 "eae_prk", strlen ("eae_prk"),
291 "shared_secret", strlen ("shared_secret"),
292 kem_context, sizeof kem_context,
295 shared_secret);
296}
static uint8_t GNUNET_CRYPTO_HPKE_KEM_SUITE_ID[]
static enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_labeled_extract_and_expand(const void *dh, size_t dh_len, const char *extract_ctx, const char *expand_ctx, const void *extract_lbl, size_t extract_lbl_len, const void *expand_lbl, size_t expand_lbl_len, const uint8_t *kem_context, size_t kem_context_len, const uint8_t *suite_id, size_t suite_id_len, struct GNUNET_ShortHashCode *shared_secret)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_x25519_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *sk, const struct GNUNET_CRYPTO_EcdhePublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *dh)
Derive key material from a ECDH public key and a private X25519 key.
Definition crypto_ecc.c:788
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
A public key used for encryption.

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_CRYPTO_HpkePrivateKey::ecdhe_key, GNUNET_CRYPTO_HpkePublicKey::ecdhe_key, GNUNET_CRYPTO_HPKE_KEM_SUITE_ID, GNUNET_CRYPTO_hpke_labeled_extract_and_expand(), GNUNET_CRYPTO_x25519_ecdh(), GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_CRYPTO_eddsa_kem_decaps(), GNUNET_CRYPTO_hpke_receiver_setup2(), and handle_responder_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_kem_encaps()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_encaps ( const struct GNUNET_CRYPTO_HpkePublicKey pkR,
struct GNUNET_CRYPTO_HpkeEncapsulation c,
struct GNUNET_ShortHashCode prk 
)

Encapsulate key material for a X25519 public key.

Dual to GNUNET_CRYPTO_hpke_kem_decaps. Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
pkRpublic key of receiver
cpublic key from X25519 to use for the ECDH (X=h(x)G)
prkwhere to write the key material
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 232 of file crypto_hpke.c.

236{
238 // skE, pkE = GenerateKeyPair()
239 GNUNET_CRYPTO_ecdhe_key_create (&skE.ecdhe_key);
240
241 return GNUNET_CRYPTO_hpke_kem_encaps_norand (pub, c, &skE, shared_secret);
242}
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition crypto_ecc.c:455
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_encaps_norand(const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_HpkePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
Deterministic variant of GNUNET_CRYPTO_hpke_kem_encaps.
A public key used for decryption.

References GNUNET_CRYPTO_HpkePrivateKey::ecdhe_key, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_hpke_kem_encaps_norand(), and pub.

Referenced by GNUNET_CRYPTO_eddsa_kem_encaps(), and send_responder_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_kem_encaps_norand()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_encaps_norand ( const struct GNUNET_CRYPTO_HpkePublicKey pkR,
struct GNUNET_CRYPTO_HpkeEncapsulation c,
const struct GNUNET_CRYPTO_HpkePrivateKey skE,
struct GNUNET_ShortHashCode prk 
)

Deterministic variant of GNUNET_CRYPTO_hpke_kem_encaps.

Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
pkRpublic key of receiver
cpublic key from X25519 to use for the ECDH (X=h(x)G)
skEephemeral private key from X25519 to use
prkwhere to write the key material
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 211 of file crypto_hpke.c.

216{
217 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pk;
218 // enc = SerializePublicKey(pkE) is a NOP, see Section 7.1.1
220 &skE->ecdhe_key,
221 &ecdh_pk);
223 ecdh_pk.q_y,
224 sizeof ecdh_pk.q_y);
227 pkR, enc, skE, shared_secret);
228}
static enum GNUNET_GenericReturnValue kem_encaps_norand(uint8_t *suite_id, size_t suite_id_len, const struct GNUNET_CRYPTO_HpkePublicKey *pkR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_HpkePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
static OpusEncoder * enc
OPUS encoder.
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.
Definition crypto_ecc.c:218
struct GNUNET_CRYPTO_EcdhePrivateKey ecdhe_key
An ECDHE/X25519 key.

References GNUNET_CRYPTO_HpkePrivateKey::ecdhe_key, enc, GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_HPKE_KEM_SUITE_ID, GNUNET_memcpy, kem_encaps_norand(), and GNUNET_CRYPTO_EcdhePublicKey::q_y.

Referenced by GNUNET_CRYPTO_hpke_kem_encaps(), and GNUNET_CRYPTO_hpke_sender_setup2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand ( uint8_t  random_tweak,
const struct GNUNET_CRYPTO_HpkePublicKey pkR,
struct GNUNET_CRYPTO_HpkeEncapsulation c,
const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey skE,
struct GNUNET_ShortHashCode shared_secret 
)

Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair.

Following the terminology in https://eprint.iacr.org/2021/509.pdf. Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
random_tweakrandom 8-bit value used as seed
pkRpublic key of receiver
crepresentative of ephemeral public key A to use for the ECDH (direct_map(r)=A=aG)
skEspecial elligator ephemeral private key from X25519 to use
shared_secretwhere to write the key material HKDF-Extract(r||aX)=HKDF-Extract(r||x(aG))
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 318 of file crypto_hpke.c.

324{
326 struct GNUNET_CRYPTO_HpkePrivateKey skE_hpke;
327 // skE, pkE = GenerateElligatorKeyPair()
328 // enc = SerializePublicKey(pkE) == c is the elligator representative
330 random_tweak,
331 skE,
332 &pkE.ecdhe_key,
334
335 GNUNET_memcpy (&skE_hpke.ecdhe_key,
336 skE,
337 sizeof *skE);
340 pkR,
341 c,
342 &skE_hpke,
343 shared_secret);
344}
static uint8_t GNUNET_CRYPTO_HPKE_KEM_ELLIGATOR_SUITE_ID[]
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand(uint8_t random_tweak, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk, struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_ElligatorRepresentative *repr)
Generates a valid public key for elligator's inverse map by adding a lower order point to a prime ord...
Elligator representative (always for Curve25519)

References GNUNET_CRYPTO_HpkePrivateKey::ecdhe_key, GNUNET_CRYPTO_HpkePublicKey::ecdhe_key, GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand(), GNUNET_CRYPTO_HPKE_KEM_ELLIGATOR_SUITE_ID, GNUNET_memcpy, and kem_encaps_norand().

Referenced by GNUNET_CRYPTO_hpke_elligator_kem_encaps(), GNUNET_CRYPTO_hpke_sender_setup2(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_elligator_kem_encaps()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps ( const struct GNUNET_CRYPTO_HpkePublicKey pkR,
struct GNUNET_CRYPTO_HpkeEncapsulation c,
struct GNUNET_ShortHashCode shared_secret 
)

Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair.

Following the terminology in https://eprint.iacr.org/2021/509.pdf. Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
pkRReceiver public key (X)
crepresentative of ephemeral public key A to use for the ECDH (direct_map(r)=A=aG)
shared_secretwhere to write the key material HKDF-Extract(r||aX)=HKDF-Extract(r||x(aG))
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 348 of file crypto_hpke.c.

352{
353 uint8_t random_tweak;
355
356 GNUNET_CRYPTO_random_block (&random_tweak,
357 sizeof(uint8_t));
358
359 // skE, pkE = GenerateElligatorKeyPair()
361
362 return GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand (random_tweak, pkR, c,
363 &skE, shared_secret);
364}
void GNUNET_CRYPTO_ecdhe_elligator_key_create(struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk)
Generates a private key for Curve25519.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand(uint8_t random_tweak, const struct GNUNET_CRYPTO_HpkePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephem...
Special private ECC key generated by GNUNET_CRYPTO_ecdhe_elligator_key_create.

References GNUNET_CRYPTO_ecdhe_elligator_key_create(), GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand(), and GNUNET_CRYPTO_random_block().

Referenced by setup_initial_shared_secret_ephemeral(), start_initial_kx_out(), and start_initial_kx_out().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_elligator_kem_decaps()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_decaps ( const struct GNUNET_CRYPTO_HpkePrivateKey skR,
const struct GNUNET_CRYPTO_HpkeEncapsulation c,
struct GNUNET_ShortHashCode shared_secret 
)

Carries out ecdh decapsulation with own private key and the representative of the received public key.

Following the terminology in https://eprint.iacr.org/2021/509.pdf. Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
skRsender private key (x)
rreceived representative r, from which we can obtain the public key A (direct_map(r)=A=aG)
shared_secretwhere to write the key material HKDF-Extract(r||aX)=HKDF-Extract(r||x(aG))
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 368 of file crypto_hpke.c.

372{
376 uint8_t kem_context[sizeof *r + crypto_scalarmult_curve25519_BYTES];
377 uint8_t pkR[crypto_scalarmult_BYTES];
378
380 // pkE = DeserializePublicKey(enc) Elligator deserialize!
382 &pkE.ecdhe_key,
383 NULL,
384 r);
385 // dh = DH(skR, pkE)
388 &skR->ecdhe_key,
389 &pkE.ecdhe_key,
390 &dh.ecdhe_key));
391 // pkRm = DeserializePublicKey(pk(skR)) is a NOP, see Section 7.1.1
392 crypto_scalarmult_curve25519_base (pkR,
393 skR->ecdhe_key.d);
394 memcpy (kem_context, r, sizeof *r);
395 memcpy (kem_context + sizeof *r, pkR, sizeof pkR);
396 // shared_secret = ExtractAndExpand(dh, kem_context)
398 &dh.ecdhe_key, sizeof dh.ecdhe_key,
399 "HPKE-v1",
400 "HPKE-v1",
401 "eae_prk", strlen ("eae_prk"),
402 "shared_secret", strlen ("shared_secret"),
403 kem_context, sizeof kem_context,
406 shared_secret);
407}
void GNUNET_CRYPTO_ecdhe_elligator_decoding(struct GNUNET_CRYPTO_EcdhePublicKey *point, bool *high_y, const struct GNUNET_CRYPTO_ElligatorRepresentative *representative)
Clears the most significant bit and second most significant bit of the serialized representaive befor...
uint8_t r[256/8]
Represents an element of Curve25519 finite field.

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_CRYPTO_HpkePrivateKey::ecdhe_key, GNUNET_CRYPTO_HpkePublicKey::ecdhe_key, GNUNET_assert, GNUNET_CRYPTO_ecdhe_elligator_decoding(), GNUNET_CRYPTO_HPKE_KEM_ELLIGATOR_SUITE_ID, GNUNET_CRYPTO_hpke_labeled_extract_and_expand(), GNUNET_CRYPTO_x25519_ecdh(), GNUNET_OK, and GNUNET_CRYPTO_ElligatorRepresentative::r.

Referenced by GNUNET_CRYPTO_hpke_receiver_setup2(), setup_in_cipher_elligator(), setup_in_cipher_elligator(), and setup_initial_shared_secret_dec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_kem_decaps()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps ( const struct GNUNET_CRYPTO_EddsaPrivateKey priv,
const struct GNUNET_CRYPTO_HpkeEncapsulation c,
struct GNUNET_ShortHashCode prk 
)

Decapsulate a key for a private EdDSA key.

Dual to #GNUNET_CRRYPTO_eddsa_kem_encaps. Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
privprivate key from EdDSA to use for the ECDH (x)
cthe encapsulated key
prkwhere to write the key material HKDF-Extract(c||aX)=HKDF-Extract(c||x(aG))
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 301 of file crypto_hpke.c.

305{
307
308 // This maps the ed25519 point to X25519
309 if (0 != crypto_sign_ed25519_sk_to_curve25519 (skR.ecdhe_key.d,
310 priv->d))
311 return GNUNET_SYSERR;
312 return GNUNET_CRYPTO_hpke_kem_decaps (&skR, c, shared_secret);
313
314}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_decaps(const struct GNUNET_CRYPTO_HpkePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Decapsulate a key for a private X25519 key.

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_CRYPTO_EddsaPrivateKey::d, GNUNET_CRYPTO_HpkePrivateKey::ecdhe_key, GNUNET_CRYPTO_hpke_kem_decaps(), and GNUNET_SYSERR.

Referenced by handle_decaps(), setup_in_cipher(), setup_in_cipher(), and setup_shared_secret_dec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_kem_encaps()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_encaps ( const struct GNUNET_CRYPTO_EddsaPublicKey pub,
struct GNUNET_CRYPTO_HpkeEncapsulation c,
struct GNUNET_ShortHashCode prk 
)

Encapsulate key material for a EdDSA public key.

Dual to #GNUNET_CRRYPTO_eddsa_kem_decaps. Use GNUNET_CRYPTO_hkdf_expand to derive further context-specific keys from the key material.

Parameters
pubpublic key from EdDSA to use for the ECDH (X=h(x)G)
cencapsulation of prk
prkwhere to write the key material HKDF-Extract(c||aX)=HKDF-Extract(c||x(aG))
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 246 of file crypto_hpke.c.

249{
251
252 // This maps the ed25519 point to X25519
253 if (0 != crypto_sign_ed25519_pk_to_curve25519 (pkR.ecdhe_key.q_y,
254 pub->q_y))
255 return GNUNET_SYSERR;
256
257 return GNUNET_CRYPTO_hpke_kem_encaps (&pkR, c, shared_secret);
258}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_encaps(const struct GNUNET_CRYPTO_HpkePublicKey *pub, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Encapsulate key material for a X25519 public key.

References GNUNET_CRYPTO_HpkePublicKey::ecdhe_key, GNUNET_CRYPTO_hpke_kem_encaps(), GNUNET_SYSERR, pub, GNUNET_CRYPTO_EddsaPublicKey::q_y, and GNUNET_CRYPTO_EcdhePublicKey::q_y.

Referenced by encapsulate_for_dv(), inject_rekey(), inject_rekey(), send_initiator_hello(), send_responder_hello(), and setup_shared_secret_ephemeral().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_ecdh()

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.

Derive key material from a ECDH public key and a private ECDSA key. Dual to #GNUNET_CRRYPTO_ecdh_ecdsa.

Parameters
privprivate key from ECDSA to use for the ECDH (x)
pubpublic key to use for the ECDH (yG)
key_materialwhere to write the key material H(h(x)yG)
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 826 of file crypto_ecc.c.

829{
830 uint8_t p[crypto_scalarmult_BYTES];
831
832 BENCHMARK_START (ecdsa_ecdh);
833 if (0 != crypto_scalarmult (p, priv->d, pub->q_y))
834 return GNUNET_SYSERR;
836 crypto_scalarmult_BYTES,
837 key_material);
838 BENCHMARK_END (ecdsa_ecdh);
839 return GNUNET_OK;
840}

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_EcdsaPrivateKey::d, GNUNET_CRYPTO_hash(), GNUNET_OK, GNUNET_SYSERR, p, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_ecdh_eddsa()

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.

Dual to #GNUNET_CRRYPTO_eddsa_ecdh. This converts the Edwards25519 public key pub to a Curve25519 public key before computing a X25519 DH (see GNUNET_CRYPTO_ecc_ecdh). The resulting X25519 secret is then derived to a key using SHA-512. NOTE: Whenever you can get away with it, use separate key pairs for signing and encryption (DH)!

Parameters
privprivate key to use for the ECDH (y)
pubpublic key from EdDSA to use for the ECDH (X=h(x)G)
key_materialwhere to write the key material H(yX)=H(h(x)yG)
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 844 of file crypto_ecc.c.

847{
848 uint8_t p[crypto_scalarmult_BYTES];
849 uint8_t curve25510_pk[crypto_scalarmult_BYTES];
850
851 if (0 != crypto_sign_ed25519_pk_to_curve25519 (curve25510_pk, pub->q_y))
852 return GNUNET_SYSERR;
853 if (0 != crypto_scalarmult (p, priv->d, curve25510_pk))
854 return GNUNET_SYSERR;
855 GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
856 return GNUNET_OK;
857}

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_CRYPTO_hash(), GNUNET_OK, GNUNET_SYSERR, p, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by checkvec(), output_vectors(), and update_ax_by_kx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdh_x25519()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_x25519 ( const struct GNUNET_CRYPTO_EcdhePrivateKey priv,
const struct GNUNET_CRYPTO_EcdhePublicKey pub,
struct GNUNET_CRYPTO_EcdhePublicKey dh 
)

Derive key material from a EdDSA public key and a private ECDH key.

Dual to #GNUNET_CRRYPTO_x25519_ecdh. NOTE: Whenever you can get away with it, use separate key pairs for signing and encryption (DH)!

Parameters
privprivate key to use for the ECDH (y)
pubpublic key from EdDSA to use for the ECDH (X=h(x)G)
dhthe DH shared secret (NOTE: Derive key from this before use!)
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 804 of file crypto_ecc.c.

807{
808 uint64_t checkbyte = 0;
809 size_t num_words = sizeof *dh / sizeof (uint64_t);
810 if (0 != crypto_scalarmult_curve25519 (dh->q_y, sk->d, pk->q_y))
811 return GNUNET_SYSERR;
812 // We need to check if this is the all-zero value
813 for (int i = 0; i < num_words; i++)
814 checkbyte |= ((uint64_t*) dh)[i];
815 if (0 == checkbyte)
816 {
818 "HPKE ECDH: X25519 all zero value!\n");
819 return GNUNET_SYSERR;
820 }
821 return GNUNET_OK;
822}

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, pk, and GNUNET_CRYPTO_EcdhePublicKey::q_y.

Referenced by kem_encaps_norand().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdh_ecdsa()

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.

Dual to #GNUNET_CRRYPTO_ecdsa_ecdh.

Parameters
privprivate key to use for the ECDH (y)
pubpublic key from ECDSA to use for the ECDH (X=h(x)G)
key_materialwhere to write the key material H(yX)=H(h(x)yG)
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 861 of file crypto_ecc.c.

864{
865 uint8_t p[crypto_scalarmult_BYTES];
866 uint8_t curve25510_pk[crypto_scalarmult_BYTES];
867
868 if (0 != crypto_sign_ed25519_pk_to_curve25519 (curve25510_pk, pub->q_y))
869 return GNUNET_SYSERR;
870 if (0 != crypto_scalarmult (p, priv->d, curve25510_pk))
871 return GNUNET_SYSERR;
872 GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
873 return GNUNET_OK;
874}

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_CRYPTO_hash(), GNUNET_OK, GNUNET_SYSERR, p, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_eddsa_sign_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_ ( const struct GNUNET_CRYPTO_EddsaPrivateKey priv,
const struct GNUNET_CRYPTO_SignaturePurpose purpose,
struct GNUNET_CRYPTO_EddsaSignature sig 
)

EdDSA sign a given block.

The purpose data is the beginning of the data of which the signature is to be created. The size field in purpose must correctly indicate the number of bytes of the data structure, including its header. If possible, use GNUNET_CRYPTO_eddsa_sign() instead of this function (only if validate is not fixed-size, you must use this function directly).

Parameters
privprivate key to use for the signing
purposewhat to sign (size, purpose)
[out]sigwhere to write the signature
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 646 of file crypto_ecc.c.

650{
651
652 size_t mlen = ntohl (purpose->size);
653 unsigned char sk[crypto_sign_SECRETKEYBYTES];
654 unsigned char pk[crypto_sign_PUBLICKEYBYTES];
655 int res;
656
657 BENCHMARK_START (eddsa_sign);
658 GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
659 res = crypto_sign_detached ((uint8_t *) sig,
660 NULL,
661 (uint8_t *) purpose,
662 mlen,
663 sk);
664 BENCHMARK_END (eddsa_sign);
665 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
666}
static char * res
Currently read line or NULL on EOF.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_EddsaPrivateKey::d, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, pk, res, and GNUNET_CRYPTO_SignaturePurpose::size.

Referenced by do_generate_pid(), GNUNET_CRYPTO_blinded_key_sign_(), GNUNET_CRYPTO_blinded_key_sign_by_peer_identity(), GNUNET_CRYPTO_blinded_key_sign_raw_(), handle_sign(), insert_decrypt_element(), insert_round1_element(), and insert_round2_element().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_sign_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_ ( const struct GNUNET_CRYPTO_EcdsaPrivateKey priv,
const struct GNUNET_CRYPTO_SignaturePurpose purpose,
struct GNUNET_CRYPTO_EcdsaSignature sig 
)

ECDSA Sign a given block.

The purpose data is the beginning of the data of which the signature is to be created. The size field in purpose must correctly indicate the number of bytes of the data structure, including its header. If possible, use GNUNET_CRYPTO_ecdsa_sign() instead of this function (only if validate is not fixed-size, you must use this function directly).

Parameters
privprivate key to use for the signing
purposewhat to sign (size, purpose)
[out]sigwhere to write the signature
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 575 of file crypto_ecc.c.

579{
580 gcry_sexp_t priv_sexp;
581 gcry_sexp_t sig_sexp;
582 gcry_sexp_t data;
583 int rc;
584 gcry_mpi_t rs[2];
585
586 BENCHMARK_START (ecdsa_sign);
587
588 priv_sexp = decode_private_ecdsa_key (priv);
589 data = data_to_ecdsa_value (purpose);
590 if (0 != (rc = gcry_pk_sign (&sig_sexp, data, priv_sexp)))
591 {
593 _ ("ECC signing failed at %s:%d: %s\n"),
594 __FILE__,
595 __LINE__,
596 gcry_strerror (rc));
597 gcry_sexp_release (data);
598 gcry_sexp_release (priv_sexp);
599 return GNUNET_SYSERR;
600 }
601 gcry_sexp_release (priv_sexp);
602 gcry_sexp_release (data);
603
604 /* extract 'r' and 's' values from sexpression 'sig_sexp' and store in
605 'signature' */
606 if (0 != (rc = key_from_sexp (rs, sig_sexp, "sig-val", "rs")))
607 {
608 GNUNET_break (0);
609 gcry_sexp_release (sig_sexp);
610 return GNUNET_SYSERR;
611 }
612 gcry_sexp_release (sig_sexp);
613 GNUNET_CRYPTO_mpi_print_unsigned (sig->r, sizeof(sig->r), rs[0]);
614 GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof(sig->s), rs[1]);
615 gcry_mpi_release (rs[0]);
616 gcry_mpi_release (rs[1]);
617
618 BENCHMARK_END (ecdsa_sign);
619
620 return GNUNET_OK;
621}
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.
Definition crypto_ecc.c:101
static gcry_sexp_t data_to_ecdsa_value(const struct GNUNET_CRYPTO_SignaturePurpose *purpose)
Convert the data specified in the given purpose argument to an S-expression suitable for signature op...
Definition crypto_ecc.c:552
#define LOG(kind,...)
Definition crypto_ecc.c:65
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 libgcry...
Definition crypto_ecc.c:159
static char * data
The data to insert into the dht.
@ GNUNET_ERROR_TYPE_WARNING
unsigned char s[256/8]
S value.
unsigned char r[256/8]
R value.

References _, BENCHMARK_END, BENCHMARK_START, data, data_to_ecdsa_value(), decode_private_ecdsa_key(), GNUNET_break, GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_ERROR_TYPE_WARNING, GNUNET_OK, GNUNET_SYSERR, key_from_sexp(), LOG, GNUNET_CRYPTO_EcdsaSignature::r, and GNUNET_CRYPTO_EcdsaSignature::s.

Referenced by GNUNET_CRYPTO_blinded_key_sign_(), GNUNET_CRYPTO_blinded_key_sign_raw_(), and GNUNET_CRYPTO_ecdsa_sign_derived().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_sign_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_edx25519_sign_ ( const struct GNUNET_CRYPTO_Edx25519PrivateKey priv,
const struct GNUNET_CRYPTO_SignaturePurpose purpose,
struct GNUNET_CRYPTO_Edx25519Signature sig 
)

Edx25519 sign a given block.

The purpose data is the beginning of the data of which the signature is to be created. The size field in purpose must correctly indicate the number of bytes of the data structure, including its header. If possible, use GNUNET_CRYPTO_edx25519_sign() instead of this function (only if validate is not fixed-size, you must use this function directly).

Parameters
privprivate key to use for the signing
purposewhat to sign (size, purpose)
[out]sigwhere to write the signature
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Edx25519 sign a given block.

But instead of expanding a private seed (which is usually the case for crypto APIs) and using the resulting scalars, it takes the scalars directly from Edx25519PrivateKey. We require this functionality in order to use derived private keys for signatures.

The resulting signature is a standard EdDSA signature which can be verified using the usual APIs.

Parameters
privthe private key (containing two scalars .a and .b)
purpthe signature purpose
sigthe resulting signature

Calculate the public key P from the private scalar in the key.

Calculate r: r = SHA512 (b ∥ M) where M is our message (purpose).

Temporarily put P into S

Reduce the scalar value r

Calculate R := r * G of the signature

Calculate hram := SHA512 (R ∥ P ∥ M)

Reduce the resulting scalar value

Calculate S := r + hram * s mod L

Definition at line 101 of file crypto_edx25519.c.

105{
106
107 crypto_hash_sha512_state hs;
108 unsigned char r[64];
109 unsigned char hram[64];
110 unsigned char P[32];
111 unsigned char r_mod[64];
112 unsigned char R[32];
113 unsigned char tmp[32];
114 unsigned char hram_mod[64];
115
116 crypto_hash_sha512_init (&hs);
117
121 crypto_scalarmult_ed25519_base_noclamp (P,
122 priv->a);
123
129 crypto_hash_sha512_update (&hs,
130 priv->b,
131 sizeof(priv->b));
132 crypto_hash_sha512_update (&hs,
133 (uint8_t*) purpose,
134 ntohl (purpose->size));
135 crypto_hash_sha512_final (&hs,
136 r);
137
141 memcpy (sig->s, P, 32);
142
146 crypto_core_ed25519_scalar_reduce (r_mod, r);
147
151 crypto_scalarmult_ed25519_base_noclamp (R, r_mod);
152 memcpy (sig->r, R, sizeof (R));
153
158 crypto_hash_sha512_init (&hs);
159 crypto_hash_sha512_update (&hs, (uint8_t*) sig, 64);
160 crypto_hash_sha512_update (&hs, (uint8_t*) purpose,
161 ntohl (purpose->size));
162 crypto_hash_sha512_final (&hs, hram);
163
167 crypto_core_ed25519_scalar_reduce (hram_mod, hram);
168
173 crypto_core_ed25519_scalar_mul (tmp, hram_mod, priv->a);
174 crypto_core_ed25519_scalar_add (sig->s, tmp, r_mod);
175
176 sodium_memzero (r, sizeof (r));
177 sodium_memzero (r_mod, sizeof (r_mod));
178
179 return GNUNET_OK;
180}
unsigned char b[256/8]
b consists of 32 bytes which where originally the lower 32bytes of the key expansion.
unsigned char s[256/8]
S value.
unsigned char r[256/8]
R value.

References GNUNET_CRYPTO_Edx25519PrivateKey::a, GNUNET_CRYPTO_Edx25519PrivateKey::b, GNUNET_OK, GNUNET_CRYPTO_Edx25519Signature::r, GNUNET_CRYPTO_Edx25519Signature::s, and GNUNET_CRYPTO_SignaturePurpose::size.

◆ GNUNET_CRYPTO_eddsa_verify_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_ ( uint32_t  purpose,
const struct GNUNET_CRYPTO_SignaturePurpose validate,
const struct GNUNET_CRYPTO_EddsaSignature sig,
const struct GNUNET_CRYPTO_EddsaPublicKey pub 
)

Verify EdDSA signature.

The validate data is the beginning of the data of which the signature is to be verified. The size field in validate must correctly indicate the number of bytes of the data structure, including its header. If purpose does not match the purpose given in validate (the latter must be in big endian), signature verification fails. If possible, use GNUNET_CRYPTO_eddsa_verify() instead of this function (only if validate is not fixed-size, you must use this function directly).

Parameters
purposewhat is the purpose that the signature should have?
validateblock to validate (size, purpose, data)
sigsignature that is being validated
pubpublic key of the signer
Returns
GNUNET_OK if ok, GNUNET_SYSERR if invalid

Definition at line 729 of file crypto_ecc.c.

734{
735 const unsigned char *m = (const void *) validate;
736 size_t mlen = ntohl (validate->size);
737 const unsigned char *s = (const void *) sig;
738
739 int res;
740
741 if (purpose != ntohl (validate->purpose))
742 return GNUNET_SYSERR; /* purpose mismatch */
743
744 BENCHMARK_START (eddsa_verify);
745
746 res = crypto_sign_verify_detached (s, m, mlen, pub->q_y);
747 BENCHMARK_END (eddsa_verify);
748 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
749}
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition gnunet-arm.c:103
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...

References BENCHMARK_END, BENCHMARK_START, GNUNET_OK, GNUNET_SYSERR, m, pub, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_CRYPTO_EddsaPublicKey::q_y, res, and GNUNET_CRYPTO_SignaturePurpose::size.

Referenced by block_plugin_dns_check_block(), block_plugin_fs_check_block(), block_plugin_regex_check_block(), GNUNET_CRYPTO_blinded_key_signature_verify_(), GNUNET_CRYPTO_blinded_key_signature_verify_raw_(), GNUNET_CRYPTO_verify_peer_identity(), GNUNET_GNSRECORD_block_verify(), keygen_round1_new_element(), keygen_round2_new_element(), and verify_message_crypto().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_verify_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_verify_ ( uint32_t  purpose,
const struct GNUNET_CRYPTO_SignaturePurpose validate,
const struct GNUNET_CRYPTO_EcdsaSignature sig,
const struct GNUNET_CRYPTO_EcdsaPublicKey pub 
)

Verify ECDSA signature.

The validate data is the beginning of the data of which the signature is to be verified. The size field in validate must correctly indicate the number of bytes of the data structure, including its header. If purpose does not match the purpose given in validate (the latter must be in big endian), signature verification fails. If possible, use GNUNET_CRYPTO_eddsa_verify() instead of this function (only if validate is not fixed-size, you must use this function directly).

Parameters
purposewhat is the purpose that the signature should have?
validateblock to validate (size, purpose, data)
sigsignature that is being validated
pubpublic key of the signer
Returns
GNUNET_OK if ok, GNUNET_SYSERR if invalid

Definition at line 670 of file crypto_ecc.c.

675{
676 gcry_sexp_t data;
677 gcry_sexp_t sig_sexpr;
678 gcry_sexp_t pub_sexpr;
679 int rc;
680
681 BENCHMARK_START (ecdsa_verify);
682
683 if (purpose != ntohl (validate->purpose))
684 return GNUNET_SYSERR; /* purpose mismatch */
685
686 /* build s-expression for signature */
687 if (0 != (rc = gcry_sexp_build (&sig_sexpr,
688 NULL,
689 "(sig-val(ecdsa(r %b)(s %b)))",
690 (int) sizeof(sig->r),
691 sig->r,
692 (int) sizeof(sig->s),
693 sig->s)))
694 {
695 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
696 return GNUNET_SYSERR;
697 }
698 data = data_to_ecdsa_value (validate);
699 if (0 != (rc = gcry_sexp_build (&pub_sexpr,
700 NULL,
701 "(public-key(ecc(curve " CURVE ")(q %b)))",
702 (int) sizeof(pub->q_y),
703 pub->q_y)))
704 {
705 gcry_sexp_release (data);
706 gcry_sexp_release (sig_sexpr);
707 return GNUNET_SYSERR;
708 }
709 rc = gcry_pk_verify (sig_sexpr, data, pub_sexpr);
710 gcry_sexp_release (pub_sexpr);
711 gcry_sexp_release (data);
712 gcry_sexp_release (sig_sexpr);
713 if (0 != rc)
714 {
716 _ ("ECDSA signature verification failed at %s:%d: %s\n"),
717 __FILE__,
718 __LINE__,
719 gcry_strerror (rc));
720 BENCHMARK_END (ecdsa_verify);
721 return GNUNET_SYSERR;
722 }
723 BENCHMARK_END (ecdsa_verify);
724 return GNUNET_OK;
725}
#define CURVE
IMPLEMENTATION NOTICE:
Definition crypto_ecc.c:63
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Definition crypto_ecc.c:79
@ GNUNET_ERROR_TYPE_INFO

References _, BENCHMARK_END, BENCHMARK_START, CURVE, data, data_to_ecdsa_value(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_OK, GNUNET_SYSERR, LOG, LOG_GCRY, pub, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_CRYPTO_EddsaPublicKey::q_y, GNUNET_CRYPTO_EcdsaSignature::r, and GNUNET_CRYPTO_EcdsaSignature::s.

Referenced by GNUNET_CRYPTO_blinded_key_signature_verify_(), GNUNET_CRYPTO_blinded_key_signature_verify_raw_(), and GNUNET_GNSRECORD_block_verify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_verify_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_edx25519_verify_ ( uint32_t  purpose,
const struct GNUNET_CRYPTO_SignaturePurpose validate,
const struct GNUNET_CRYPTO_Edx25519Signature sig,
const struct GNUNET_CRYPTO_Edx25519PublicKey pub 
)

Verify Edx25519 signature.

The validate data is the beginning of the data of which the signature is to be verified. The size field in validate must correctly indicate the number of bytes of the data structure, including its header. If purpose does not match the purpose given in validate (the latter must be in big endian), signature verification fails. If possible, use GNUNET_CRYPTO_edx25519_verify() instead of this function (only if validate is not fixed-size, you must use this function directly).

Parameters
purposewhat is the purpose that the signature should have?
validateblock to validate (size, purpose, data)
sigsignature that is being validated
pubpublic key of the signer
Returns
GNUNET_OK if ok, GNUNET_SYSERR if invalid

Definition at line 184 of file crypto_edx25519.c.

189{
190 const unsigned char *m = (const void *) validate;
191 size_t mlen = ntohl (validate->size);
192 const unsigned char *s = (const void *) sig;
193
194 int res;
195
196 if (purpose != ntohl (validate->purpose))
197 return GNUNET_SYSERR; /* purpose mismatch */
198
199 res = crypto_sign_verify_detached (s, m, mlen, pub->q_y);
200 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
201}

References GNUNET_OK, GNUNET_SYSERR, m, pub, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_CRYPTO_EddsaPublicKey::q_y, res, and GNUNET_CRYPTO_SignaturePurpose::size.

◆ GNUNET_CRYPTO_ecdsa_private_key_derive()

struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_private_key_derive ( const struct GNUNET_CRYPTO_EcdsaPrivateKey priv,
const char *  label,
const char *  context 
)

Derive a private key from a given private key and a label.

Essentially calculates a private key 'h = H(l,P) * d mod n' where n is the size of the ECC group and P is the public key associated with the private key 'd'.

Parameters
privoriginal private key
labellabel to use for key deriviation
contextadditional context to use for HKDF of 'h'; typically the name of the subsystem/application
Returns
derived private key

"The result of the HKDF must be clamped and interpreted in network byte order. " – RFC 9498 We need to convert for libsodium

hc_le now contains the scalar h. The private scalar a is sk[0:31] We calculate: d' := h * a mod L

Definition at line 200 of file crypto_ecc_gnsrecord.c.

204{
207 struct GNUNET_HashCode h;
208 unsigned char h_mod_L[crypto_core_ed25519_SCALARBYTES];
209 unsigned char h_le[64];
210
211
214
215 derive_h (&pub, sizeof (pub), label, context, &h);
216
221 for (size_t i = 0; i < 64; i++)
222 h_le[i] = ((unsigned char*) &h)[63 - i];
223
230 crypto_core_ed25519_scalar_reduce (h_mod_L,
231 (unsigned char*) &h_le);
232 crypto_core_ed25519_scalar_mul (ret->d, h_mod_L, priv->d);
233 return ret;
234}
static void derive_h(const void *pub, size_t pubsize, const char *label, const char *context, struct GNUNET_HashCode *hc)
Derive the 'h' value for key derivation, where 'h = H(l,P)'.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
static pa_context * context
Pulseaudio context.
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive key.
Definition crypto_ecc.c:191
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...

References context, GNUNET_CRYPTO_EcdsaPrivateKey::d, derive_h(), GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_new, h, pub, and ret.

Referenced by GNUNET_CRYPTO_ecdsa_sign_derived(), and run_pkey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_public_key_derive()

void GNUNET_CRYPTO_ecdsa_public_key_derive ( const struct GNUNET_CRYPTO_EcdsaPublicKey pub,
const char *  label,
const char *  context,
struct GNUNET_CRYPTO_EcdsaPublicKey result 
)

Derive a public key from a given public key and a label.

Essentially calculates a public key 'V = H(l,P) * P'.

Parameters
puboriginal public key
labellabel to use for key deriviation
contextadditional context to use for HKDF of 'h'. typically the name of the subsystem/application
resultwhere to write the derived public key

"The result of the HKDF must be clamped and interpreted in network byte order. " – RFC 9498 We need to convert for libsodium

We calculate: Q := h * P mod L

Definition at line 238 of file crypto_ecc_gnsrecord.c.

243{
244 struct GNUNET_HashCode hc;
245 unsigned char h_mod_L[crypto_core_ed25519_SCALARBYTES];
246 unsigned char h_le[64];
247
248 derive_h (pub, sizeof (*pub), label, context, &hc);
253 for (size_t i = 0; i < 64; i++)
254 h_le[i] = ((unsigned char*) &hc)[63 - i];
255
256
261 crypto_core_ed25519_scalar_reduce (h_mod_L,
262 (unsigned char*) &h_le);
263 GNUNET_assert (0 == crypto_scalarmult_ed25519_noclamp (result->q_y,
264 h_mod_L,
265 pub->q_y));
266}

References context, derive_h(), GNUNET_assert, pub, GNUNET_CRYPTO_EddsaPublicKey::q_y, and result.

Referenced by block_sign_ecdsa(), GNUNET_GNSRECORD_query_from_public_key(), and run_pkey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_private_key_derive()

void GNUNET_CRYPTO_eddsa_private_key_derive ( const struct GNUNET_CRYPTO_EddsaPrivateKey priv,
const char *  label,
const char *  context,
struct GNUNET_CRYPTO_EddsaPrivateScalar result 
)

Derive a private scalar from a given private key and a label.

Essentially calculates a private key 'h = H(l,P) * d mod n' where n is the size of the ECC group and P is the public key associated with the private key 'd'. The result is the derived private scalar, not the private key as for EdDSA we cannot derive before we hash the private key.

Parameters
privoriginal private key
labellabel to use for key deriviation
contextadditional context to use for HKDF of 'h'; typically the name of the subsystem/application
resultderived private scalar

This is the standard private key expansion in Ed25519. The first 32 octets are used as a little-endian private scalar. We derive this scalar using our "h".

Get h mod L

"The result of the HKDF must be clamped and interpreted in network byte order. " – RFC 9498 We need to convert for libsodium

h_le now contains the scalar h. The private scalar a is sk[0:31] We calculate: d' := h * a mod L

We hash the derived "h" parameter with the other half of the expanded private key. This ensures that for signature generation, the "R" is derived from the same derivation path as "h" and is not reused.

Definition at line 273 of file crypto_ecc_gnsrecord.c.

278{
280 struct GNUNET_HashCode h;
281 unsigned char h_le[64];
282 unsigned char sk[64];
283 unsigned char *d;
284 unsigned char *nonce;
285 unsigned char h_mod_L[crypto_core_ed25519_SCALARBYTES];
286
287 d = result->s;
288 nonce = result->s + 32;
289
296 crypto_hash_sha512 (sk, priv->d, 32);
297 sk[0] &= 248;
298 sk[31] &= 127;
299 sk[31] |= 64;
300
305 derive_h (&pub, sizeof (pub), label, context, &h);
306
311 for (size_t i = 0; i < 64; i++)
312 h_le[i] = ((unsigned char*) &h)[63 - i];
313
314
321 crypto_core_ed25519_scalar_reduce (h_mod_L,
322 (unsigned char*) &h_le);
323 crypto_core_ed25519_scalar_mul (d, h_mod_L, sk);
324
325 {
332 crypto_hash_sha256_state hs;
333 crypto_hash_sha256_init (&hs);
334 crypto_hash_sha256_update (&hs, sk + 32, 32);
335 crypto_hash_sha256_update (&hs, (unsigned char*) &h, sizeof (h));
336 crypto_hash_sha256_final (&hs, nonce);
337 }
338
339}
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...

References context, d, GNUNET_CRYPTO_EddsaPrivateKey::d, derive_h(), GNUNET_CRYPTO_eddsa_key_get_public(), h, pub, and result.

Referenced by GNUNET_CRYPTO_eddsa_sign_derived(), GNUNET_FS_publish_ublock_(), and run_edkey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_public_key_derive()

void GNUNET_CRYPTO_eddsa_public_key_derive ( const struct GNUNET_CRYPTO_EddsaPublicKey pub,
const char *  label,
const char *  context,
struct GNUNET_CRYPTO_EddsaPublicKey result 
)

Derive a public key from a given public key and a label.

Essentially calculates a public key 'V = H(l,P) * P'.

Parameters
puboriginal public key
labellabel to use for key deriviation
contextadditional context to use for HKDF of 'h'. typically the name of the subsystem/application
resultwhere to write the derived public key

"The result of the HKDF must be clamped and interpreted in network byte order. " – RFC 9498 We need to convert for libsodium

h_le now contains the scalar h. We calculate: Q := h * P mod L

Definition at line 343 of file crypto_ecc_gnsrecord.c.

348{
349 struct GNUNET_HashCode h;
350 unsigned char h_le[64];
351 unsigned char h_mod_L[crypto_core_ed25519_SCALARBYTES];
352
353 /* calculate h_mod_n = h % n */
354 derive_h (pub, sizeof (*pub), label, context, &h);
355
360 for (size_t i = 0; i < 64; i++)
361 h_le[i] = ((unsigned char*) &h)[63 - i];
362
368 crypto_core_ed25519_scalar_reduce (h_mod_L,
369 (unsigned char*) &h_le);
370
371 GNUNET_assert (0 == crypto_scalarmult_ed25519_noclamp (result->q_y,
372 h_mod_L,
373 pub->q_y));
374}

References context, derive_h(), GNUNET_assert, h, pub, GNUNET_CRYPTO_EddsaPublicKey::q_y, and result.

Referenced by block_sign_eddsa(), GNUNET_FS_search_start_searching_(), GNUNET_FS_unindex_do_remove_kblocks_(), GNUNET_GNSRECORD_query_from_public_key(), run_edkey(), and schedule_transmit_search_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_private_key_derive()

void GNUNET_CRYPTO_edx25519_private_key_derive ( const struct GNUNET_CRYPTO_Edx25519PrivateKey priv,
const void *  seed,
size_t  seedsize,
struct GNUNET_CRYPTO_Edx25519PrivateKey result 
)

Derive a private scalar from a given private key and a label.

Essentially calculates a private key 'h = H(l,P) * d mod n' where n is the size of the ECC group and P is the public key associated with the private key 'd'.

Parameters
privoriginal private key
seedinput seed
seedsizesize of the seed
resultderived private key

dc now contains the private scalar "a". We carefully remove the clamping and derive a'. Calculate: a1 := a / 8 a2 := h * a1 mod n a' := a2 * 8 mod n

Definition at line 242 of file crypto_edx25519.c.

247{
249 struct GNUNET_HashCode hc;
250 uint8_t a[32];
251 uint8_t eight[32] = { 8 };
252 uint8_t eight_inv[32];
253 uint8_t h[64] = { 0 };
254
256
257 /* Get h mod n */
258 derive_h (&pub,
259 seed,
260 seedsize,
261 &hc);
262
263 memcpy (h, &hc, 64);
264 crypto_core_ed25519_scalar_reduce (h,
265 h);
266#ifdef CHECK_RARE_CASES
274 {
275 char zero[32] = { 0 };
276 char one[32] = { 1 };
277
278 GNUNET_assert (0 != memcmp (zero, h, 32));
279 GNUNET_assert (0 != memcmp (one, h, 32));
280 }
281#endif
282
292 GNUNET_assert (0 == crypto_core_ed25519_scalar_invert (eight_inv,
293 eight));
294
295 crypto_core_ed25519_scalar_mul (a, priv->a, eight_inv);
296 crypto_core_ed25519_scalar_mul (a, a, h);
297 crypto_core_ed25519_scalar_mul (a, a, eight);
298
299#ifdef CHECK_RARE_CASES
300 /* The likelihood for a' == 0 or a' == 1 is neglegible */
301 {
302 char zero[32] = { 0 };
303 char one[32] = { 1 };
304
305 GNUNET_assert (0 != memcmp (zero, a, 32));
306 GNUNET_assert (0 != memcmp (one, a, 32));
307 }
308#endif
309
310 /* We hash the derived "h" parameter with the other half of the expanded
311 * private key (that is: priv->b). This ensures that for signature
312 * generation, the "R" is derived from the same derivation path as "h" and is
313 * not reused. */
314 {
315 struct GNUNET_HashCode hcb;
316 struct GNUNET_HashContext *hctx;
317
319 GNUNET_CRYPTO_hash_context_read (hctx, priv->b, sizeof(priv->b));
320 GNUNET_CRYPTO_hash_context_read (hctx, (unsigned char*) &hc, sizeof (hc));
322
323 /* Truncate result, effectively doing SHA512/256 */
324 for (size_t i = 0; i < 32; i++)
325 result->b[i] = ((unsigned char *) &hcb)[i];
326 }
327
328 for (size_t i = 0; i < 32; i++)
329 result->a[i] = a[i];
330
331 sodium_memzero (a, sizeof(a));
332}
static void derive_h(const struct GNUNET_CRYPTO_Edx25519PublicKey *pub, const void *seed, size_t seedsize, struct GNUNET_HashCode *phc)
Derive the 'h' value for key derivation, where 'h = H(P ∥ seed) mod n' and 'n' is the size of the cyc...
static const struct GNUNET_CRYPTO_BlindablePrivateKey zero
Public key of all zeros.
void GNUNET_CRYPTO_edx25519_key_get_public(const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, struct GNUNET_CRYPTO_Edx25519PublicKey *pub)
Extract the public key for the given private key.
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...

References GNUNET_CRYPTO_Edx25519PrivateKey::a, GNUNET_CRYPTO_Edx25519PrivateKey::b, derive_h(), GNUNET_assert, GNUNET_CRYPTO_edx25519_key_get_public(), GNUNET_CRYPTO_hash_context_finish(), GNUNET_CRYPTO_hash_context_read(), GNUNET_CRYPTO_hash_context_start(), h, pub, result, seed, and zero.

Referenced by output_vectors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_edx25519_public_key_derive()

void GNUNET_CRYPTO_edx25519_public_key_derive ( const struct GNUNET_CRYPTO_Edx25519PublicKey pub,
const void *  seed,
size_t  seedsize,
struct GNUNET_CRYPTO_Edx25519PublicKey result 
)

Derive a public key from a given public key and a label.

Essentially calculates a public key 'V = H(l,P) * P'.

Parameters
puboriginal public key
seedinput seed
seedsizesize of the seed
resultwhere to write the derived public key

Definition at line 336 of file crypto_edx25519.c.

341{
342 struct GNUNET_HashCode hc;
343 uint8_t h[64] = { 0 };
344
345 derive_h (pub,
346 seed,
347 seedsize,
348 &hc);
349 memcpy (h,
350 &hc,
351 64);
352 crypto_core_ed25519_scalar_reduce (h,
353 h);
354 GNUNET_assert (0 == crypto_scalarmult_ed25519_noclamp (result->q_y,
355 h,
356 pub->q_y));
357}

References derive_h(), GNUNET_assert, h, pub, GNUNET_CRYPTO_EddsaPublicKey::q_y, result, and seed.

Referenced by output_vectors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdhe_elligator_decoding()

void GNUNET_CRYPTO_ecdhe_elligator_decoding ( struct GNUNET_CRYPTO_EcdhePublicKey point,
bool *  high_y,
const struct GNUNET_CRYPTO_ElligatorRepresentative representative 
)

Clears the most significant bit and second most significant bit of the serialized representaive before applying elligator direct map.

Parameters
representativeserialized elligator representative of an element of Curves25519's finite field
pointdestination for the calculated point on the curve
high_ybool pointed to will be set to 'true' if corresponding y-coordinate is > 2 ^ 254 - 10, otherwise 0. Can be set to NULL if not needed.

Definition at line 508 of file crypto_elligator.c.

512{
513 // if sign of direct map transformation not needed throw it away
515 bool high_y_local;
516 bool *high_y_ptr;
517 if (NULL == high_y)
518 high_y_ptr = &high_y_local;
519 else
520 high_y_ptr = high_y;
521
522 memcpy (&r_tmp.r, &representative->r, sizeof(r_tmp.r));
523 r_tmp.r[31] &= 63;
524 // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Print high_y\n");
525 elligator_direct_map ((uint8_t *) point->q_y,
526 high_y_ptr,
527 (uint8_t *) r_tmp.r);
528}
static bool elligator_direct_map(uint8_t *point, bool *high_y, uint8_t *representative)
Takes a number of the underlying finite field of Curve25519 and projects it into a valid point on tha...

References elligator_direct_map(), GNUNET_CRYPTO_EcdhePublicKey::q_y, and GNUNET_CRYPTO_ElligatorRepresentative::r.

Referenced by GNUNET_CRYPTO_hpke_elligator_kem_decaps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdhe_elligator_encoding()

bool GNUNET_CRYPTO_ecdhe_elligator_encoding ( uint8_t  random_tweak,
struct GNUNET_CRYPTO_ElligatorRepresentative r,
const struct GNUNET_CRYPTO_EcdhePublicKey pub 
)

Encodes a point on Curve25519 to a an element of the underlying finite field.

This transformation is deterministic.

Parameters
random_tweakrandom 8-bit value used as seed
rstorage for the calculated representative
puba point on the curve
Returns
'true' if the given point can be encoded into a representative. Otherwise 'false' is returned and the content of the representative storage is undefined

Definition at line 359 of file crypto_elligator.c.

363{
364 bool high_y;
365 bool msb_set;
366 bool smsb_set;
367
368
369 uint8_t *representative = r->r;
370 uint8_t *point = (uint8_t *) pub->q_y;
371
372 mp_limb_t scratch_space[scratch_space_length];
373
374 mp_limb_t a[P_LIMBS + P_LIMBS];
375 mp_limb_t b[P_LIMBS + P_LIMBS];
376 mp_limb_t c[P_LIMBS + P_LIMBS];
377
378 high_y = random_tweak & 1;
379
380 // a := point
381
382 decode_bytes (a, point);
383
384 // b := -a / (a + A), or b := p if a = 0
385
386 mpn_add_n (b, a, A, P_LIMBS);
387 mpn_sec_powm (c, b, P_LIMBS, negative_2, P_BITS - 1, p, P_LIMBS,
388 scratch_space);
389 mpn_sec_mul (b, c, P_LIMBS, a, P_LIMBS, scratch_space);
390 mpn_sec_div_r (b, P_LIMBS + P_LIMBS, p, P_LIMBS, scratch_space);
391 mpn_sub_n (b, p, b, P_LIMBS);
392
393 // If high_y = true, b := 1 / b or b := 0 if it was = p
394
395 mpn_sec_powm (c, b, P_LIMBS, negative_2, P_BITS - 1, p, P_LIMBS,
396 scratch_space);
397 mpn_cnd_swap (high_y, b, c, P_LIMBS);
398
399 // c := b / u
400
401 mpn_sec_mul (c, b, P_LIMBS, inverted_u, P_LIMBS, scratch_space);
402 mpn_sec_div_r (c, P_LIMBS + P_LIMBS, p, P_LIMBS, scratch_space);
403
404 // If c is a square modulo p, b := least_square_root(c)
405
406 least_square_root (b, c, scratch_space);
407
408 // Determine, whether b ^ 2 = c
409
410 mpn_sec_sqr (a, b, P_LIMBS, scratch_space);
411 mpn_sec_div_r (a, P_LIMBS + P_LIMBS, p, P_LIMBS, scratch_space);
412 mpn_sub_n (a, a, c, P_LIMBS);
413
414 {
415 bool result = mpn_sec_sub_1 (a, a, P_LIMBS, 1, scratch_space);
416
417 encode_bytes (representative, b);
418
419 // Setting most significant bit and second most significant bit randomly
420 msb_set = (random_tweak >> 1) & 1;
421 smsb_set = (random_tweak >> 2) & 1;
422 if (msb_set)
423 {
424 r->r[31] |= 128;
425 }
426 if (smsb_set)
427 {
428 r->r[31] |= 64;
429 }
430 return result;
431 }
432}
static void decode_bytes(mp_limb_t *number, const uint8_t *bytes)
This function decodes the byte buffer into the MPI limb.
static void encode_bytes(uint8_t *bytes, mp_limb_t *number)
This function encodes the MPI limb into a byte buffer.
static mp_limb_t negative_2[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
#define P_BITS
static mp_limb_t p[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
#define P_LIMBS
static void least_square_root(mp_limb_t *root, const mp_limb_t *number, mp_limb_t *scratch_space)
Calculates the root of a given number.
static mp_size_t scratch_space_length
static mp_limb_t A[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static mp_limb_t inverted_u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]

References A, decode_bytes(), encode_bytes(), inverted_u, least_square_root(), negative_2, p, P_BITS, P_LIMBS, pub, GNUNET_CRYPTO_EddsaPublicKey::q_y, GNUNET_CRYPTO_ElligatorRepresentative::r, result, and scratch_space_length.

Referenced by GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand ( uint8_t  random_tweak,
const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey sk,
struct GNUNET_CRYPTO_EcdhePublicKey pub,
struct GNUNET_CRYPTO_ElligatorRepresentative repr 
)

Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point.

Following Method 1 in description https://elligator.org/key-exchange section Step 2: Generate a “special” public key.

Parameters
random_tweakrandom 8-bit value used as seed
skprivate key for generating valid public key
pubvalid public key for elligator inverse map
reprstorage for a calculated representative
Returns
GNUNET_OK on success

Definition at line 639 of file crypto_elligator.c.

644{
646 if (GNUNET_SYSERR ==
648 return GNUNET_SYSERR;
649
650 if (NULL == repr)
651 return GNUNET_OK;
652 if (! GNUNET_CRYPTO_ecdhe_elligator_encoding (random_tweak,
653 repr,
654 &pub))
655 return GNUNET_SYSERR;
656 memcpy (pk->q_y, pub.q_y, sizeof(pk->q_y));
657 return GNUNET_OK;
658}
static enum GNUNET_GenericReturnValue elligator_generate_public_key(const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
bool GNUNET_CRYPTO_ecdhe_elligator_encoding(uint8_t random_tweak, struct GNUNET_CRYPTO_ElligatorRepresentative *r, const struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Encodes a point on Curve25519 to a an element of the underlying finite field.

References elligator_generate_public_key(), GNUNET_CRYPTO_ecdhe_elligator_encoding(), GNUNET_OK, GNUNET_SYSERR, pk, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.

Referenced by GNUNET_CRYPTO_ecdhe_elligator_key_get_public(), GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdhe_elligator_key_get_public()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdhe_elligator_key_get_public ( const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey sk,
struct GNUNET_CRYPTO_EcdhePublicKey pub,
struct GNUNET_CRYPTO_ElligatorRepresentative repr 
)

Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point.

Following Method 1 in description https://elligator.org/key-exchange section Step 2: Generate a “special” public key.

Parameters
skprivate key for generating valid public key
pubvalid public key for elligator inverse map
reprstorage for a calculated representative
Returns
GNUNET_OK on success

Definition at line 662 of file crypto_elligator.c.

666{
667 uint8_t random_tweak;
668 GNUNET_CRYPTO_random_block (&random_tweak,
669 sizeof(uint8_t));
670
672 sk,
673 pk,
674 repr);
675}

References GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand(), GNUNET_CRYPTO_random_block(), and pk.

Referenced by GNUNET_CRYPTO_ecdhe_elligator_key_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdhe_elligator_key_create()

void GNUNET_CRYPTO_ecdhe_elligator_key_create ( struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey sk)

Generates a private key for Curve25519.

Parameters
skCurve25519 private key

Definition at line 679 of file crypto_elligator.c.

681{
684 // inverse map can fail for some public keys generated by GNUNET_CRYPTO_ecdhe_elligator_generate_public_key
685 while (true)
686 {
688 sizeof (struct
690 ;
692 &repr))
693 break;
694 }
695
696}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdhe_elligator_key_get_public(const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk, struct GNUNET_CRYPTO_EcdhePublicKey *pk, struct GNUNET_CRYPTO_ElligatorRepresentative *repr)
Generates a valid public key for elligator's inverse map by adding a lower order point to a prime ord...

References GNUNET_CRYPTO_ecdhe_elligator_key_get_public(), GNUNET_CRYPTO_random_block(), GNUNET_OK, and pk.

Referenced by GNUNET_CRYPTO_hpke_elligator_kem_encaps().

Here is the call graph for this function:
Here is the caller graph for this function: