GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
gnunet_crypto_lib.h File Reference

cryptographic primitives for GNUnet More...

#include <sodium.h>
#include "gnunet_common.h"
#include <gcrypt.h>
Include dependency graph for gnunet_crypto_lib.h:

Go to the source code of this file.

Data Structures

struct  GNUNET_CRYPTO_HashAsciiEncoded
 0-terminated ASCII encoding of a struct GNUNET_HashCode. More...
 
struct  GNUNET_CRYPTO_EccSignaturePurpose
 header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed data More...
 
struct  GNUNET_CRYPTO_EddsaSignature
 an ECC signature using EdDSA. More...
 
struct  GNUNET_CRYPTO_EcdsaSignature
 an ECC signature using ECDSA More...
 
struct  GNUNET_CRYPTO_EddsaPublicKey
 Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and EdDSA signatures. More...
 
struct  GNUNET_CRYPTO_EcdsaPublicKey
 Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDSA signatures. More...
 
struct  GNUNET_PeerIdentity
 The identity of the host (wraps the signing key of the peer). More...
 
struct  GNUNET_CRYPTO_EcdhePublicKey
 Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encryption (ECDH), See http://cr.yp.to/ecdh.html. More...
 
struct  GNUNET_CRYPTO_EcdhePrivateKey
 Private ECC key encoded for transmission. More...
 
struct  GNUNET_CRYPTO_EcdsaPrivateKey
 Private ECC key encoded for transmission. More...
 
struct  GNUNET_CRYPTO_EddsaPrivateKey
 Private ECC key encoded for transmission. More...
 
struct  GNUNET_CRYPTO_SymmetricSessionKey
 type for session keys More...
 
struct  ChallengeNonceP
 Type of a nonce used for challenges. More...
 
struct  GNUNET_CRYPTO_SymmetricInitializationVector
 IV for sym cipher. More...
 
struct  GNUNET_CRYPTO_AuthKey
 type for (message) authentication keys More...
 
struct  GNUNET_CRYPTO_PaillierPublicKey
 Paillier public key. More...
 
struct  GNUNET_CRYPTO_PaillierPrivateKey
 Paillier private key. More...
 
struct  GNUNET_CRYPTO_PaillierCiphertext
 Paillier ciphertext. More...
 
struct  GNUNET_CRYPTO_PowSalt
 Value for a salt for GNUNET_CRYPTO_pow_hash(). More...
 
struct  GNUNET_CRYPTO_EccPoint
 Point on a curve (always for Curve25519) encoded in a format suitable for network transmission (ECDH), see http://cr.yp.to/ecdh.html. More...
 
struct  GNUNET_CRYPTO_RsaBlindingKeySecret
 Constant-size pre-secret for blinding key generation. More...
 

Macros

#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH   126
 Maximum length of an ECC signature. More...
 
#define GNUNET_CRYPTO_AES_KEY_LENGTH   (256 / 8)
 length of the sessionkey in bytes (256 BIT sessionkey) More...
 
#define GNUNET_CRYPTO_HASH_LENGTH   (512 / 8)
 Length of a hash value. More...
 
#define GNUNET_CRYPTO_PKEY_ASCII_LENGTH   52
 How many characters (without 0-terminator) are our ASCII-encoded public keys (ECDSA/EDDSA/ECDHE). More...
 
#define GNUNET_CRYPTO_PAILLIER_BITS   2048
 Size of paillier plain texts and public keys. More...
 
#define GNUNET_CRYPTO_hash_from_string(enc, result)   GNUNET_CRYPTO_hash_from_string2 (enc, strlen (enc), result)
 Convert ASCII encoding back to struct GNUNET_HashCode More...
 
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
 EdDSA sign a given block. More...
 
#define GNUNET_CRYPTO_ecdsa_sign(priv, ps, sig)
 ECDSA sign a given block. More...
 
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
 Verify EdDSA signature. More...
 
#define GNUNET_CRYPTO_ecdsa_verify(purp, ps, sig, pub)
 Verify ECDSA signature. More...
 

Typedefs

typedef void(* GNUNET_CRYPTO_HashCompletedCallback) (void *cls, const struct GNUNET_HashCode *res)
 Function called once the hash computation over the specified file has completed. More...
 

Enumerations

enum  GNUNET_CRYPTO_Quality { GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_QUALITY_STRONG, GNUNET_CRYPTO_QUALITY_NONCE }
 Desired quality level for random numbers. More...
 

Functions

void GNUNET_CRYPTO_seed_weak_random (int32_t seed)
 Seed a weak random generator. More...
 
uint8_t GNUNET_CRYPTO_crc8_n (const void *buf, size_t len)
 Calculate the checksum of a buffer in one step. More...
 
uint32_t GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len)
 Perform an incremental step in a CRC16 (for TCP/IP) calculation. More...
 
uint16_t GNUNET_CRYPTO_crc16_finish (uint32_t sum)
 Convert results from GNUNET_CRYPTO_crc16_step to final crc16. More...
 
uint16_t GNUNET_CRYPTO_crc16_n (const void *buf, size_t len)
 Calculate the checksum of a buffer in one step. More...
 
int32_t GNUNET_CRYPTO_crc32_n (const void *buf, size_t len)
 Compute the CRC32 checksum for the first len bytes of the buffer. More...
 
void GNUNET_CRYPTO_zero_keys (void *buffer, size_t length)
 Zero out buffer, securely against compiler optimizations. More...
 
void GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
 Fill block with a random values. More...
 
void GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode, struct GNUNET_Uuid *uuid)
 Fill UUID with a timeflake pseudo-random value. More...
 
uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
 Produce a random value. More...
 
uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
 Random on unsigned 64-bit values. More...
 
unsigned int * GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n)
 Get an array with a random permutation of the numbers 0...n-1. More...
 
void GNUNET_CRYPTO_symmetric_create_session_key (struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Create a new random session key. More...
 
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. More...
 
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. More...
 
void GNUNET_CRYPTO_symmetric_derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
 Derive an IV. More...
 
void GNUNET_CRYPTO_symmetric_derive_iv_v (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len, va_list argp)
 Derive an IV. More...
 
void GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block, struct GNUNET_CRYPTO_HashAsciiEncoded *result)
 Convert hash to ASCII encoding. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, struct GNUNET_HashCode *result)
 Convert ASCII encoding back to a 'struct GNUNET_HashCode'. More...
 
uint32_t GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b)
 Compute the distance between 2 hashcodes. More...
 
void GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode *ret)
 Compute hash of a given block. More...
 
void GNUNET_CRYPTO_pow_hash (const struct GNUNET_CRYPTO_PowSalt *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
 Calculate the 'proof-of-work' hash (an expensive hash). More...
 
struct GNUNET_HashContextGNUNET_CRYPTO_hash_context_start (void)
 Start incremental hashing operation. More...
 
struct GNUNET_HashContextGNUNET_CRYPTO_hash_context_copy (const struct GNUNET_HashContext *hc)
 Make a copy of the hash computation. More...
 
void GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc, const void *buf, size_t size)
 Add data to be hashed. More...
 
void GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
 Finish the hash computation. More...
 
void GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc)
 Abort hashing, do not bother calculating final result. More...
 
void GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
 Calculate HMAC of a message (RFC 2104) TODO: Shouldn' this be the standard hmac function and the above be renamed? More...
 
void GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
 Calculate HMAC of a message (RFC 2104) More...
 
struct GNUNET_CRYPTO_FileHashContextGNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, void *callback_cls)
 Compute the hash of an entire file. More...
 
void GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc)
 Cancel a file hashing operation. More...
 
void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, struct GNUNET_HashCode *result)
 Create a random hash code. More...
 
void GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
 compute result = b - a More...
 
void GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *delta, struct GNUNET_HashCode *result)
 compute result = a + delta More...
 
void GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
 compute result = a ^ b More...
 
void GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
 Convert a hashcode into a key. More...
 
int GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code, unsigned int bit)
 Obtain a bit from a hashcode. More...
 
int GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, unsigned int bit)
 Obtain a bit from a hashcode. More...
 
unsigned int GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first, const struct GNUNET_HashCode *second)
 Determine how many low order bits match in two struct GNUNET_HashCodes. More...
 
int GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
 Compare function for HashCodes, producing a total ordering of all hashcodes. More...
 
int GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2, const struct GNUNET_HashCode *target)
 Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia). More...
 
void GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len, va_list argp)
 Derive an authentication key. More...
 
void GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
 Derive an authentication key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
 Derive key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
 Derive key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
 Derive key. More...
 
void GNUNET_CRYPTO_kdf_mod_mpi (gcry_mpi_t *r, gcry_mpi_t n, const void *xts, size_t xts_len, const void *skm, size_t skm_len, const char *ctx)
 Deterministically generate a pseudo-random number uniformly from the integers modulo a libgcrypt mpi. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
 Derive key. More...
 
void GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 Extract the public key for the given private key. More...
 
void GNUNET_CRYPTO_eddsa_key_get_public (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
 Extract the public key for the given private key. More...
 
void GNUNET_CRYPTO_ecdhe_key_get_public (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
 Extract the public key for the given private key. More...
 
char * GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 Convert a public key to a string. More...
 
char * GNUNET_CRYPTO_ecdsa_private_key_to_string (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
 Convert a private key to a string. More...
 
char * GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
 Convert a private key to a string. More...
 
char * GNUNET_CRYPTO_eddsa_public_key_to_string (const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
 Convert a public key to a string. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_public_key_from_string (const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 Convert a string representing a public key to a public key. More...
 
int GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPrivateKey *pub)
 Convert a string representing a private key to a private key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
 Convert a string representing a public key to a public key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, int do_create, struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey)
 Create a new private key by reading it from a file. More...
 
int 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. More...
 
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. More...
 
void GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
 Create a new private key. More...
 
void GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
 Create a new private key. More...
 
void GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
 Create a new private key. More...
 
void GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
 Clear memory that was used to store a private key. More...
 
void GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
 Clear memory that was used to store a private key. More...
 
void GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
 Clear memory that was used to store a private key. More...
 
const struct GNUNET_CRYPTO_EcdsaPrivateKeyGNUNET_CRYPTO_ecdsa_key_get_anonymous (void)
 Get the shared private key we use for anonymous users. More...
 
void GNUNET_CRYPTO_eddsa_setup_hostkey (const char *cfg_name)
 Setup a hostkey file for a peer given the name of the configuration file (!). More...
 
int GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
 Retrieve the identity of the host's peer. More...
 
struct GNUNET_CRYPTO_EccDlogContextGNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max, unsigned int mem)
 Do pre-calculation for ECC discrete logarithm for small factors. More...
 
int GNUNET_CRYPTO_ecc_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t input)
 Calculate ECC discrete logarithm for small factors. More...
 
gcry_mpi_point_t GNUNET_CRYPTO_ecc_dexp (struct GNUNET_CRYPTO_EccDlogContext *edc, int val)
 Multiply the generator g of the elliptic curve by val to obtain the point on the curve representing val. More...
 
gcry_mpi_point_t GNUNET_CRYPTO_ecc_dexp_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_t val)
 Multiply the generator g of the elliptic curve by val to obtain the point on the curve representing val. More...
 
gcry_mpi_point_t GNUNET_CRYPTO_ecc_pmul_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t p, gcry_mpi_t val)
 Multiply the point p on the elliptic curve by val. More...
 
void GNUNET_CRYPTO_ecc_point_to_bin (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t point, struct GNUNET_CRYPTO_EccPoint *bin)
 Convert point value to binary representation. More...
 
gcry_mpi_point_t GNUNET_CRYPTO_ecc_bin_to_point (struct GNUNET_CRYPTO_EccDlogContext *edc, const struct GNUNET_CRYPTO_EccPoint *bin)
 Convert binary representation of a point to computational representation. More...
 
gcry_mpi_point_t GNUNET_CRYPTO_ecc_add (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t a, gcry_mpi_point_t b)
 Add two points on the elliptic curve. More...
 
void GNUNET_CRYPTO_ecc_rnd (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t *r, gcry_mpi_point_t *r_inv)
 Obtain a random point on the curve and its additive inverse. More...
 
void GNUNET_CRYPTO_ecc_rnd_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_t *r, gcry_mpi_t *r_inv)
 Obtain a random scalar for point multiplication on the curve and its multiplicative inverse. More...
 
gcry_mpi_t GNUNET_CRYPTO_ecc_random_mod_n (struct GNUNET_CRYPTO_EccDlogContext *edc)
 Generate a random value mod n. More...
 
void GNUNET_CRYPTO_ecc_free (gcry_mpi_point_t p)
 Free a point value returned by the API. More...
 
void GNUNET_CRYPTO_ecc_dlog_release (struct GNUNET_CRYPTO_EccDlogContext *dlc)
 Release precalculated values. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
 Derive key material from a public and a private ECC key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
 Derive key material from a ECDH public key and a private EdDSA key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
 Derive key material from a ECDH public key and a private ECDSA key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
 Derive key material from a EdDSA public key and a private ECDH key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, struct GNUNET_HashCode *key_material)
 Derive key material from a EcDSA public key and a private ECDH key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_ (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
 EdDSA sign a given block. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_ (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
 ECDSA Sign a given block. More...
 
int GNUNET_CRYPTO_eddsa_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
 Verify EdDSA signature. More...
 
int GNUNET_CRYPTO_ecdsa_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 Verify ECDSA signature. More...
 
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. More...
 
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. More...
 
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. More...
 
void GNUNET_CRYPTO_mpi_scan_unsigned (gcry_mpi_t *result, const void *data, size_t size)
 Convert data buffer into MPI value. More...
 
void GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_key, struct GNUNET_CRYPTO_PaillierPrivateKey *private_key)
 Create a freshly generated paillier public key. More...
 
int GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, const gcry_mpi_t m, int desired_ops, struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext)
 Encrypt a plaintext with a paillier public key. More...
 
void GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey *private_key, const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, const struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext, gcry_mpi_t m)
 Decrypt a paillier ciphertext with a private key. More...
 
int GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, const struct GNUNET_CRYPTO_PaillierCiphertext *c1, const struct GNUNET_CRYPTO_PaillierCiphertext *c2, struct GNUNET_CRYPTO_PaillierCiphertext *result)
 Compute a ciphertext that represents the sum of the plaintext in x1 and x2. More...
 
int GNUNET_CRYPTO_paillier_hom_get_remaining (const struct GNUNET_CRYPTO_PaillierCiphertext *c)
 Get the number of remaining supported homomorphic operations. More...
 
struct GNUNET_CRYPTO_RsaPrivateKeyGNUNET_CRYPTO_rsa_private_key_create (unsigned int len)
 Create a new private key. More...
 
void GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key)
 Free memory occupied by the private key. More...
 
size_t GNUNET_CRYPTO_rsa_private_key_encode (const struct GNUNET_CRYPTO_RsaPrivateKey *key, void **buffer)
 Encode the private key in a format suitable for storing it into a file. More...
 
struct GNUNET_CRYPTO_RsaPrivateKeyGNUNET_CRYPTO_rsa_private_key_decode (const void *buf, size_t buf_size)
 Decode the private key from the data-format back to the "normal", internal format. More...
 
struct GNUNET_CRYPTO_RsaPrivateKeyGNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_RsaPrivateKey *key)
 Duplicate the given private key. More...
 
struct GNUNET_CRYPTO_RsaPublicKeyGNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey *priv)
 Extract the public key of the given private key. More...
 
void GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, struct GNUNET_HashCode *hc)
 Compute hash over the public key. More...
 
unsigned int GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key)
 Obtain the length of the RSA key in bits. More...
 
void GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key)
 Free memory occupied by the public key. More...
 
size_t GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
 Encode the public key in a format suitable for storing it into a file. More...
 
struct GNUNET_CRYPTO_RsaPublicKeyGNUNET_CRYPTO_rsa_public_key_decode (const char *buf, size_t len)
 Decode the public key from the data-format back to the "normal", internal format. More...
 
struct GNUNET_CRYPTO_RsaPublicKeyGNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key)
 Duplicate the given public key. More...
 
int GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, const struct GNUNET_CRYPTO_RsaSignature *s2)
 Compare the values of two signatures. More...
 
int GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, const struct GNUNET_CRYPTO_RsaPrivateKey *p2)
 Compare the values of two private keys. More...
 
int GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, const struct GNUNET_CRYPTO_RsaPublicKey *p2)
 Compare the values of two public keys. More...
 
int GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, void **buf, size_t *buf_size)
 Blinds the given message with the given blinding key. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, const void *msg, size_t msg_len)
 Sign a blinded value, which must be a full domain hash of a message. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, const struct GNUNET_HashCode *hash)
 Create and sign a full domain hash of a message. More...
 
void GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig)
 Free memory occupied by signature. More...
 
size_t GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
 Encode the given signature in a format suitable for storing it into a file. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_signature_decode (const void *buf, size_t buf_size)
 Decode the signature from the data-format back to the "normal", internal format. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig)
 Duplicate the given rsa signature. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey)
 Unblind a blind-signed signature. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaPublicKey *public_key)
 Verify whether the given hash corresponds to the given signature and the signature is valid with respect to the given public key. More...
 

Detailed Description

cryptographic primitives for GNUnet

Author
Christian Grothoff
Krista Bennett
Gerd Knorr kraxe.nosp@m.l@by.nosp@m.tesex.nosp@m..org
Ioana Patrascu
Tzvetan Horozov
Jeffrey Burdges burdg.nosp@m.es@g.nosp@m.nunet.nosp@m..org

Definition in file gnunet_crypto_lib.h.

Macro Definition Documentation

◆ GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH

#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH   126

Maximum length of an ECC signature.

Note: round up to multiple of 8 minus 2 for alignment.

Definition at line 68 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_AES_KEY_LENGTH

#define GNUNET_CRYPTO_AES_KEY_LENGTH   (256 / 8)

◆ GNUNET_CRYPTO_HASH_LENGTH

#define GNUNET_CRYPTO_HASH_LENGTH   (512 / 8)

Length of a hash value.

Definition at line 106 of file gnunet_crypto_lib.h.

Referenced by RPS_sampler_elem_reinit().

◆ GNUNET_CRYPTO_PKEY_ASCII_LENGTH

#define GNUNET_CRYPTO_PKEY_ASCII_LENGTH   52

How many characters (without 0-terminator) are our ASCII-encoded public keys (ECDSA/EDDSA/ECDHE).

Definition at line 112 of file gnunet_crypto_lib.h.

Referenced by uri_loc_parse().

◆ GNUNET_CRYPTO_PAILLIER_BITS

#define GNUNET_CRYPTO_PAILLIER_BITS   2048

Size of paillier plain texts and public keys.

Private keys and ciphertexts are twice this size.

Definition at line 333 of file gnunet_crypto_lib.h.

Referenced by encrypt_fair(), get_fair_encryption_challenge(), GNUNET_CRYPTO_paillier_create(), GNUNET_CRYPTO_paillier_encrypt(), GNUNET_CRYPTO_paillier_encrypt1(), run(), and verify_fair().

Typedef Documentation

◆ GNUNET_CRYPTO_HashCompletedCallback

typedef void(* GNUNET_CRYPTO_HashCompletedCallback) (void *cls, const struct GNUNET_HashCode *res)

Function called once the hash computation over the specified file has completed.

Parameters
clsclosure
resresulting hash, NULL on error

Definition at line 811 of file gnunet_crypto_lib.h.

Function Documentation

◆ GNUNET_CRYPTO_crc16_step()

uint32_t GNUNET_CRYPTO_crc16_step ( uint32_t  sum,
const void *  buf,
size_t  len 
)

Perform an incremental step in a CRC16 (for TCP/IP) calculation.

Parameters
sumcurrent sum, initially 0
bufbuffer to calculate CRC over (must be 16-bit aligned)
lennumber of bytes in buf, must be multiple of 2
Returns
updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16)
Parameters
sumcurrent sum, initially 0
bufbuffer to calculate CRC over (must be 16-bit aligned)
lennumber of bytes in hdr, must be multiple of 2
Returns
updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish() to get actual crc16)

Definition at line 125 of file crypto_crc.c.

References buf.

Referenced by GNUNET_CRYPTO_crc16_n(), GNUNET_TUN_calculate_icmp_checksum(), GNUNET_TUN_calculate_tcp4_checksum(), GNUNET_TUN_calculate_tcp6_checksum(), GNUNET_TUN_calculate_udp4_checksum(), and GNUNET_TUN_calculate_udp6_checksum().

126 {
127  const uint16_t *hdr = buf;
128 
129  for (; len >= 2; len -= 2)
130  sum += *(hdr++);
131  if (len == 1)
132  sum += (*hdr) & ntohs (0xFF00);
133  return sum;
134 }
static char buf[2048]
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_crc16_finish()

uint16_t GNUNET_CRYPTO_crc16_finish ( uint32_t  sum)

Convert results from GNUNET_CRYPTO_crc16_step to final crc16.

Parameters
sumcumulative sum
Returns
crc16 value

Convert results from GNUNET_CRYPTO_crc16_step to final crc16.

Parameters
sumcumulative sum
Returns
crc16 value

Definition at line 144 of file crypto_crc.c.

Referenced by GNUNET_CRYPTO_crc16_n(), GNUNET_TUN_calculate_icmp_checksum(), GNUNET_TUN_calculate_tcp4_checksum(), GNUNET_TUN_calculate_tcp6_checksum(), GNUNET_TUN_calculate_udp4_checksum(), and GNUNET_TUN_calculate_udp6_checksum().

145 {
146  sum = (sum >> 16) + (sum & 0xFFFF);
147  sum += (sum >> 16);
148 
149  return ~sum;
150 }
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_symmetric_derive_iv_v()

void GNUNET_CRYPTO_symmetric_derive_iv_v ( struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
const struct GNUNET_CRYPTO_SymmetricSessionKey skey,
const void *  salt,
size_t  salt_len,
va_list  argp 
)

Derive an IV.

Parameters
ivinitialization vector
skeysession key
saltsalt for the derivation
salt_lensize of the salt
argppairs of void * & size_t for context chunks, terminated by NULL
ivinitialization vector
skeysession key
saltsalt for the derivation
salt_lensize of the salt
argppairs of void * & size_t for context chunks, terminated by NULL

Definition at line 229 of file crypto_symmetric.c.

References GNUNET_CRYPTO_SymmetricInitializationVector::aes_iv, GNUNET_CRYPTO_SymmetricSessionKey::aes_key, GNUNET_CRYPTO_kdf_v(), GNUNET_memcpy, GNUNET_CRYPTO_SymmetricInitializationVector::twofish_iv, and GNUNET_CRYPTO_SymmetricSessionKey::twofish_key.

Referenced by GNUNET_CRYPTO_symmetric_derive_iv().

237 {
238  char aes_salt[salt_len + 4];
239  char twofish_salt[salt_len + 4];
240 
241  GNUNET_memcpy (aes_salt, salt, salt_len);
242  GNUNET_memcpy (&aes_salt[salt_len], "AES!", 4);
243  GNUNET_memcpy (twofish_salt, salt, salt_len);
244  GNUNET_memcpy (&twofish_salt[salt_len], "FISH", 4);
246  sizeof(iv->aes_iv),
247  aes_salt,
248  salt_len + 4,
249  skey->aes_key,
250  sizeof(skey->aes_key),
251  argp);
253  sizeof(iv->twofish_iv),
254  twofish_salt,
255  salt_len + 4,
256  skey->twofish_key,
257  sizeof(skey->twofish_key),
258  argp);
259 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf_v(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
Derive key.
Definition: crypto_kdf.c:47
unsigned char aes_key[(256/8)]
Actual key for AES.
unsigned char twofish_key[(256/8)]
Actual key for TwoFish.
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calcualations.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_pow_hash()

void GNUNET_CRYPTO_pow_hash ( const struct GNUNET_CRYPTO_PowSalt salt,
const void *  buf,
size_t  buf_len,
struct GNUNET_HashCode result 
)

Calculate the 'proof-of-work' hash (an expensive hash).

Parameters
saltsalt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long.
bufdata to hash
buf_lennumber of bytes in buf
resultwhere to write the resulting hash

We're using a non-standard formula to avoid issues with ASICs appearing (see #3795).

Parameters
saltsalt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long.
bufdata to hash
buf_lennumber of bytes in buf
resultwhere to write the resulting hash

Definition at line 41 of file crypto_pow.c.

References GNUNET_break.

Referenced by check_proof_of_work(), find_proof(), GNUNET_REVOCATION_check_pow(), and GNUNET_REVOCATION_pow_round().

45 {
46  /* Threads hardcoded at 1 in libsodium */
47  GNUNET_break (0 ==
48  crypto_pwhash_argon2id ((unsigned char *) result,
49  sizeof (struct GNUNET_HashCode),
50  buf,
51  buf_len,
52  (unsigned char*) salt,
53  3, /* iterations */
54  1024 * 1024, /* memory (1 MiB) */
55  crypto_pwhash_argon2id_ALG_ARGON2ID13));
56 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char buf[2048]
A 512-bit hashcode.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_context_start()

struct GNUNET_HashContext* GNUNET_CRYPTO_hash_context_start ( void  )

Start incremental hashing operation.

Returns
context for incremental hash computation

Definition at line 321 of file crypto_hash.c.

References BENCHMARK_END, BENCHMARK_START, GNUNET_assert, GNUNET_new, and GNUNET_HashContext::hd.

Referenced by GCCH_hash_port(), GNUNET_SET_element_hash(), GNUNET_SETI_element_hash(), and GNUNET_SETU_element_hash().

322 {
323  struct GNUNET_HashContext *hc;
324 
325  BENCHMARK_START (hash_context_start);
326 
327  hc = GNUNET_new (struct GNUNET_HashContext);
328  GNUNET_assert (0 ==
329  gcry_md_open (&hc->hd,
330  GCRY_MD_SHA512,
331  0));
332 
333  BENCHMARK_END (hash_context_start);
334 
335  return hc;
336 }
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gcry_md_hd_t hd
Internal state of the hash function.
Definition: crypto_hash.c:316
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_context_copy()

struct GNUNET_HashContext* GNUNET_CRYPTO_hash_context_copy ( const struct GNUNET_HashContext hc)

Make a copy of the hash computation.

Parameters
hchash context to use (to continue hashing independently)
Returns
copy of hc

Definition at line 351 of file crypto_hash.c.

References GNUNET_assert, GNUNET_new, and GNUNET_HashContext::hd.

352 {
353  struct GNUNET_HashContext *cp;
354 
355  cp = GNUNET_new (struct GNUNET_HashContext);
356  GNUNET_assert (0 ==
357  gcry_md_copy (&cp->hd,
358  hc->hd));
359  return cp;
360 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gcry_md_hd_t hd
Internal state of the hash function.
Definition: crypto_hash.c:316

◆ GNUNET_CRYPTO_hash_context_read()

void GNUNET_CRYPTO_hash_context_read ( struct GNUNET_HashContext hc,
const void *  buf,
size_t  size 
)

Add data to be hashed.

Parameters
hccumulative hash context
bufdata to add
sizenumber of bytes in buf

Definition at line 340 of file crypto_hash.c.

References BENCHMARK_END, BENCHMARK_START, and GNUNET_HashContext::hd.

Referenced by GCCH_hash_port(), GNUNET_SET_element_hash(), GNUNET_SETI_element_hash(), and GNUNET_SETU_element_hash().

343 {
344  BENCHMARK_START (hash_context_read);
345  gcry_md_write (hc->hd, buf, size);
346  BENCHMARK_END (hash_context_read);
347 }
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
gcry_md_hd_t hd
Internal state of the hash function.
Definition: crypto_hash.c:316
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_context_finish()

void GNUNET_CRYPTO_hash_context_finish ( struct GNUNET_HashContext hc,
struct GNUNET_HashCode r_hash 
)

Finish the hash computation.

Parameters
hchash context to use, is freed in the process
r_hashwhere to write the latest / final hash code

Definition at line 364 of file crypto_hash.c.

References BENCHMARK_END, BENCHMARK_START, GNUNET_assert, GNUNET_CRYPTO_hash_context_abort(), GNUNET_memcpy, GNUNET_HashContext::hd, and res.

Referenced by GCCH_hash_port(), GNUNET_SET_element_hash(), GNUNET_SETI_element_hash(), and GNUNET_SETU_element_hash().

366 {
367  const void *res = gcry_md_read (hc->hd, 0);
368 
369  BENCHMARK_START (hash_context_finish);
370 
371  GNUNET_assert (NULL != res);
372  if (NULL != r_hash)
373  GNUNET_memcpy (r_hash,
374  res,
375  sizeof(struct GNUNET_HashCode));
377  BENCHMARK_END (hash_context_finish);
378 }
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_CRYPTO_hash_context_abort(struct GNUNET_HashContext *hc)
Abort hashing, do not bother calculating final result.
Definition: crypto_hash.c:382
A 512-bit hashcode.
static int res
gcry_md_hd_t hd
Internal state of the hash function.
Definition: crypto_hash.c:316
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_context_abort()

void GNUNET_CRYPTO_hash_context_abort ( struct GNUNET_HashContext hc)

Abort hashing, do not bother calculating final result.

Parameters
hchash context to destroy

Definition at line 382 of file crypto_hash.c.

References GNUNET_free, and GNUNET_HashContext::hd.

Referenced by GNUNET_CRYPTO_hash_context_finish().

383 {
384  gcry_md_close (hc->hd);
385  GNUNET_free (hc);
386 }
gcry_md_hd_t hd
Internal state of the hash function.
Definition: crypto_hash.c:316
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hmac_raw()

void GNUNET_CRYPTO_hmac_raw ( const void *  key,
size_t  key_len,
const void *  plaintext,
size_t  plaintext_len,
struct GNUNET_HashCode hmac 
)

Calculate HMAC of a message (RFC 2104) TODO: Shouldn' this be the standard hmac function and the above be renamed?

Parameters
keysecret key
key_lensecret key length
plaintextinput plaintext
plaintext_lenlength of plaintext
hmacwhere to store the hmac

Definition at line 274 of file crypto_hash.c.

References GNUNET_HashCode::bits, GNUNET_assert, GNUNET_memcpy, mc, and once.

Referenced by calculate_hmac(), GNUNET_CRYPTO_hmac(), and OIDC_generate_id_token().

277 {
278  static int once;
279  static gcry_md_hd_t md;
280  const unsigned char *mc;
281 
282  if (! once)
283  {
284  once = 1;
285  GNUNET_assert (GPG_ERR_NO_ERROR ==
286  gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
287  }
288  else
289  {
290  gcry_md_reset (md);
291  }
292  gcry_md_setkey (md, key, key_len);
293  gcry_md_write (md, plaintext, plaintext_len);
294  mc = gcry_md_read (md, GCRY_MD_SHA512);
295  GNUNET_assert (NULL != mc);
296  GNUNET_memcpy (hmac->bits, mc, sizeof(hmac->bits));
297 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int once
Global to mark if we&#39;ve run the initialization.
Definition: gnsrecord.c:68
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t bits[512/8/sizeof(uint32_t)]
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_file_cancel()

void GNUNET_CRYPTO_hash_file_cancel ( struct GNUNET_CRYPTO_FileHashContext fhc)

Cancel a file hashing operation.

Parameters
fhcoperation to cancel (callback must not yet have been invoked)

Definition at line 233 of file crypto_hash_file.c.

References GNUNET_CRYPTO_FileHashContext::fh, GNUNET_CRYPTO_FileHashContext::filename, GNUNET_break, GNUNET_DISK_file_close(), GNUNET_free, GNUNET_OK, GNUNET_SCHEDULER_cancel(), and GNUNET_CRYPTO_FileHashContext::task.

Referenced by client_disconnect_cb(), GNUNET_FS_indexing_done(), GNUNET_FS_unindex_signal_suspend_(), GNUNET_FS_unindex_stop(), and publish_cleanup().

234 {
236  GNUNET_free (fhc->filename);
238  GNUNET_DISK_file_close (fhc->fh));
239  GNUNET_free (fhc);
240 }
struct GNUNET_SCHEDULER_Task * task
Current task for hashing.
struct GNUNET_DISK_FileHandle * fh
File descriptor.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * filename
Name of the file we are hashing.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_get_bit_rtl()

int GNUNET_CRYPTO_hash_get_bit_rtl ( const struct GNUNET_HashCode code,
unsigned int  bit 
)

Obtain a bit from a hashcode.

Parameters
codethe GNUNET_CRYPTO_hash to index bit-wise
bitindex into the hashcode, [0...511] where 0 is the rightmost bit (bytes in code interpreted little endian)
Returns
Bit bit from hashcode code, -1 for invalid index

Definition at line 180 of file crypto_hash.c.

References GNUNET_assert.

Referenced by get_distance(), and GNUNET_CRYPTO_hash_matching_bits().

182 {
183  GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
184  return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
185 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A 512-bit hashcode.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_kdf_v()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf_v ( void *  result,
size_t  out_len,
const void *  xts,
size_t  xts_len,
const void *  skm,
size_t  skm_len,
va_list  argp 
)

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
argpva_list of void * & size_t pairs for context chunks
Returns
GNUNET_YES on success

Definition at line 47 of file crypto_kdf.c.

References GNUNET_CRYPTO_hkdf_v().

Referenced by GNUNET_CRYPTO_hmac_derive_key_v(), GNUNET_CRYPTO_kdf(), and GNUNET_CRYPTO_symmetric_derive_iv_v().

54 {
55  /*
56  * "Finally, we point out to a particularly advantageous instantiation using
57  * HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from SHA-512 is
58  * truncated to 256 bits). This makes sense in two ways: First, the extraction part is where we need a
59  * stronger hash function due to the unconventional demand from the hash function in the extraction
60  * setting. Second, as shown in Section 6, using HMAC with a truncated output as an extractor
61  * allows to prove the security of HKDF under considerably weaker assumptions on the underlying
62  * hash function."
63  *
64  * http://eprint.iacr.org/2010/264
65  *///
67  out_len,
68  GCRY_MD_SHA512,
69  GCRY_MD_SHA256,
70  xts,
71  xts_len,
72  skm,
73  skm_len,
74  argp);
75 }
static int result
Global testing status.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_v(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
Derive key.
Definition: crypto_hkdf.c:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_kdf_mod_mpi()

void GNUNET_CRYPTO_kdf_mod_mpi ( gcry_mpi_t *  r,
gcry_mpi_t  n,
const void *  xts,
size_t  xts_len,
const void *  skm,
size_t  skm_len,
const char *  ctx 
)

Deterministically generate a pseudo-random number uniformly from the integers modulo a libgcrypt mpi.

Parameters
[out]rMPI value set to the FDH
nMPI to work modulo
xtssalt
xts_lenlength of xts
skmsource key material
skm_lenlength of skm
ctxcontext string

Definition at line 127 of file crypto_kdf.c.

References buf, GNUNET_assert, GNUNET_CRYPTO_kdf(), and GNUNET_YES.

Referenced by rsa_blinding_key_derive(), and rsa_full_domain_hash().

132 {
133  gcry_error_t rc;
134  unsigned int nbits;
135  size_t rsize;
136  uint16_t ctr;
137 
138  nbits = gcry_mpi_get_nbits (n);
139  /* GNUNET_assert (nbits > 512); */
140 
141  ctr = 0;
142  while (1)
143  {
144  /* Ain't clear if n is always divisible by 8 */
145  uint8_t buf[ (nbits - 1) / 8 + 1 ];
146  uint16_t ctr_nbo = htons (ctr);
147 
148  rc = GNUNET_CRYPTO_kdf (buf,
149  sizeof(buf),
150  xts, xts_len,
151  skm, skm_len,
152  ctx, strlen (ctx),
153  &ctr_nbo, sizeof(ctr_nbo),
154  NULL, 0);
155  GNUNET_assert (GNUNET_YES == rc);
156 
157  rc = gcry_mpi_scan (r,
158  GCRYMPI_FMT_USG,
159  (const unsigned char *) buf,
160  sizeof(buf),
161  &rsize);
162  GNUNET_assert (0 == rc); /* Allocation error? */
163 
164  gcry_mpi_clear_highbit (*r, nbits);
165  GNUNET_assert (0 == gcry_mpi_test_bit (*r, nbits));
166  ++ctr;
167  /* We reject this FDH if either *r > n and retry with another ctr */
168  if (0 > gcry_mpi_cmp (*r, n))
169  break;
170  gcry_mpi_release (*r);
171  }
172 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:90
static char buf[2048]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_public_key_to_string()

char* GNUNET_CRYPTO_ecdsa_public_key_to_string ( const struct GNUNET_CRYPTO_EcdsaPublicKey pub)

Convert a public key to a string.

Parameters
pubkey to convert
Returns
string representing pub

Definition at line 208 of file crypto_ecc.c.

References end, GNUNET_free, GNUNET_malloc, and GNUNET_STRINGS_data_to_string().

Referenced by abd_value_to_string(), delegation_chain_fw_resolution_start(), forward_resolution(), get_ego(), GNUNET_ABD_delegate_to_string(), handle_intermediate_result(), handle_verify_result(), print_deleset(), and store_cb().

210 {
211  char *pubkeybuf;
212  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
213  char *end;
214 
215  if (keylen % 5 > 0)
216  keylen += 5 - keylen % 5;
217  keylen /= 5;
218  pubkeybuf = GNUNET_malloc (keylen + 1);
219  end =
220  GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
221  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
222  pubkeybuf,
223  keylen);
224  if (NULL == end)
225  {
226  GNUNET_free (pubkeybuf);
227  return NULL;
228  }
229  *end = '\0';
230  return pubkeybuf;
231 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_malloc(size)
Wrapper around malloc.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:872
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_private_key_to_string()

char* GNUNET_CRYPTO_ecdsa_private_key_to_string ( const struct GNUNET_CRYPTO_EcdsaPrivateKey priv)

Convert a private key to a string.

Parameters
privkey to convert
Returns
string representing priv

Definition at line 289 of file crypto_ecc.c.

References end, GNUNET_free, GNUNET_malloc, and GNUNET_STRINGS_data_to_string().

291 {
292  char *privkeybuf;
293  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)) * 8;
294  char *end;
295 
296  if (keylen % 5 > 0)
297  keylen += 5 - keylen % 5;
298  keylen /= 5;
299  privkeybuf = GNUNET_malloc (keylen + 1);
300  end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
301  sizeof(
303  privkeybuf,
304  keylen);
305  if (NULL == end)
306  {
307  GNUNET_free (privkeybuf);
308  return NULL;
309  }
310  *end = '\0';
311  return privkeybuf;
312 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
Private ECC key encoded for transmission.
#define GNUNET_malloc(size)
Wrapper around malloc.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:872
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_eddsa_private_key_to_string()

char* GNUNET_CRYPTO_eddsa_private_key_to_string ( const struct GNUNET_CRYPTO_EddsaPrivateKey priv)

Convert a private key to a string.

Parameters
privkey to convert
Returns
string representing pub

Definition at line 262 of file crypto_ecc.c.

References end, GNUNET_free, GNUNET_malloc, and GNUNET_STRINGS_data_to_string().

Referenced by run().

264 {
265  char *privkeybuf;
266  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
267  char *end;
268 
269  if (keylen % 5 > 0)
270  keylen += 5 - keylen % 5;
271  keylen /= 5;
272  privkeybuf = GNUNET_malloc (keylen + 1);
273  end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
274  sizeof(
276  privkeybuf,
277  keylen);
278  if (NULL == end)
279  {
280  GNUNET_free (privkeybuf);
281  return NULL;
282  }
283  *end = '\0';
284  return privkeybuf;
285 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
Private ECC key encoded for transmission.
#define GNUNET_malloc(size)
Wrapper around malloc.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:872
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_public_key_to_string()

char* GNUNET_CRYPTO_eddsa_public_key_to_string ( const struct GNUNET_CRYPTO_EddsaPublicKey pub)

Convert a public key to a string.

Parameters
pubkey to convert
Returns
string representing pub

Definition at line 235 of file crypto_ecc.c.

References end, GNUNET_free, GNUNET_malloc, and GNUNET_STRINGS_data_to_string().

Referenced by conversation_value_to_string(), create_keys(), GCP_2s(), GNUNET_FRIENDS_write(), GNUNET_HELLO_compose_uri(), GNUNET_i2s(), GNUNET_i2s2(), GNUNET_i2s_full(), main(), print_key(), run(), and uri_loc_to_string().

237 {
238  char *pubkeybuf;
239  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
240  char *end;
241 
242  if (keylen % 5 > 0)
243  keylen += 5 - keylen % 5;
244  keylen /= 5;
245  pubkeybuf = GNUNET_malloc (keylen + 1);
246  end =
247  GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
248  sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
249  pubkeybuf,
250  keylen);
251  if (NULL == end)
252  {
253  GNUNET_free (pubkeybuf);
254  return NULL;
255  }
256  *end = '\0';
257  return pubkeybuf;
258 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_malloc(size)
Wrapper around malloc.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:872
#define GNUNET_free(ptr)
Wrapper around free.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_public_key_from_string()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_public_key_from_string ( const char *  enc,
size_t  enclen,
struct GNUNET_CRYPTO_EcdsaPublicKey pub 
)

Convert a string representing a public key to a public key.

Parameters
encencoded public key
enclennumber of bytes in enc (without 0-terminator)
pubwhere to store the public key
Returns
GNUNET_OK on success

Definition at line 316 of file crypto_ecc.c.

References GNUNET_OK, GNUNET_STRINGS_string_to_data(), and GNUNET_SYSERR.

Referenced by abd_string_to_value(), access_handler_callback(), GNUNET_ABD_delegate_from_string(), identity_cb(), run(), and sign_cb().

320 {
321  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
322 
323  if (keylen % 5 > 0)
324  keylen += 5 - keylen % 5;
325  keylen /= 5;
326  if (enclen != keylen)
327  return GNUNET_SYSERR;
328 
329  if (GNUNET_OK !=
331  enclen,
332  pub,
333  sizeof(
335  return GNUNET_SYSERR;
336  return GNUNET_OK;
337 }
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
static OpusEncoder * enc
OPUS encoder.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_eddsa_private_key_from_string()

int GNUNET_CRYPTO_eddsa_private_key_from_string ( const char *  enc,
size_t  enclen,
struct GNUNET_CRYPTO_EddsaPrivateKey pub 
)

Convert a string representing a private key to a private key.

Parameters
encencoded public key
enclennumber of bytes in enc (without 0-terminator)
privwhere to store the private key
Returns
GNUNET_OK on success

Definition at line 366 of file crypto_ecc.c.

References GNUNET_break, GNUNET_OK, GNUNET_STRINGS_string_to_data(), and GNUNET_SYSERR.

370 {
371  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
372 
373  if (keylen % 5 > 0)
374  keylen += 5 - keylen % 5;
375  keylen /= 5;
376  if (enclen != keylen)
377  return GNUNET_SYSERR;
378 
379  if (GNUNET_OK !=
381  enclen,
382  priv,
383  sizeof(
385  return GNUNET_SYSERR;
386 #if CRYPTO_BUG
387  if (GNUNET_OK != check_eddsa_key (priv))
388  {
389  GNUNET_break (0);
390  return GNUNET_OK;
391  }
392 #endif
393  return GNUNET_OK;
394 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Private ECC key encoded for transmission.
static OpusEncoder * enc
OPUS encoder.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
Here is the call graph for this function:

◆ GNUNET_CRYPTO_eddsa_public_key_from_string()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string ( const char *  enc,
size_t  enclen,
struct GNUNET_CRYPTO_EddsaPublicKey pub 
)

Convert a string representing a public key to a public key.

Parameters
encencoded public key
enclennumber of bytes in enc (without 0-terminator)
pubwhere to store the public key
Returns
GNUNET_OK on success

Definition at line 341 of file crypto_ecc.c.

References GNUNET_OK, GNUNET_STRINGS_string_to_data(), and GNUNET_SYSERR.

Referenced by blacklist_cfg_iter(), conversation_string_to_value(), create_keys(), gns_string_to_value(), GNUNET_FRIENDS_parse(), hosts_directory_scan_callback(), on_identity(), run(), s2i_full(), server_parse_url(), show_peer(), and uri_loc_parse().

345 {
346  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
347 
348  if (keylen % 5 > 0)
349  keylen += 5 - keylen % 5;
350  keylen /= 5;
351  if (enclen != keylen)
352  return GNUNET_SYSERR;
353 
354  if (GNUNET_OK !=
356  enclen,
357  pub,
358  sizeof(
360  return GNUNET_SYSERR;
361  return GNUNET_OK;
362 }
static OpusEncoder * enc
OPUS encoder.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_dlog_prepare()

struct GNUNET_CRYPTO_EccDlogContext* GNUNET_CRYPTO_ecc_dlog_prepare ( unsigned int  max,
unsigned int  mem 
)

Do pre-calculation for ECC discrete logarithm for small factors.

Parameters
maxmaximum value the factor can be
memmemory to use (should be smaller than max), must not be zero.
Returns
NULL on error

Definition at line 157 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, CURVE, edc, extract_pk(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_CRYPTO_EccDlogContext::map, GNUNET_CRYPTO_EccDlogContext::max, and GNUNET_CRYPTO_EccDlogContext::mem.

Referenced by run().

159 {
161  unsigned int K = ((max + (mem - 1)) / mem);
162  gcry_mpi_point_t g;
163  struct GNUNET_PeerIdentity key;
164  gcry_mpi_point_t gKi;
165  gcry_mpi_t fact;
166  gcry_mpi_t n;
167  unsigned int i;
168 
169  GNUNET_assert (max < INT32_MAX);
171  edc->max = max;
172  edc->mem = mem;
173 
175  GNUNET_NO);
176 
177  GNUNET_assert (0 == gcry_mpi_ec_new (&edc->ctx,
178  NULL,
179  CURVE));
180  g = gcry_mpi_ec_get_point ("g", edc->ctx, 0);
181  GNUNET_assert (NULL != g);
182  fact = gcry_mpi_new (0);
183  gKi = gcry_mpi_point_new (0);
184  for (i = 0; i <= mem; i++)
185  {
186  gcry_mpi_set_ui (fact, i * K);
187  gcry_mpi_ec_mul (gKi, fact, g, edc->ctx);
188  extract_pk (gKi, edc->ctx, &key);
191  &key,
192  (void *) (long) i + max,
194  }
195  /* negative values */
196  n = gcry_mpi_ec_get_mpi ("n", edc->ctx, 1);
197  for (i = 1; i < mem; i++)
198  {
199  gcry_mpi_set_ui (fact, i * K);
200  gcry_mpi_sub (fact, n, fact);
201  gcry_mpi_ec_mul (gKi, fact, g, edc->ctx);
202  extract_pk (gKi, edc->ctx, &key);
205  &key,
206  (void *) (long) max - i,
208  }
209  gcry_mpi_release (fact);
210  gcry_mpi_release (n);
211  gcry_mpi_point_release (gKi);
212  gcry_mpi_point_release (g);
213  return edc;
214 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiPeerMap * map
Map mapping points (here "interpreted" as EdDSA public keys) to a "void * = long" which corresponds t...
static void extract_pk(gcry_mpi_point_t pt, gcry_ctx_t ctx, struct GNUNET_PeerIdentity *pid)
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
static struct GNUNET_CRYPTO_EccDlogContext * edc
Context for DLOG operations on a curve.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_HashCode key
The key used in the DHT.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
The identity of the host (wraps the signing key of the peer).
Internal structure used to cache pre-calculated values for DLOG calculation.
#define CURVE
Name of the curve we are using.
unsigned int max
Maximum absolute value the calculation supports.
unsigned int mem
How much memory should we use (relates to the number of entries in the map).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_dlog()

int GNUNET_CRYPTO_ecc_dlog ( struct GNUNET_CRYPTO_EccDlogContext edc,
gcry_mpi_point_t  input 
)

Calculate ECC discrete logarithm for small factors.

Opposite of GNUNET_CRYPTO_ecc_dexp().

Parameters
dlcprecalculated values, determine range of factors
inputpoint on the curve to factor
Returns
INT_MAX if dlog failed, otherwise the factor
Parameters
edcprecalculated values, determine range of factors
inputpoint on the curve to factor
Returns
INT_MAX if dlog failed, otherwise the factor

Definition at line 225 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, extract_pk(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), INT_MAX, GNUNET_CRYPTO_EccDlogContext::map, GNUNET_CRYPTO_EccDlogContext::max, GNUNET_CRYPTO_EccDlogContext::mem, q, and res.

Referenced by compute_scalar_product().

227 {
228  unsigned int K = ((edc->max + (edc->mem - 1)) / edc->mem);
229  gcry_mpi_point_t g;
230  struct GNUNET_PeerIdentity key;
231  gcry_mpi_point_t q;
232  unsigned int i;
233  int res;
234  void *retp;
235 
236  g = gcry_mpi_ec_get_point ("g", edc->ctx, 0);
237  GNUNET_assert (NULL != g);
238  q = gcry_mpi_point_new (0);
239 
240  res = INT_MAX;
241  for (i = 0; i <= edc->max / edc->mem; i++)
242  {
243  if (0 == i)
244  extract_pk (input, edc->ctx, &key);
245  else
246  extract_pk (q, edc->ctx, &key);
248  &key);
249  if (NULL != retp)
250  {
251  res = (((long) retp) - edc->max) * K - i;
252  /* we continue the loop here to make the implementation
253  "constant-time". If we do not care about this, we could just
254  'break' here and do fewer operations... */
255  }
256  if (i == edc->max / edc->mem)
257  break;
258  /* q = q + g */
259  if (0 == i)
260  gcry_mpi_ec_add (q, input, g, edc->ctx);
261  else
262  gcry_mpi_ec_add (q, q, g, edc->ctx);
263  }
264  gcry_mpi_point_release (g);
265  gcry_mpi_point_release (q);
266 
267  return res;
268 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiPeerMap * map
Map mapping points (here "interpreted" as EdDSA public keys) to a "void * = long" which corresponds t...
static void extract_pk(gcry_mpi_point_t pt, gcry_ctx_t ctx, struct GNUNET_PeerIdentity *pid)
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
#define INT_MAX
static int res
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
struct GNUNET_HashCode key
The key used in the DHT.
The identity of the host (wraps the signing key of the peer).
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
unsigned int max
Maximum absolute value the calculation supports.
unsigned int mem
How much memory should we use (relates to the number of entries in the map).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_dexp()

gcry_mpi_point_t GNUNET_CRYPTO_ecc_dexp ( struct GNUNET_CRYPTO_EccDlogContext edc,
int  val 
)

Multiply the generator g of the elliptic curve by val to obtain the point on the curve representing val.

Afterwards, point addition will correspond to integer addition. GNUNET_CRYPTO_ecc_dlog() can be used to convert a point back to an integer (as long as the integer is smaller than the MAX of the edc context).

Parameters
edccalculation context for ECC operations
valvalue to encode into a point
Returns
representation of the value as an ECC point, must be freed using GNUNET_CRYPTO_ecc_free()

Definition at line 334 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, and GNUNET_assert.

336 {
337  gcry_mpi_t fact;
338  gcry_mpi_t n;
339  gcry_mpi_point_t g;
340  gcry_mpi_point_t r;
341 
342  g = gcry_mpi_ec_get_point ("g", edc->ctx, 0);
343  GNUNET_assert (NULL != g);
344  fact = gcry_mpi_new (0);
345  if (val < 0)
346  {
347  n = gcry_mpi_ec_get_mpi ("n", edc->ctx, 1);
348  gcry_mpi_set_ui (fact, -val);
349  gcry_mpi_sub (fact, n, fact);
350  gcry_mpi_release (n);
351  }
352  else
353  {
354  gcry_mpi_set_ui (fact, val);
355  }
356  r = gcry_mpi_point_new (0);
357  gcry_mpi_ec_mul (r, fact, g, edc->ctx);
358  gcry_mpi_release (fact);
359  gcry_mpi_point_release (g);
360  return r;
361 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.

◆ GNUNET_CRYPTO_ecc_dexp_mpi()

gcry_mpi_point_t GNUNET_CRYPTO_ecc_dexp_mpi ( struct GNUNET_CRYPTO_EccDlogContext edc,
gcry_mpi_t  val 
)

Multiply the generator g of the elliptic curve by val to obtain the point on the curve representing val.

Parameters
edccalculation context for ECC operations
val(positive) value to encode into a point
Returns
representation of the value as an ECC point, must be freed using GNUNET_CRYPTO_ecc_free()

Definition at line 374 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, and GNUNET_assert.

Referenced by send_alices_cryptodata_message().

376 {
377  gcry_mpi_point_t g;
378  gcry_mpi_point_t r;
379 
380  g = gcry_mpi_ec_get_point ("g", edc->ctx, 0);
381  GNUNET_assert (NULL != g);
382  r = gcry_mpi_point_new (0);
383  gcry_mpi_ec_mul (r, val, g, edc->ctx);
384  gcry_mpi_point_release (g);
385  return r;
386 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_pmul_mpi()

gcry_mpi_point_t GNUNET_CRYPTO_ecc_pmul_mpi ( struct GNUNET_CRYPTO_EccDlogContext edc,
gcry_mpi_point_t  p,
gcry_mpi_t  val 
)

Multiply the point p on the elliptic curve by val.

Parameters
edccalculation context for ECC operations
ppoint to multiply
val(positive) value to encode into a point
Returns
representation of the value as an ECC point, must be freed using GNUNET_CRYPTO_ecc_free()

Definition at line 420 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx.

Referenced by compute_scalar_product(), and handle_alices_cryptodata_message().

423 {
424  gcry_mpi_point_t r;
425 
426  r = gcry_mpi_point_new (0);
427  gcry_mpi_ec_mul (r, val, p, edc->ctx);
428  return r;
429 }
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_point_to_bin()

void GNUNET_CRYPTO_ecc_point_to_bin ( struct GNUNET_CRYPTO_EccDlogContext edc,
gcry_mpi_point_t  point,
struct GNUNET_CRYPTO_EccPoint bin 
)

Convert point value to binary representation.

Parameters
edccalculation context for ECC operations
pointcomputational point representation
[out]binbinary point representation

Definition at line 101 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, GNUNET_assert, GNUNET_CRYPTO_mpi_print_unsigned(), and GNUNET_CRYPTO_EccPoint::q_y.

Referenced by send_alices_cryptodata_message(), and transmit_bobs_cryptodata_message().

104 {
105  gcry_mpi_t q_y;
106 
107  GNUNET_assert (0 == gcry_mpi_ec_set_point ("q", point, edc->ctx));
108  q_y = gcry_mpi_ec_get_mpi ("q@eddsa", edc->ctx, 0);
109  GNUNET_assert (q_y);
111  sizeof(bin->q_y),
112  q_y);
113  gcry_mpi_release (q_y);
114 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:78
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
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...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_bin_to_point()

gcry_mpi_point_t GNUNET_CRYPTO_ecc_bin_to_point ( struct GNUNET_CRYPTO_EccDlogContext edc,
const struct GNUNET_CRYPTO_EccPoint bin 
)

Convert binary representation of a point to computational representation.

Parameters
edccalculation context for ECC operations
binbinary point representation
Returns
computational representation

Definition at line 125 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, CURVE, GNUNET_assert, GNUNET_break, q, and GNUNET_CRYPTO_EccPoint::q_y.

Referenced by handle_alices_cryptodata_message(), and handle_bobs_cryptodata_message().

127 {
128  gcry_sexp_t pub_sexpr;
129  gcry_ctx_t ctx;
130  gcry_mpi_point_t q;
131 
132  (void) edc;
133  if (0 != gcry_sexp_build (&pub_sexpr, NULL,
134  "(public-key(ecc(curve " CURVE ")(q %b)))",
135  (int) sizeof(bin->q_y),
136  bin->q_y))
137  {
138  GNUNET_break (0);
139  return NULL;
140  }
141  GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, pub_sexpr, NULL));
142  gcry_sexp_release (pub_sexpr);
143  q = gcry_mpi_ec_get_point ("q", ctx, 0);
144  gcry_ctx_release (ctx);
145  return q;
146 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
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...
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
#define CURVE
Name of the curve we are using.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_add()

gcry_mpi_point_t GNUNET_CRYPTO_ecc_add ( struct GNUNET_CRYPTO_EccDlogContext edc,
gcry_mpi_point_t  a,
gcry_mpi_point_t  b 
)

Add two points on the elliptic curve.

Parameters
edccalculation context for ECC operations
asome value
bsome value
Returns
a + b, must be freed using GNUNET_CRYPTO_ecc_free()

Definition at line 398 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx.

Referenced by compute_scalar_product(), and handle_alices_cryptodata_message().

401 {
402  gcry_mpi_point_t r;
403 
404  r = gcry_mpi_point_new (0);
405  gcry_mpi_ec_add (r, a, b, edc->ctx);
406  return r;
407 }
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_rnd()

void GNUNET_CRYPTO_ecc_rnd ( struct GNUNET_CRYPTO_EccDlogContext edc,
gcry_mpi_point_t *  r,
gcry_mpi_point_t *  r_inv 
)

Obtain a random point on the curve and its additive inverse.

Both returned values must be freed using GNUNET_CRYPTO_ecc_free().

Parameters
edccalculation context for ECC operations
[out]rset to a random point on the curve
[out]r_invset to the additive inverse of r

Definition at line 442 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, GNUNET_assert, and GNUNET_CRYPTO_ecc_random_mod_n().

445 {
446  gcry_mpi_t fact;
447  gcry_mpi_t n;
448  gcry_mpi_point_t g;
449 
450  fact = GNUNET_CRYPTO_ecc_random_mod_n (edc);
451 
452  /* calculate 'r' */
453  g = gcry_mpi_ec_get_point ("g", edc->ctx, 0);
454  GNUNET_assert (NULL != g);
455  *r = gcry_mpi_point_new (0);
456  gcry_mpi_ec_mul (*r, fact, g, edc->ctx);
457 
458  /* calculate 'r_inv' */
459  n = gcry_mpi_ec_get_mpi ("n", edc->ctx, 1);
460  gcry_mpi_sub (fact, n, fact); /* fact = n - fact = - fact */
461  *r_inv = gcry_mpi_point_new (0);
462  gcry_mpi_ec_mul (*r_inv, fact, g, edc->ctx);
463 
464  gcry_mpi_release (n);
465  gcry_mpi_release (fact);
466  gcry_mpi_point_release (g);
467 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
gcry_mpi_t GNUNET_CRYPTO_ecc_random_mod_n(struct GNUNET_CRYPTO_EccDlogContext *edc)
Generate a random value mod n.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_ecc_rnd_mpi()

void GNUNET_CRYPTO_ecc_rnd_mpi ( struct GNUNET_CRYPTO_EccDlogContext edc,
gcry_mpi_t *  r,
gcry_mpi_t *  r_inv 
)

Obtain a random scalar for point multiplication on the curve and its multiplicative inverse.

Parameters
edccalculation context for ECC operations
[out]rset to a random scalar on the curve
[out]r_invset to the multiplicative inverse of r

Definition at line 479 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, and GNUNET_CRYPTO_ecc_random_mod_n().

Referenced by run().

482 {
483  gcry_mpi_t n;
484 
486  /* r_inv = n - r = - r */
487  *r_inv = gcry_mpi_new (0);
488  n = gcry_mpi_ec_get_mpi ("n", edc->ctx, 1);
489  gcry_mpi_sub (*r_inv, n, *r);
490 }
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
gcry_mpi_t GNUNET_CRYPTO_ecc_random_mod_n(struct GNUNET_CRYPTO_EccDlogContext *edc)
Generate a random value mod n.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_random_mod_n()

gcry_mpi_t GNUNET_CRYPTO_ecc_random_mod_n ( struct GNUNET_CRYPTO_EccDlogContext edc)

Generate a random value mod n.

Parameters
edcECC context
Returns
random value mod n.

Definition at line 278 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, and GNUNET_assert.

Referenced by GNUNET_CRYPTO_ecc_rnd(), GNUNET_CRYPTO_ecc_rnd_mpi(), and send_alices_cryptodata_message().

279 {
280  gcry_mpi_t n;
281  unsigned int highbit;
282  gcry_mpi_t r;
283 
284  n = gcry_mpi_ec_get_mpi ("n", edc->ctx, 1);
285 
286  /* check public key for number of bits, bail out if key is all zeros */
287  highbit = 256; /* Curve25519 */
288  while ((! gcry_mpi_test_bit (n, highbit)) &&
289  (0 != highbit))
290  highbit--;
291  GNUNET_assert (0 != highbit);
292  /* generate fact < n (without bias) */
293  GNUNET_assert (NULL != (r = gcry_mpi_new (0)));
294  do
295  {
296  gcry_mpi_randomize (r,
297  highbit + 1,
298  GCRY_STRONG_RANDOM);
299  }
300  while (gcry_mpi_cmp (r, n) >= 0);
301  gcry_mpi_release (n);
302  return r;
303 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_free()

void GNUNET_CRYPTO_ecc_free ( gcry_mpi_point_t  p)

Free a point value returned by the API.

Parameters
ppoint to free

Definition at line 499 of file crypto_ecc_dlog.c.

500 {
501  gcry_mpi_point_release (p);
502 }
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59

◆ GNUNET_CRYPTO_ecc_dlog_release()

void GNUNET_CRYPTO_ecc_dlog_release ( struct GNUNET_CRYPTO_EccDlogContext edc)

Release precalculated values.

Parameters
dlcdlog context
edcdlog context

Definition at line 312 of file crypto_ecc_dlog.c.

References GNUNET_CRYPTO_EccDlogContext::ctx, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_free, and GNUNET_CRYPTO_EccDlogContext::map.

Referenced by shutdown_task().

313 {
314  gcry_ctx_release (edc->ctx);
316  GNUNET_free (edc);
317 }
struct GNUNET_CONTAINER_MultiPeerMap * map
Map mapping points (here "interpreted" as EdDSA public keys) to a "void * = long" which corresponds t...
gcry_ctx_t ctx
Context to use for operations on the elliptic curve.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_mpi_print_unsigned()

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.

The MPI val may not be negative.

Parameters
bufwhere to output to
sizenumber of bytes in buf
valvalue to write to buf

Definition at line 78 of file crypto_mpi.c.

References adjust(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_memcpy, LOG_GCRY, p, and size.

Referenced by decrypt_conclude(), encrypt_fair(), extract_pk(), GNUNET_CRYPTO_ecc_point_to_bin(), GNUNET_CRYPTO_ecdsa_key_get_anonymous(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_ecdsa_sign_(), GNUNET_CRYPTO_paillier_create(), GNUNET_CRYPTO_paillier_encrypt(), GNUNET_CRYPTO_paillier_encrypt1(), GNUNET_CRYPTO_paillier_hom_add(), GNUNET_SECRETSHARING_encrypt(), GNUNET_SECRETSHARING_plaintext_generate_i(), insert_decrypt_element(), insert_round1_element(), insert_round2_element(), and keygen_round2_conclude().

81 {
82  size_t rsize;
83  int rc;
84 
85  if (gcry_mpi_get_flag (val, GCRYMPI_FLAG_OPAQUE))
86  {
87  /* Store opaque MPIs left aligned into the buffer. */
88  unsigned int nbits;
89  const void *p;
90 
91  p = gcry_mpi_get_opaque (val, &nbits);
92  GNUNET_assert (p);
93  rsize = (nbits + 7) / 8;
94  if (rsize > size)
95  rsize = size;
96  GNUNET_memcpy (buf, p, rsize);
97  if (rsize < size)
98  memset (buf + rsize, 0, size - rsize);
99  }
100  else
101  {
102  /* Store regular MPIs as unsigned integers right aligned into
103  the buffer. */
104  rsize = size;
105  if (0 !=
106  (rc = gcry_mpi_print (GCRYMPI_FMT_USG,
107  buf,
108  rsize, &rsize,
109  val)))
110  {
112  "gcry_mpi_print",
113  rc);
114  GNUNET_assert (0);
115  }
116  adjust (buf, rsize, size);
117  }
118 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Definition: crypto_mpi.c:39
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
static void adjust(void *buf, size_t size, size_t target)
If target != size, move target bytes to the end of the size-sized buffer and zero out the first targe...
Definition: crypto_mpi.c:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_mpi_scan_unsigned()

void GNUNET_CRYPTO_mpi_scan_unsigned ( gcry_mpi_t *  result,
const void *  data,
size_t  size 
)

Convert data buffer into MPI value.

The buffer is interpreted as network byte order, unsigned integer.

Parameters
resultwhere to store MPI value (allocated)
dataraw data (GCRYMPI_FMT_USG)
sizenumber of bytes in data

Definition at line 131 of file crypto_mpi.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, and LOG_GCRY.

Referenced by decrypt_conclude(), decrypt_new_element(), derive_h(), encrypt_fair(), get_fair_encryption_challenge(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_paillier_decrypt(), GNUNET_CRYPTO_paillier_encrypt(), GNUNET_CRYPTO_paillier_encrypt1(), GNUNET_CRYPTO_paillier_hom_add(), GNUNET_SECRETSHARING_encrypt(), insert_decrypt_element(), keygen_reveal_get_exp_coeff(), keygen_reveal_get_exp_preshare(), keygen_round1_new_element(), restore_fair(), and verify_fair().

134 {
135  int rc;
136 
137  if (0 != (rc = gcry_mpi_scan (result,
138  GCRYMPI_FMT_USG,
139  data, size, &size)))
140  {
142  "gcry_mpi_scan",
143  rc);
144  GNUNET_assert (0);
145  }
146 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Definition: crypto_mpi.c:39
static int result
Global testing status.
static unsigned int size
Size of the "table".
Definition: peer.c:67
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_paillier_create()

void GNUNET_CRYPTO_paillier_create ( struct GNUNET_CRYPTO_PaillierPublicKey public_key,
struct GNUNET_CRYPTO_PaillierPrivateKey private_key 
)

Create a freshly generated paillier public key.

Parameters
[out]public_keyWhere to store the public key?
[out]private_keyWhere to store the private key?

Definition at line 39 of file crypto_paillier.c.

References GNUNET_assert, GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_CRYPTO_PAILLIER_BITS, GNUNET_CRYPTO_PaillierPrivateKey::lambda, GNUNET_CRYPTO_PaillierPrivateKey::mu, p, and q.

Referenced by handle_client_keygen(), and run().

43 {
44  gcry_mpi_t p;
45  gcry_mpi_t q;
46  gcry_mpi_t phi;
47  gcry_mpi_t mu;
48  gcry_mpi_t n;
49 
50  /* Generate two distinct primes. The probability that the loop body
51  is executed more than once is very very low... */
52  p = NULL;
53  q = NULL;
54  do
55  {
56  if (NULL != p)
57  gcry_mpi_release (p);
58  if (NULL != q)
59  gcry_mpi_release (q);
60  GNUNET_assert (0 ==
61  gcry_prime_generate (&p,
63  0, NULL, NULL, NULL,
64  GCRY_STRONG_RANDOM, 0));
65  GNUNET_assert (0 ==
66  gcry_prime_generate (&q,
68  0, NULL, NULL, NULL,
69  GCRY_STRONG_RANDOM, 0));
70  }
71  while (0 == gcry_mpi_cmp (p, q));
72  /* n = p * q */
73  GNUNET_assert (NULL != (n = gcry_mpi_new (0)));
74  gcry_mpi_mul (n,
75  p,
76  q);
78  sizeof(struct
80  n);
81 
82  /* compute phi(n) = (p-1)(q-1) */
83  GNUNET_assert (NULL != (phi = gcry_mpi_new (0)));
84  gcry_mpi_sub_ui (p, p, 1);
85  gcry_mpi_sub_ui (q, q, 1);
86  gcry_mpi_mul (phi, p, q);
87  gcry_mpi_release (p);
88  gcry_mpi_release (q);
89 
90  /* lambda equals phi(n) in the simplified key generation */
93  phi);
94  /* mu = phi^{-1} mod n, as we use g = n + 1 */
95  GNUNET_assert (NULL != (mu = gcry_mpi_new (0)));
96  GNUNET_assert (0 != gcry_mpi_invm (mu,
97  phi,
98  n));
99  gcry_mpi_release (phi);
100  gcry_mpi_release (n);
101  GNUNET_CRYPTO_mpi_print_unsigned (private_key->mu,
103  mu);
104  gcry_mpi_release (mu);
105 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:78
unsigned char lambda[2048/8]
Lambda-component of the private key.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
unsigned char mu[2048/8]
Mu-component of the private key.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
#define GNUNET_CRYPTO_PAILLIER_BITS
Size of paillier plain texts and public keys.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_paillier_encrypt()

int GNUNET_CRYPTO_paillier_encrypt ( const struct GNUNET_CRYPTO_PaillierPublicKey public_key,
const gcry_mpi_t  m,
int  desired_ops,
struct GNUNET_CRYPTO_PaillierCiphertext ciphertext 
)

Encrypt a plaintext with a paillier public key.

Parameters
public_keyPublic key to use.
mPlaintext to encrypt.
desired_opsHow many homomorphic ops the caller intends to use
[out]ciphertextEncryption of plaintext with public_key.
Returns
guaranteed number of supported homomorphic operations >= 1, or desired_ops, in case that is lower, or -1 if less than one homomorphic operation is possible

Definition at line 220 of file crypto_paillier.c.

References GNUNET_CRYPTO_PaillierCiphertext::bits, GNUNET_assert, GNUNET_break_op, GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_CRYPTO_mpi_scan_unsigned(), GNUNET_CRYPTO_PAILLIER_BITS, GNUNET_MIN, GNUNET_SYSERR, and GNUNET_CRYPTO_PaillierCiphertext::remaining_ops.

Referenced by compute_service_response(), and send_alices_cryptodata_message().

226 {
227  int possible_opts;
228  gcry_mpi_t n_square;
229  gcry_mpi_t r;
230  gcry_mpi_t rn;
231  gcry_mpi_t g;
232  gcry_mpi_t gm;
233  gcry_mpi_t c;
234  gcry_mpi_t n;
235  gcry_mpi_t max_num;
236  unsigned int highbit;
237 
238  /* set max_num = 2^{GNUNET_CRYPTO_PAILLIER_BITS}, the largest
239  number we can have as a result */
240  GNUNET_assert (NULL != (max_num = gcry_mpi_set_ui (NULL, 1)));
241  gcry_mpi_mul_2exp (max_num,
242  max_num,
244 
245  /* Determine how many operations we could allow, assuming the other
246  number has the same length (or is smaller), by counting the
247  number of possible operations. We essentially divide max_num by
248  2 until the result is no longer larger than 'm', incrementing the
249  maximum number of operations in each round, starting at -2 */for (possible_opts = -2; gcry_mpi_cmp (max_num, m) > 0; possible_opts++)
250  gcry_mpi_div (max_num,
251  NULL,
252  max_num,
253  GCRYMPI_CONST_TWO,
254  0);
255  gcry_mpi_release (max_num);
256 
257  if (possible_opts < 1)
258  possible_opts = 0;
259  /* Enforce soft-cap by caller */
260  possible_opts = GNUNET_MIN (desired_ops, possible_opts);
261  ciphertext->remaining_ops = htonl (possible_opts);
262 
264  public_key,
265  sizeof(struct
267 
268  /* check public key for number of bits, bail out if key is all zeros */
269  highbit = GNUNET_CRYPTO_PAILLIER_BITS - 1;
270  while ((! gcry_mpi_test_bit (n, highbit)) &&
271  (0 != highbit))
272  highbit--;
273  if (0 == highbit)
274  {
275  /* invalid public key */
276  GNUNET_break_op (0);
277  gcry_mpi_release (n);
278  return GNUNET_SYSERR;
279  }
280 
281  /* generate r < n (without bias) */
282  GNUNET_assert (NULL != (r = gcry_mpi_new (0)));
283  do
284  {
285  gcry_mpi_randomize (r, highbit + 1, GCRY_STRONG_RANDOM);
286  }
287  while (gcry_mpi_cmp (r, n) >= 0);
288 
289  /* g = n + 1 */
290  GNUNET_assert (0 != (g = gcry_mpi_new (0)));
291  gcry_mpi_add_ui (g, n, 1);
292 
293  /* n_square = n^2 */
294  GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
295  gcry_mpi_mul (n_square,
296  n,
297  n);
298 
299  /* gm = g^m mod n^2 */
300  GNUNET_assert (0 != (gm = gcry_mpi_new (0)));
301  gcry_mpi_powm (gm, g, m, n_square);
302  gcry_mpi_release (g);
303 
304  /* rn <- r^n mod n^2 */
305  GNUNET_assert (0 != (rn = gcry_mpi_new (0)));
306  gcry_mpi_powm (rn, r, n, n_square);
307  gcry_mpi_release (r);
308  gcry_mpi_release (n);
309 
310  /* c <- rn * gm mod n^2 */
311  GNUNET_assert (0 != (c = gcry_mpi_new (0)));
312  gcry_mpi_mulm (c, rn, gm, n_square);
313  gcry_mpi_release (n_square);
314  gcry_mpi_release (gm);
315  gcry_mpi_release (rn);
316 
318  sizeof(ciphertext->bits),
319  c);
320  gcry_mpi_release (c);
321 
322  return possible_opts;
323 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:78
int32_t remaining_ops
Guaranteed minimum number of homomorphic operations with this ciphertext, in network byte order (NBO)...
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
unsigned char bits[2048 *2/8]
The bits of the ciphertext.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
void GNUNET_CRYPTO_mpi_scan_unsigned(gcry_mpi_t *result, const void *data, size_t size)
Convert data buffer into MPI value.
Definition: crypto_mpi.c:131
#define GNUNET_CRYPTO_PAILLIER_BITS
Size of paillier plain texts and public keys.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_paillier_decrypt()

void GNUNET_CRYPTO_paillier_decrypt ( const struct GNUNET_CRYPTO_PaillierPrivateKey private_key,
const struct GNUNET_CRYPTO_PaillierPublicKey public_key,
const struct GNUNET_CRYPTO_PaillierCiphertext ciphertext,
gcry_mpi_t  m 
)

Decrypt a paillier ciphertext with a private key.

Parameters
private_keyPrivate key to use for decryption.
public_keyPublic key to use for decryption.
ciphertextCiphertext to decrypt.
[out]mDecryption of ciphertext with .
private_keyPrivate key to use for decryption.
public_keyPublic key to use for encryption.
ciphertextCiphertext to decrypt.
[out]mDecryption of ciphertext with .

Definition at line 335 of file crypto_paillier.c.

References GNUNET_CRYPTO_PaillierCiphertext::bits, GNUNET_assert, GNUNET_CRYPTO_mpi_scan_unsigned(), GNUNET_CRYPTO_PaillierPrivateKey::lambda, and GNUNET_CRYPTO_PaillierPrivateKey::mu.

Referenced by compute_scalar_product(), and keygen_round2_new_element().

342 {
343  gcry_mpi_t mu;
344  gcry_mpi_t lambda;
345  gcry_mpi_t n;
346  gcry_mpi_t n_square;
347  gcry_mpi_t c;
348  gcry_mpi_t cmu;
349  gcry_mpi_t cmum1;
350  gcry_mpi_t mod;
351 
353  private_key->lambda,
354  sizeof(private_key->lambda));
356  private_key->mu,
357  sizeof(private_key->mu));
359  public_key,
360  sizeof(struct
363  ciphertext->bits,
364  sizeof(ciphertext->bits));
365 
366  /* n_square = n * n */
367  GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
368  gcry_mpi_mul (n_square, n, n);
369 
370  /* cmu = c^lambda mod n^2 */
371  GNUNET_assert (0 != (cmu = gcry_mpi_new (0)));
372  gcry_mpi_powm (cmu,
373  c,
374  lambda,
375  n_square);
376  gcry_mpi_release (n_square);
377  gcry_mpi_release (lambda);
378  gcry_mpi_release (c);
379 
380  /* cmum1 = cmu - 1 */
381  GNUNET_assert (0 != (cmum1 = gcry_mpi_new (0)));
382  gcry_mpi_sub_ui (cmum1, cmu, 1);
383  gcry_mpi_release (cmu);
384 
385  /* mod = cmum1 / n (mod n) */
386  GNUNET_assert (0 != (mod = gcry_mpi_new (0)));
387  gcry_mpi_div (mod, NULL, cmum1, n, 0);
388  gcry_mpi_release (cmum1);
389 
390  /* m = mod * mu mod n */
391  gcry_mpi_mulm (m, mod, mu, n);
392  gcry_mpi_release (mod);
393  gcry_mpi_release (mu);
394  gcry_mpi_release (n);
395 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned char lambda[2048/8]
Lambda-component of the private key.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
unsigned char bits[2048 *2/8]
The bits of the ciphertext.
unsigned char mu[2048/8]
Mu-component of the private key.
void GNUNET_CRYPTO_mpi_scan_unsigned(gcry_mpi_t *result, const void *data, size_t size)
Convert data buffer into MPI value.
Definition: crypto_mpi.c:131
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_paillier_hom_add()

int GNUNET_CRYPTO_paillier_hom_add ( const struct GNUNET_CRYPTO_PaillierPublicKey public_key,
const struct GNUNET_CRYPTO_PaillierCiphertext c1,
const struct GNUNET_CRYPTO_PaillierCiphertext c2,
struct GNUNET_CRYPTO_PaillierCiphertext result 
)

Compute a ciphertext that represents the sum of the plaintext in x1 and x2.

Note that this operation can only be done a finite number of times before an overflow occurs.

Parameters
public_keyPublic key to use for encryption.
c1Paillier cipher text.
c2Paillier cipher text.
[out]resultResult of the homomorphic operation.
Returns
GNUNET_OK if the result could be computed, GNUNET_SYSERR if no more homomorphic operations are remaining.

Compute a ciphertext that represents the sum of the plaintext in x1 and x2.

Note that this operation can only be done a finite number of times before an overflow occurs.

Parameters
public_keyPublic key to use for encryption.
c1Paillier cipher text.
c2Paillier cipher text.
[out]resultResult of the homomorphic operation.
Returns
GNUNET_OK if the result could be computed, GNUNET_SYSERR if no more homomorphic operations are remaining.

Definition at line 413 of file crypto_paillier.c.

References testconfigure::b, GNUNET_CRYPTO_PaillierCiphertext::bits, GNUNET_assert, GNUNET_break_op, GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_CRYPTO_mpi_scan_unsigned(), GNUNET_MIN, GNUNET_SYSERR, and GNUNET_CRYPTO_PaillierCiphertext::remaining_ops.

Referenced by compute_service_response().

420 {
421  gcry_mpi_t a;
422  gcry_mpi_t b;
423  gcry_mpi_t c;
424  gcry_mpi_t n;
425  gcry_mpi_t n_square;
426  int32_t o1;
427  int32_t o2;
428 
429  o1 = (int32_t) ntohl (c1->remaining_ops);
430  o2 = (int32_t) ntohl (c2->remaining_ops);
431  if ((0 >= o1) || (0 >= o2))
432  {
433  GNUNET_break_op (0);
434  return GNUNET_SYSERR;
435  }
436 
438  c1->bits,
439  sizeof(c1->bits));
441  c2->bits,
442  sizeof(c2->bits));
444  public_key,
445  sizeof(struct
447 
448  /* n_square = n * n */
449  GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
450  gcry_mpi_mul (n_square, n, n);
451  gcry_mpi_release (n);
452 
453  /* c = a * b mod n_square */
454  GNUNET_assert (0 != (c = gcry_mpi_new (0)));
455  gcry_mpi_mulm (c, a, b, n_square);
456  gcry_mpi_release (n_square);
457  gcry_mpi_release (a);
458  gcry_mpi_release (b);
459 
460  result->remaining_ops = htonl (GNUNET_MIN (o1, o2) - 1);
462  sizeof(result->bits),
463  c);
464  gcry_mpi_release (c);
465  return ntohl (result->remaining_ops);
466 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:78
int32_t remaining_ops
Guaranteed minimum number of homomorphic operations with this ciphertext, in network byte order (NBO)...
unsigned char bits[2048 *2/8]
The bits of the ciphertext.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
void GNUNET_CRYPTO_mpi_scan_unsigned(gcry_mpi_t *result, const void *data, size_t size)
Convert data buffer into MPI value.
Definition: crypto_mpi.c:131
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_paillier_hom_get_remaining()

int GNUNET_CRYPTO_paillier_hom_get_remaining ( const struct GNUNET_CRYPTO_PaillierCiphertext c)

Get the number of remaining supported homomorphic operations.

Parameters
cPaillier cipher text.
Returns
the number of remaining homomorphic operations

Definition at line 476 of file crypto_paillier.c.

References GNUNET_assert, and GNUNET_CRYPTO_PaillierCiphertext::remaining_ops.

478 {
479  GNUNET_assert (NULL != c);
480  return ntohl (c->remaining_ops);
481 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int32_t remaining_ops
Guaranteed minimum number of homomorphic operations with this ciphertext, in network byte order (NBO)...

◆ GNUNET_CRYPTO_rsa_private_key_create()

struct GNUNET_CRYPTO_RsaPrivateKey* GNUNET_CRYPTO_rsa_private_key_create ( unsigned int  len)

Create a new private key.

Caller must free return value.

Parameters
lenlength of the key in bits (i.e. 2048)
Returns
fresh private key

Definition at line 143 of file crypto_rsa.c.

References BENCHMARK_END, BENCHMARK_START, GNUNET_assert, GNUNET_new, ret, and GNUNET_CRYPTO_RsaPrivateKey::sexp.

Referenced by output_vectors().

144 {
146  gcry_sexp_t s_key;
147  gcry_sexp_t s_keyparam;
148 
149  BENCHMARK_START (rsa_private_key_create);
150 
151  GNUNET_assert (0 ==
152  gcry_sexp_build (&s_keyparam,
153  NULL,
154  "(genkey(rsa(nbits %d)))",
155  len));
156  GNUNET_assert (0 ==
157  gcry_pk_genkey (&s_key,
158  s_keyparam));
159  gcry_sexp_release (s_keyparam);
160 #if EXTRA_CHECKS
161  GNUNET_assert (0 ==
162  gcry_pk_testkey (s_key));
163 #endif
165  ret->sexp = s_key;
166  BENCHMARK_END (rsa_private_key_create);
167  return ret;
168 }
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA private key.
Definition: crypto_rsa.c:44
The private information of an RSA key pair.
Definition: crypto_rsa.c:39
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_private_key_free()

void GNUNET_CRYPTO_rsa_private_key_free ( struct GNUNET_CRYPTO_RsaPrivateKey key)

Free memory occupied by the private key.

Parameters
keypointer to the memory to free

Definition at line 172 of file crypto_rsa.c.

References GNUNET_free, and GNUNET_CRYPTO_RsaPrivateKey::sexp.

Referenced by GNUNET_CRYPTO_rsa_private_key_decode(), and output_vectors().

173 {
174  gcry_sexp_release (key->sexp);
175  GNUNET_free (key);
176 }
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA private key.
Definition: crypto_rsa.c:44
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_private_key_encode()

size_t GNUNET_CRYPTO_rsa_private_key_encode ( const struct GNUNET_CRYPTO_RsaPrivateKey key,
void **  buffer 
)

Encode the private key in a format suitable for storing it into a file.

Parameters
keythe private key
[out]bufferset to a buffer with the encoded key
Returns
size of memory allocatedin buffer

Definition at line 180 of file crypto_rsa.c.

References testconfigure::b, GNUNET_assert, GNUNET_malloc, and GNUNET_CRYPTO_RsaPrivateKey::sexp.

Referenced by GNUNET_CRYPTO_rsa_private_key_cmp(), and output_vectors().

183 {
184  size_t n;
185  char *b;
186 
187  n = gcry_sexp_sprint (key->sexp,
188  GCRYSEXP_FMT_DEFAULT,
189  NULL,
190  0);
191  b = GNUNET_malloc (n);
192  GNUNET_assert ((n - 1) == /* since the last byte is \0 */
193  gcry_sexp_sprint (key->sexp,
194  GCRYSEXP_FMT_DEFAULT,
195  b,
196  n));
197  *buffer = b;
198  return n;
199 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA private key.
Definition: crypto_rsa.c:44
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_private_key_decode()

struct GNUNET_CRYPTO_RsaPrivateKey* GNUNET_CRYPTO_rsa_private_key_decode ( const void *  buf,
size_t  buf_size 
)

Decode the private key from the data-format back to the "normal", internal format.

Parameters
bufthe buffer where the private key data is stored
buf_sizethe size of the data in buf
Returns
NULL on error

Definition at line 203 of file crypto_rsa.c.

References GNUNET_CRYPTO_rsa_private_key_free(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_new, key, LOG, and GNUNET_CRYPTO_RsaPrivateKey::sexp.

Referenced by checkvec().

205 {
207 
209  if (0 !=
210  gcry_sexp_new (&key->sexp,
211  buf,
212  buf_size,
213  0))
214  {
216  "Decoded private key is not valid\n");
217  GNUNET_free (key);
218  return NULL;
219  }
220  if (0 != gcry_pk_testkey (key->sexp))
221  {
223  "Decoded private key is not valid\n");
225  return NULL;
226  }
227  return key;
228 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA private key.
Definition: crypto_rsa.c:44
static char buf[2048]
#define LOG(kind,...)
Definition: crypto_rsa.c:33
struct GNUNET_HashCode key
The key used in the DHT.
void GNUNET_CRYPTO_rsa_private_key_free(struct GNUNET_CRYPTO_RsaPrivateKey *key)
Free memory occupied by the private key.
Definition: crypto_rsa.c:172
The private information of an RSA key pair.
Definition: crypto_rsa.c:39
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_private_key_dup()

struct GNUNET_CRYPTO_RsaPrivateKey* GNUNET_CRYPTO_rsa_private_key_dup ( const struct GNUNET_CRYPTO_RsaPrivateKey key)

Duplicate the given private key.

Parameters
keythe private key to duplicate
Returns
the duplicate key; NULL upon error

Definition at line 1174 of file crypto_rsa.c.

References GNUNET_assert, GNUNET_new, and GNUNET_CRYPTO_RsaPrivateKey::sexp.

1176 {
1177  struct GNUNET_CRYPTO_RsaPrivateKey *dup;
1178  gcry_sexp_t dup_sexp;
1179  size_t erroff;
1180 
1181  /* check if we really are exporting a private key */
1182  dup_sexp = gcry_sexp_find_token (key->sexp, "private-key", 0);
1183  GNUNET_assert (NULL != dup_sexp);
1184  gcry_sexp_release (dup_sexp);
1185  /* copy the sexp */
1186  GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp));
1187  dup = GNUNET_new (struct GNUNET_CRYPTO_RsaPrivateKey);
1188  dup->sexp = dup_sexp;
1189  return dup;
1190 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA private key.
Definition: crypto_rsa.c:44
The private information of an RSA key pair.
Definition: crypto_rsa.c:39

◆ GNUNET_CRYPTO_rsa_private_key_get_public()

struct GNUNET_CRYPTO_RsaPublicKey* GNUNET_CRYPTO_rsa_private_key_get_public ( const struct GNUNET_CRYPTO_RsaPrivateKey priv)

Extract the public key of the given private key.

Parameters
privthe private key
Returns
NULL on error, otherwise the public key

Definition at line 232 of file crypto_rsa.c.

References BENCHMARK_END, BENCHMARK_START, GNUNET_break_op, GNUNET_new, key_from_sexp(), pub, result, GNUNET_CRYPTO_RsaPrivateKey::sexp, and GNUNET_CRYPTO_RsaPublicKey::sexp.

Referenced by GNUNET_CRYPTO_rsa_sign_fdh(), output_vectors(), and rsa_sign_mpi().

234 {
236  gcry_mpi_t ne[2];
237  int rc;
238  gcry_sexp_t result;
239 
240  BENCHMARK_START (rsa_private_key_get_public);
241 
242  rc = key_from_sexp (ne, priv->sexp, "public-key", "ne");
243  if (0 != rc)
244  rc = key_from_sexp (ne, priv->sexp, "private-key", "ne");
245  if (0 != rc)
246  rc = key_from_sexp (ne, priv->sexp, "rsa", "ne");
247  if (0 != rc)
248  {
249  GNUNET_break_op (0);
250  return NULL;
251  }
252  rc = gcry_sexp_build (&result,
253  NULL,
254  "(public-key(rsa(n %m)(e %m)))",
255  ne[0],
256  ne[1]);
257  gcry_mpi_release (ne[0]);
258  gcry_mpi_release (ne[1]);
259  pub = GNUNET_new (struct GNUNET_CRYPTO_RsaPublicKey);
260  pub->sexp = result;
261  BENCHMARK_END (rsa_private_key_get_public);
262  return pub;
263 }
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_rsa.c:94
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
#define GNUNET_new(type)
Allocate a struct or union of the given type.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA private key.
Definition: crypto_rsa.c:44
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static int result
Global testing status.
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_public_key_hash()

void GNUNET_CRYPTO_rsa_public_key_hash ( const struct GNUNET_CRYPTO_RsaPublicKey key,
struct GNUNET_HashCode hc 
)

Compute hash over the public key.

Parameters
keypublic key to hash
hcwhere to store the hash code

Definition at line 367 of file crypto_rsa.c.

References buf, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_rsa_public_key_encode(), and GNUNET_free.

369 {
370  void *buf;
371  size_t buf_size;
372 
373  buf_size = GNUNET_CRYPTO_rsa_public_key_encode (key,
374  &buf);
375  GNUNET_CRYPTO_hash (buf,
376  buf_size,
377  hc);
378  GNUNET_free (buf);
379 }
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
static char buf[2048]
GNUNET_NETWORK_STRUCT_END size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:300
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_public_key_len()

unsigned int GNUNET_CRYPTO_rsa_public_key_len ( const struct GNUNET_CRYPTO_RsaPublicKey key)

Obtain the length of the RSA key in bits.

Parameters
keythe public key to introspect
Returns
length of the key in bits

Definition at line 634 of file crypto_rsa.c.

References GNUNET_break, key_from_sexp(), and GNUNET_CRYPTO_RsaPublicKey::sexp.

635 {
636  gcry_mpi_t n;
637  unsigned int rval;
638 
639  if (0 != key_from_sexp (&n, key->sexp, "rsa", "n"))
640  { /* Not an RSA public key */
641  GNUNET_break (0);
642  return 0;
643  }
644  rval = gcry_mpi_get_nbits (n);
645  gcry_mpi_release (n);
646  return rval;
647 }
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_rsa.c:94
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56
Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_public_key_free()

void GNUNET_CRYPTO_rsa_public_key_free ( struct GNUNET_CRYPTO_RsaPublicKey key)

Free memory occupied by the public key.

Parameters
keypointer to the memory to free

Definition at line 267 of file crypto_rsa.c.

References GNUNET_free, GNUNET_NETWORK_STRUCT_BEGIN, and GNUNET_CRYPTO_RsaPublicKey::sexp.

Referenced by clean_rsa_pub(), clean_rsa_public_key(), GNUNET_CRYPTO_rsa_sign_fdh(), output_vectors(), and rsa_sign_mpi().

268 {
269  gcry_sexp_release (key->sexp);
270  GNUNET_free (key);
271 }
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_public_key_encode()

size_t GNUNET_CRYPTO_rsa_public_key_encode ( const struct GNUNET_CRYPTO_RsaPublicKey key,
void **  buffer 
)

Encode the public key in a format suitable for storing it into a file.

Parameters
keythe private key
[out]bufferset to a buffer with the encoded key
Returns
size of memory allocated in buffer

Definition at line 300 of file crypto_rsa.c.

References buf, GNUNET_assert, GNUNET_break, GNUNET_malloc, key_from_sexp(), GNUNET_CRYPTO_RsaPublicKeyHeaderP::modulus_length, GNUNET_CRYPTO_RsaPublicKeyHeaderP::public_exponent_length, ret, and GNUNET_CRYPTO_RsaPublicKey::sexp.

Referenced by bind_rsa_pub(), checkvec(), GNUNET_CRYPTO_rsa_public_key_cmp(), GNUNET_CRYPTO_rsa_public_key_hash(), GNUNET_JSON_from_rsa_public_key(), my_conv_rsa_public_key(), output_vectors(), qconv_rsa_public_key(), and rsa_full_domain_hash().

303 {
304  gcry_mpi_t ne[2];
305  size_t n_size;
306  size_t e_size;
307  size_t rsize;
308  size_t buf_size;
309  char *buf;
311  int ret;
312 
313  ret = key_from_sexp (ne, key->sexp, "public-key", "ne");
314  if (0 != ret)
315  ret = key_from_sexp (ne, key->sexp, "rsa", "ne");
316  if (0 != ret)
317  {
318  GNUNET_break (0);
319  *buffer = NULL;
320  return 0;
321  }
322  gcry_mpi_print (GCRYMPI_FMT_USG,
323  NULL,
324  0,
325  &n_size,
326  ne[0]);
327  gcry_mpi_print (GCRYMPI_FMT_USG,
328  NULL,
329  0,
330  &e_size,
331  ne[1]);
332  if ( (e_size > UINT16_MAX) ||
333  (n_size > UINT16_MAX) )
334  {
335  GNUNET_break (0);
336  *buffer = NULL;
337  gcry_mpi_release (ne[0]);
338  gcry_mpi_release (ne[1]);
339  return 0;
340  }
341  buf_size = n_size + e_size + sizeof (hdr);
342  buf = GNUNET_malloc (buf_size);
343  hdr.modulus_length = htons ((uint16_t) n_size);
344  hdr.public_exponent_length = htons ((uint16_t) e_size);
345  memcpy (buf, &hdr, sizeof (hdr));
346  GNUNET_assert (0 ==
347  gcry_mpi_print (GCRYMPI_FMT_USG,
348  (unsigned char *) &buf[sizeof (hdr)],
349  n_size,
350  &rsize,
351  ne[0]));
352 
353  GNUNET_assert (0 ==
354  gcry_mpi_print (GCRYMPI_FMT_USG,
355  (unsigned char *) &buf[sizeof (hdr) + n_size],
356  e_size,
357  &rsize,
358  ne[1]));
359  *buffer = buf;
360  gcry_mpi_release (ne[0]);
361  gcry_mpi_release (ne[1]);
362  return buf_size;
363 }
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_rsa.c:94
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char buf[2048]
Format of the header of a serialized RSA public key.
Definition: crypto_rsa.c:279
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_public_key_decode()

struct GNUNET_CRYPTO_RsaPublicKey* GNUNET_CRYPTO_rsa_public_key_decode ( const char *  buf,
size_t  len 
)

Decode the public key from the data-format back to the "normal", internal format.

Parameters
bufthe buffer where the public key data is stored
lenthe length of the data in buf
Returns
NULL on error

Definition at line 383 of file crypto_rsa.c.

References data, e, GNUNET_break, GNUNET_break_op, GNUNET_new, key, GNUNET_CRYPTO_RsaPublicKeyHeaderP::modulus_length, GNUNET_CRYPTO_RsaPublicKeyHeaderP::public_exponent_length, and GNUNET_CRYPTO_RsaPublicKey::sexp.

Referenced by checkvec(), extract_rsa_pub(), extract_rsa_public_key(), parse_rsa_public_key(), and post_extract_rsa_public_key().

385 {
388  size_t e_size;
389  size_t n_size;
390  gcry_mpi_t n;
391  gcry_mpi_t e;
392  gcry_sexp_t data;
393 
394  if (len < sizeof (hdr))
395  {
396  GNUNET_break_op (0);
397  return NULL;
398  }
399  memcpy (&hdr, buf, sizeof (hdr));
400  n_size = ntohs (hdr.modulus_length);
401  e_size = ntohs (hdr.public_exponent_length);
402  if (len != sizeof (hdr) + e_size + n_size)
403  {
404  GNUNET_break_op (0);
405  return NULL;
406  }
407  if (0 !=
408  gcry_mpi_scan (&n,
409  GCRYMPI_FMT_USG,
410  &buf[sizeof (hdr)],
411  n_size,
412  NULL))
413  {
414  GNUNET_break_op (0);
415  return NULL;
416  }
417  if (0 !=
418  gcry_mpi_scan (&e,
419  GCRYMPI_FMT_USG,
420  &buf[sizeof (hdr) + n_size],
421  e_size,
422  NULL))
423  {
424  GNUNET_break_op (0);
425  gcry_mpi_release (n);
426  return NULL;
427  }
428 
429  if (0 !=
430  gcry_sexp_build (&data,
431  NULL,
432  "(public-key(rsa(n %m)(e %m)))",
433  n,
434  e))
435  {
436  GNUNET_break (0);
437  gcry_mpi_release (n);
438  gcry_mpi_release (e);
439  return NULL;
440  }
441  gcry_mpi_release (n);
442  gcry_mpi_release (e);
443  key = GNUNET_new (struct GNUNET_CRYPTO_RsaPublicKey);
444  key->sexp = data;
445  return key;
446 }
static struct Experiment * e
#define GNUNET_new(type)
Allocate a struct or union of the given type.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
Format of the header of a serialized RSA public key.
Definition: crypto_rsa.c:279
struct GNUNET_HashCode key
The key used in the DHT.
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_public_key_dup()

struct GNUNET_CRYPTO_RsaPublicKey* GNUNET_CRYPTO_rsa_public_key_dup ( const struct GNUNET_CRYPTO_RsaPublicKey key)

Duplicate the given public key.

Parameters
keythe public key to duplicate
Returns
the duplicate key; NULL upon error

Definition at line 1028 of file crypto_rsa.c.

References GNUNET_assert, GNUNET_new, and GNUNET_CRYPTO_RsaPublicKey::sexp.

1029 {
1030  struct GNUNET_CRYPTO_RsaPublicKey *dup;
1031  gcry_sexp_t dup_sexp;
1032  size_t erroff;
1033 
1034  /* check if we really are exporting a public key */
1035  dup_sexp = gcry_sexp_find_token (key->sexp, "public-key", 0);
1036  GNUNET_assert (NULL != dup_sexp);
1037  gcry_sexp_release (dup_sexp);
1038  /* copy the sexp */
1039  GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp));
1040  dup = GNUNET_new (struct GNUNET_CRYPTO_RsaPublicKey);
1041  dup->sexp = dup_sexp;
1042  return dup;
1043 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56

◆ GNUNET_CRYPTO_rsa_signature_cmp()

int GNUNET_CRYPTO_rsa_signature_cmp ( const struct GNUNET_CRYPTO_RsaSignature s1,
const struct GNUNET_CRYPTO_RsaSignature s2 
)

Compare the values of two signatures.

Parameters
s1one signature
s2the other signature
Returns
0 if the two are equal

Definition at line 556 of file crypto_rsa.c.

References GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, and ret.

558 {
559  void *b1;
560  void *b2;
561  size_t z1;
562  size_t z2;
563  int ret;
564 
566  &b1);
568  &b2);
569  if (z1 != z2)
570  ret = 1;
571  else
572  ret = memcmp (b1,
573  b2,
574  z1);
575  GNUNET_free (b1);
576  GNUNET_free (b2);
577  return ret;
578 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:952
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_private_key_cmp()

int GNUNET_CRYPTO_rsa_private_key_cmp ( const struct GNUNET_CRYPTO_RsaPrivateKey p1,
const struct GNUNET_CRYPTO_RsaPrivateKey p2 
)

Compare the values of two private keys.

Parameters
p1one private key
p2the other private key
Returns
0 if the two are equal

Definition at line 608 of file crypto_rsa.c.

References GNUNET_CRYPTO_rsa_private_key_encode(), GNUNET_free, and ret.

610 {
611  void *b1;
612  void *b2;
613  size_t z1;
614  size_t z2;
615  int ret;
616 
618  &b1);
620  &b2);
621  if (z1 != z2)
622  ret = 1;
623  else
624  ret = memcmp (b1,
625  b2,
626  z1);
627  GNUNET_free (b1);
628  GNUNET_free (b2);
629  return ret;
630 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
size_t GNUNET_CRYPTO_rsa_private_key_encode(const struct GNUNET_CRYPTO_RsaPrivateKey *key, void **buffer)
Encode the private key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:180
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_public_key_cmp()

int GNUNET_CRYPTO_rsa_public_key_cmp ( const struct GNUNET_CRYPTO_RsaPublicKey p1,
const struct GNUNET_CRYPTO_RsaPublicKey p2 
)

Compare the values of two public keys.

Parameters
p1one public key
p2the other public key
Returns
0 if the two are equal

Definition at line 582 of file crypto_rsa.c.

References GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, and ret.

584 {
585  void *b1;
586  void *b2;
587  size_t z1;
588  size_t z2;
589  int ret;
590 
592  &b1);
594  &b2);
595  if (z1 != z2)
596  ret = 1;
597  else
598  ret = memcmp (b1,
599  b2,
600  z1);
601  GNUNET_free (b1);
602  GNUNET_free (b2);
603  return ret;
604 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_NETWORK_STRUCT_END size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:300
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_blind()

int GNUNET_CRYPTO_rsa_blind ( const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_RsaBlindingKeySecret bks,
struct GNUNET_CRYPTO_RsaPublicKey pkey,
void **  buf,
size_t *  buf_size 
)

Blinds the given message with the given blinding key.

Parameters
hashhash of the message to sign
bkeythe blinding key
pkeythe public key of the signer
[out]bufset to a buffer with the blinded message to be signed
[out]buf_sizenumber of bytes stored in buf
Returns
GNUNET_YES if successful, GNUNET_NO if RSA key is malicious

Definition at line 744 of file crypto_rsa.c.

References BENCHMARK_END, BENCHMARK_START, data, GNUNET_assert, GNUNET_break, GNUNET_NO, GNUNET_YES, key_from_sexp(), numeric_mpi_alloc_n_print(), RsaBlindingKey::r, ret, rsa_blinding_key_derive(), rsa_blinding_key_free(), rsa_full_domain_hash(), and GNUNET_CRYPTO_RsaPublicKey::sexp.

Referenced by checkvec(), and output_vectors().

749 {
750  struct RsaBlindingKey *bkey;
751  gcry_mpi_t data;
752  gcry_mpi_t ne[2];
753  gcry_mpi_t r_e;
754  gcry_mpi_t data_r_e;
755  int ret;
756 
757  BENCHMARK_START (rsa_blind);
758 
759  GNUNET_assert (buf != NULL);
760  GNUNET_assert (buf_size != NULL);
761  ret = key_from_sexp (ne, pkey->sexp, "public-key", "ne");
762  if (0 != ret)
763  ret = key_from_sexp (ne, pkey->sexp, "rsa", "ne");
764  if (0 != ret)
765  {
766  GNUNET_break (0);
767  *buf = NULL;
768  *buf_size = 0;
769  return GNUNET_NO;
770  }
771 
772  data = rsa_full_domain_hash (pkey, hash);
773  if (NULL == data)
774  goto rsa_gcd_validate_failure;
775 
776  bkey = rsa_blinding_key_derive (pkey, bks);
777  if (NULL == bkey)
778  {
779  gcry_mpi_release (data);
780  goto rsa_gcd_validate_failure;
781  }
782 
783  r_e = gcry_mpi_new (0);
784  gcry_mpi_powm (r_e,
785  bkey->r,
786  ne[1],
787  ne[0]);
788  data_r_e = gcry_mpi_new (0);
789  gcry_mpi_mulm (data_r_e,
790  data,
791  r_e,
792  ne[0]);
793  gcry_mpi_release (data);
794  gcry_mpi_release (ne[0]);
795  gcry_mpi_release (ne[1]);
796  gcry_mpi_release (r_e);
797  rsa_blinding_key_free (bkey);
798 
799  *buf_size = numeric_mpi_alloc_n_print (data_r_e,
800  (char **) buf);
801  gcry_mpi_release (data_r_e);
802 
803  BENCHMARK_END (rsa_blind);
804 
805  return GNUNET_YES;
806 
807 rsa_gcd_validate_failure:
808  /* We know the RSA key is malicious here, so warn the wallet. */
809  /* GNUNET_break_op (0); */
810  gcry_mpi_release (ne[0]);
811  gcry_mpi_release (ne[1]);
812  *buf = NULL;
813  *buf_size = 0;
814  return GNUNET_NO;
815 }
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_rsa.c:94
static struct RsaBlindingKey * rsa_blinding_key_derive(const struct GNUNET_CRYPTO_RsaPublicKey *pkey, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks)
Create a blinding key.
Definition: crypto_rsa.c:481
static gcry_mpi_t rsa_full_domain_hash(const struct GNUNET_CRYPTO_RsaPublicKey *pkey, const struct GNUNET_HashCode *hash)
Computes a full domain hash seeded by the given public key.
Definition: crypto_rsa.c:708
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gcry_mpi_t r
Random value used for blinding.
Definition: crypto_rsa.c:80
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static size_t numeric_mpi_alloc_n_print(gcry_mpi_t v, char **buffer)
Print an MPI to a newly created buffer.
Definition: crypto_rsa.c:671
static char buf[2048]
RSA blinding key.
Definition: crypto_rsa.c:75
static void rsa_blinding_key_free(struct RsaBlindingKey *bkey)
Destroy a blinding key.
Definition: crypto_rsa.c:656
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_sign_blinded()

struct GNUNET_CRYPTO_RsaSignature* GNUNET_CRYPTO_rsa_sign_blinded ( const struct GNUNET_CRYPTO_RsaPrivateKey key,
const void *  msg,
size_t  msg_len 
)

Sign a blinded value, which must be a full domain hash of a message.

Parameters
keyprivate key to use for the signing
msgthe (blinded) message to sign
msg_lennumber of bytes in msg to sign
Returns
NULL on error, signature on success

Definition at line 900 of file crypto_rsa.c.

References BENCHMARK_END, BENCHMARK_START, GNUNET_assert, and rsa_sign_mpi().

Referenced by checkvec(), and output_vectors().

903 {
904  gcry_mpi_t v = NULL;
905  struct GNUNET_CRYPTO_RsaSignature *sig;
906 
907  BENCHMARK_START (rsa_sign_blinded);
908 
909  GNUNET_assert (0 ==
910  gcry_mpi_scan (&v,
911  GCRYMPI_FMT_USG,
912  msg,
913  msg_len,
914  NULL));
915 
916  sig = rsa_sign_mpi (key, v);
917  gcry_mpi_release (v);
918  BENCHMARK_END (rsa_sign_blinded);
919  return sig;
920 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
an RSA signature
Definition: crypto_rsa.c:63
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
static struct GNUNET_CRYPTO_RsaSignature * rsa_sign_mpi(const struct GNUNET_CRYPTO_RsaPrivateKey *key, gcry_mpi_t value)
Sign the given MPI.
Definition: crypto_rsa.c:846
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_sign_fdh()

struct GNUNET_CRYPTO_RsaSignature* GNUNET_CRYPTO_rsa_sign_fdh ( const struct GNUNET_CRYPTO_RsaPrivateKey key,
const struct GNUNET_HashCode hash 
)

Create and sign a full domain hash of a message.

Parameters
keyprivate key to use for the signing
hashthe hash of the message to sign
Returns
NULL on error, including a malicious RSA key, signature on success

Definition at line 924 of file crypto_rsa.c.

References GNUNET_CRYPTO_rsa_private_key_get_public(), GNUNET_CRYPTO_rsa_public_key_free(), pkey, rsa_full_domain_hash(), and rsa_sign_mpi().

926 {
928  gcry_mpi_t v = NULL;
929  struct GNUNET_CRYPTO_RsaSignature *sig;
930 
932  v = rsa_full_domain_hash (pkey, hash);
934  if (NULL == v) /* rsa_gcd_validate failed meaning */
935  return NULL; /* our *own* RSA key is malicious. */
936 
937  sig = rsa_sign_mpi (key, v);
938  gcry_mpi_release (v);
939  return sig;
940 }
static char * pkey
Public key of the zone to look in, in ASCII.
an RSA signature
Definition: crypto_rsa.c:63
static gcry_mpi_t rsa_full_domain_hash(const struct GNUNET_CRYPTO_RsaPublicKey *pkey, const struct GNUNET_HashCode *hash)
Computes a full domain hash seeded by the given public key.
Definition: crypto_rsa.c:708
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:267
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_private_key_get_public(const struct GNUNET_CRYPTO_RsaPrivateKey *priv)
Extract the public key of the given private key.
Definition: crypto_rsa.c:232
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
static struct GNUNET_CRYPTO_RsaSignature * rsa_sign_mpi(const struct GNUNET_CRYPTO_RsaPrivateKey *key, gcry_mpi_t value)
Sign the given MPI.
Definition: crypto_rsa.c:846
Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_signature_free()

void GNUNET_CRYPTO_rsa_signature_free ( struct GNUNET_CRYPTO_RsaSignature sig)

Free memory occupied by signature.

Parameters
sigmemory to free

Definition at line 944 of file crypto_rsa.c.

References GNUNET_free, and GNUNET_CRYPTO_RsaSignature::sexp.

Referenced by clean_rsa_sig(), clean_rsa_signature(), and output_vectors().

945 {
946  gcry_sexp_release (sig->sexp);
947  GNUNET_free (sig);
948 }
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA signature.
Definition: crypto_rsa.c:68
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_signature_encode()

size_t GNUNET_CRYPTO_rsa_signature_encode ( const struct GNUNET_CRYPTO_RsaSignature sig,
void **  buffer 
)

Encode the given signature in a format suitable for storing it into a file.

Parameters
sigthe signature
[out]bufferset to a buffer with the encoded key
Returns
size of memory allocated in buffer

Definition at line 952 of file crypto_rsa.c.

References buf, GNUNET_assert, GNUNET_malloc, key_from_sexp(), ret, and GNUNET_CRYPTO_RsaSignature::sexp.

Referenced by bind_rsa_sig(), checkvec(), GNUNET_CRYPTO_rsa_signature_cmp(), GNUNET_JSON_from_rsa_signature(), my_conv_rsa_signature(), output_vectors(), and qconv_rsa_signature().

955 {
956  gcry_mpi_t s;
957  size_t buf_size;
958  size_t rsize;
959  unsigned char *buf;
960  int ret;
961 
962  ret = key_from_sexp (&s,
963  sig->sexp,
964  "sig-val",
965  "s");
966  if (0 != ret)
967  ret = key_from_sexp (&s,
968  sig->sexp,
969  "rsa",
970  "s");
971  GNUNET_assert (0 == ret);
972  gcry_mpi_print (GCRYMPI_FMT_USG,
973  NULL,
974  0,
975  &buf_size,
976  s);
977  buf = GNUNET_malloc (buf_size);
978  GNUNET_assert (0 ==
979  gcry_mpi_print (GCRYMPI_FMT_USG,
980  buf,
981  buf_size,
982  &rsize,
983  s));
984  GNUNET_assert (rsize == buf_size);
985  *buffer = (void *) buf;
986  gcry_mpi_release (s);
987  return buf_size;
988 }
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_rsa.c:94
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char buf[2048]
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA signature.
Definition: crypto_rsa.c:68
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_signature_decode()

struct GNUNET_CRYPTO_RsaSignature* GNUNET_CRYPTO_rsa_signature_decode ( const void *  buf,
size_t  buf_size 
)

Decode the signature from the data-format back to the "normal", internal format.

Parameters
bufthe buffer where the public key data is stored
buf_sizethe number of bytes of the data in buf
Returns
NULL on error

Definition at line 992 of file crypto_rsa.c.

References data, GNUNET_break, GNUNET_break_op, GNUNET_new, and GNUNET_CRYPTO_RsaSignature::sexp.

Referenced by extract_rsa_sig(), extract_rsa_signature(), parse_rsa_signature(), and post_extract_rsa_signature().

994 {
995  struct GNUNET_CRYPTO_RsaSignature *sig;
996  gcry_mpi_t s;
997  gcry_sexp_t data;
998 
999  if (0 !=
1000  gcry_mpi_scan (&s,
1001  GCRYMPI_FMT_USG,
1002  buf,
1003  buf_size,
1004  NULL))
1005  {
1006  GNUNET_break_op (0);
1007  return NULL;
1008  }
1009 
1010  if (0 !=
1011  gcry_sexp_build (&data,
1012  NULL,
1013  "(sig-val(rsa(s %M)))",
1014  s))
1015  {
1016  GNUNET_break (0);
1017  gcry_mpi_release (s);
1018  return NULL;
1019  }
1020  gcry_mpi_release (s);
1021  sig = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature);
1022  sig->sexp = data;
1023  return sig;
1024 }
an RSA signature
Definition: crypto_rsa.c:63
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA signature.
Definition: crypto_rsa.c:68
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_signature_dup()

struct GNUNET_CRYPTO_RsaSignature* GNUNET_CRYPTO_rsa_signature_dup ( const struct GNUNET_CRYPTO_RsaSignature sig)

Duplicate the given rsa signature.

Parameters
sigthe signature to duplicate
Returns
the duplicate key; NULL upon error

Definition at line 1194 of file crypto_rsa.c.

References GNUNET_assert, GNUNET_new, key_from_sexp(), ret, and GNUNET_CRYPTO_RsaSignature::sexp.

1195 {
1196  struct GNUNET_CRYPTO_RsaSignature *dup;
1197  gcry_sexp_t dup_sexp;
1198  size_t erroff;
1199  gcry_mpi_t s;
1200  int ret;
1201 
1202  /* verify that this is an RSA signature */
1203  ret = key_from_sexp (&s, sig->sexp, "sig-val", "s");
1204  if (0 != ret)
1205  ret = key_from_sexp (&s, sig->sexp, "rsa", "s");
1206  GNUNET_assert (0 == ret);
1207  gcry_mpi_release (s);
1208  /* copy the sexp */
1209  GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", sig->sexp));
1210  dup = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature);
1211  dup->sexp = dup_sexp;
1212  return dup;
1213 }
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_rsa.c:94
an RSA signature
Definition: crypto_rsa.c:63
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA signature.
Definition: crypto_rsa.c:68
Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_unblind()

struct GNUNET_CRYPTO_RsaSignature* GNUNET_CRYPTO_rsa_unblind ( const struct GNUNET_CRYPTO_RsaSignature sig,
const struct GNUNET_CRYPTO_RsaBlindingKeySecret bks,
struct GNUNET_CRYPTO_RsaPublicKey pkey 
)

Unblind a blind-signed signature.

The signature should have been generated with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with GNUNET_CRYPTO_rsa_blind().

Parameters
sigthe signature made on the blinded signature purpose
bksthe blinding key secret used to blind the signature purpose
pkeythe public key of the signer
Returns
unblinded signature on success, NULL if RSA key is bad or malicious.

Definition at line 1047 of file crypto_rsa.c.

References BENCHMARK_END, BENCHMARK_START, GNUNET_assert, GNUNET_break_op, GNUNET_new, key_from_sexp(), RsaBlindingKey::r, ret, rsa_blinding_key_derive(), rsa_blinding_key_free(), GNUNET_CRYPTO_RsaPublicKey::sexp, and GNUNET_CRYPTO_RsaSignature::sexp.

Referenced by checkvec(), and output_vectors().

1050 {
1051  struct RsaBlindingKey *bkey;
1052  gcry_mpi_t n;
1053  gcry_mpi_t s;
1054  gcry_mpi_t r_inv;
1055  gcry_mpi_t ubsig;
1056  int ret;
1057  struct GNUNET_CRYPTO_RsaSignature *sret;
1058 
1059  BENCHMARK_START (rsa_unblind);
1060 
1061  ret = key_from_sexp (&n, pkey->sexp, "public-key", "n");
1062  if (0 != ret)
1063  ret = key_from_sexp (&n, pkey->sexp, "rsa", "n");
1064  if (0 != ret)
1065  {
1066  GNUNET_break_op (0);
1067  return NULL;
1068  }
1069  ret = key_from_sexp (&s, sig->sexp, "sig-val", "s");
1070  if (0 != ret)
1071  ret = key_from_sexp (&s, sig->sexp, "rsa", "s");
1072  if (0 != ret)
1073  {
1074  gcry_mpi_release (n);
1075  GNUNET_break_op (0);
1076  return NULL;
1077  }
1078 
1079  bkey = rsa_blinding_key_derive (pkey, bks);
1080  if (NULL == bkey)
1081  {
1082  /* RSA key is malicious since rsa_gcd_validate failed here.
1083  * It should have failed during GNUNET_CRYPTO_rsa_blind too though,
1084  * so the exchange is being malicious in an unfamilair way, maybe
1085  * just trying to crash us. */
1086  GNUNET_break_op (0);
1087  gcry_mpi_release (n);
1088  gcry_mpi_release (s);
1089  return NULL;
1090  }
1091 
1092  r_inv = gcry_mpi_new (0);
1093  if (1 !=
1094  gcry_mpi_invm (r_inv,
1095  bkey->r,
1096  n))
1097  {
1098  /* We cannot find r mod n, so gcd(r,n) != 1, which should get *
1099  * caught above, but we handle it the same here. */
1100  GNUNET_break_op (0);
1101  gcry_mpi_release (r_inv);
1102  rsa_blinding_key_free (bkey);
1103  gcry_mpi_release (n);
1104  gcry_mpi_release (s);
1105  return NULL;
1106  }
1107 
1108  ubsig = gcry_mpi_new (0);
1109  gcry_mpi_mulm (ubsig, s, r_inv, n);
1110  gcry_mpi_release (n);
1111  gcry_mpi_release (r_inv);
1112  gcry_mpi_release (s);
1113  rsa_blinding_key_free (bkey);
1114 
1115  sret = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature);
1116  GNUNET_assert (0 ==
1117  gcry_sexp_build (&sret->sexp,
1118  NULL,
1119  "(sig-val (rsa (s %M)))",
1120  ubsig));
1121  gcry_mpi_release (ubsig);
1122  BENCHMARK_END (rsa_unblind);
1123  return sret;
1124 }
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_rsa.c:94
static struct RsaBlindingKey * rsa_blinding_key_derive(const struct GNUNET_CRYPTO_RsaPublicKey *pkey, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks)
Create a blinding key.
Definition: crypto_rsa.c:481
an RSA signature
Definition: crypto_rsa.c:63
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
gcry_mpi_t r
Random value used for blinding.
Definition: crypto_rsa.c:80
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
RSA blinding key.
Definition: crypto_rsa.c:75
static void rsa_blinding_key_free(struct RsaBlindingKey *bkey)
Destroy a blinding key.
Definition: crypto_rsa.c:656
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA signature.
Definition: crypto_rsa.c:68
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_verify()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_verify ( const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_RsaSignature sig,
const struct GNUNET_CRYPTO_RsaPublicKey public_key 
)

Verify whether the given hash corresponds to the given signature and the signature is valid with respect to the given public key.

Parameters
hashthe message to verify to match the sig
sigsignature that is being validated
public_keypublic key of the signer
Returns
GNUNET_YES if ok, GNUNET_NO if RSA key is malicious, GNUNET_SYSERR if signature

Definition at line 1128 of file crypto_rsa.c.

References _, BENCHMARK_END, BENCHMARK_START, data, GNUNET_break_op, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, LOG, mpi_to_sexp(), rsa_full_domain_hash(), GNUNET_CRYPTO_RsaPublicKey::sexp, and GNUNET_CRYPTO_RsaSignature::sexp.

Referenced by checkvec(), and output_vectors().

1131 {
1132  gcry_sexp_t data;
1133  gcry_mpi_t r;
1134  int rc;
1135 
1136  BENCHMARK_START (rsa_verify);
1137 
1138  r = rsa_full_domain_hash (pkey, hash);
1139  if (NULL == r)
1140  {
1141  GNUNET_break_op (0);
1142  /* RSA key is malicious since rsa_gcd_validate failed here.
1143  * It should have failed during GNUNET_CRYPTO_rsa_blind too though,
1144  * so the exchange is being malicious in an unfamilair way, maybe
1145  * just trying to crash us. Arguably, we've only an internal error
1146  * though because we should've detected this in our previous call
1147  * to GNUNET_CRYPTO_rsa_unblind. *///
1148  return GNUNET_NO;
1149  }
1150 
1151  data = mpi_to_sexp (r);
1152  gcry_mpi_release (r);
1153 
1154  rc = gcry_pk_verify (sig->sexp,
1155  data,
1156  pkey->sexp);
1157  gcry_sexp_release (data);
1158  if (0 != rc)
1159  {
1161  _ ("RSA signature verification failed at %s:%d: %s\n"),
1162  __FILE__,
1163  __LINE__,
1164  gcry_strerror (rc));
1165  BENCHMARK_END (rsa_verify);
1166  return GNUNET_SYSERR;
1167  }
1168  BENCHMARK_END (rsa_verify);
1169  return GNUNET_OK;
1170 }
static char * pkey
Public key of the zone to look in, in ASCII.
static gcry_mpi_t rsa_full_domain_hash(const struct GNUNET_CRYPTO_RsaPublicKey *pkey, const struct GNUNET_HashCode *hash)
Computes a full domain hash seeded by the given public key.
Definition: crypto_rsa.c:708
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
static gcry_sexp_t mpi_to_sexp(gcry_mpi_t value)
Convert an MPI to an S-expression suitable for signature operations.
Definition: crypto_rsa.c:825
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define LOG(kind,...)
Definition: crypto_rsa.c:33
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA signature.
Definition: crypto_rsa.c:68
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function: