GNUnet 0.21.2
Libgnunetutil

Multi-function utilities library for GNUnet programs. More...

Collaboration diagram for Libgnunetutil:

Modules

 BIO library
 Buffered binary disk IO (with endianness conversion)
 
 Bandwidth library
 Functions related to bandwidth (unit)
 
 Configuration library
 Configuration management.
 
 Container
 Common data structures in GNUnet programs.
 
 Crypto library: cryptographic operations
 Provides cryptographic primitives.
 
 Crypto library: hash operations
 Provides hashing and operations on hashes.
 
 DNS Stub library
 Helper library to send DNS requests to DNS resolver.
 
 DNS parser library
 Helper library to parse DNS packets.
 
 Disk library
 Disk IO APIs.
 
 Getopt library
 Command line parsing and –help formatting.
 
 Helper library
 Dealing with SUID helper processes.
 
 Load library
 Load calculations.
 
 Logging
 
 MQ library
 General-purpose message queue.
 
 Memory management
 
 Network protocol definitions
 Types of messages used in GNUnet.
 
 Networking
 
 OS library
 Low level process routines.
 
 Peer library
 Helper library for interning of peer identifiers.
 
 Plugin library
 Plugin loading and unloading.
 
 Program library
 Start command-line programs.
 
 SOCKS proxy
 SOCKS proxy for connections.
 
 Scheduler library
 Event loop (scheduler)
 
 Signal library
 Manage signal handlers.
 
 Strings library
 Strings and string handling functions, including malloc and string tokenizing.
 
 Time library
 Time and time calculations.
 

Files

file  gnunet_bandwidth_lib.h
 Functions related to bandwidth (unit)
 
file  gnunet_bio_lib.h
 Buffered IO library.
 
file  gnunet_child_management_lib.h
 GNUnet child management api.
 
file  gnunet_common.h
 commonly used definitions; globals in this file are exempt from the rule that the module name ("common") must be part of the symbol name.
 
file  gnunet_configuration_lib.h
 Configuration API.
 
file  gnunet_container_lib.h
 Container classes for GNUnet.
 
file  gnunet_crypto_lib.h
 cryptographic primitives for GNUnet
 
file  gnunet_disk_lib.h
 Disk IO APIs.
 
file  gnunet_dnsparser_lib.h
 API for helper library to parse DNS packets.
 
file  gnunet_dnsstub_lib.h
 API for helper library to send DNS requests to DNS resolver.
 
file  gnunet_getopt_lib.h
 Command line parsing and –help formatting.
 
file  gnunet_helper_lib.h
 API for dealing with SUID helper processes.
 
file  gnunet_load_lib.h
 Functions related to load calculations.
 
file  gnunet_mq_lib.h
 General-purpose message queue.
 
file  gnunet_nc_lib.h
 General-purpose broadcast mechanism for message queues.
 
file  gnunet_op_lib.h
 Asynchronous operations; register callbacks for operations and call them when a response arrives.
 
file  gnunet_os_lib.h
 Low level process routines.
 
file  gnunet_peer_lib.h
 Helper library for interning of peer identifiers.
 
file  gnunet_plugin_lib.h
 Plugin loading and unloading.
 
file  gnunet_program_lib.h
 Functions related to starting programs.
 
file  gnunet_protocols.h
 Constants for network protocols.
 
file  gnunet_scheduler_lib.h
 API to schedule computations using continuation passing style.
 
file  gnunet_signal_lib.h
 Functions related to signals.
 
file  gnunet_socks.h
 SOCKS proxy for connections.
 
file  gnunet_strings_lib.h
 Strings and string handling functions.
 
file  gnunet_time_lib.h
 Functions related to time.
 

Data Structures

struct  GNUNET_Buffer
 Dynamically growing buffer. More...
 
struct  GNUNET_HashCode
 A 512-bit hashcode. More...
 
struct  GNUNET_ShortHashCode
 A 256-bit hashcode. More...
 
struct  GNUNET_Uuid
 A UUID, a 128 bit "random" value. More...
 
struct  GNUNET_MessageHeader
 Header for all communications. More...
 
struct  GNUNET_OperationResultMessage
 Answer from service to client about last operation. More...
 
struct  GNUNET_AsyncScopeId
 Identifier for an asynchronous execution context. More...
 
struct  GNUNET_AsyncScopeSave
 Saved async scope identifier or root scope. More...
 
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_EddsaPrivateScalar
 Private ECC scalar encoded for transmission. More...
 
struct  GNUNET_CRYPTO_Edx25519PrivateKey
 Private ECC key material encoded for transmission. More...
 
struct  GNUNET_CRYPTO_Edx25519PublicKey
 Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and Edx25519 (same as EdDSA) signatures. More...
 
struct  GNUNET_CRYPTO_Edx25519Signature
 an ECC signature using Edx25519 (same as in EdDSA). More...
 
struct  GNUNET_CRYPTO_ElligatorRepresentative
 Elligator representative (always for Curve25519) More...
 
struct  GNUNET_CRYPTO_PrivateKey
 A private key for an identity as per LSD0001. More...
 
struct  GNUNET_CRYPTO_PublicKey
 An identity key as per LSD0001. More...
 
struct  GNUNET_CRYPTO_Signature
 An identity signature as per LSD0001. More...
 
struct  GNUNET_CRYPTO_SymmetricSessionKey
 type for session keys More...
 
struct  GNUNET_CRYPTO_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_Cs25519Scalar
 Curve25519 Scalar. More...
 
struct  GNUNET_CRYPTO_Cs25519Point
 Curve25519 point. More...
 
struct  GNUNET_CRYPTO_CsPrivateKey
 The private information of an Schnorr key pair. More...
 
struct  GNUNET_CRYPTO_CsPublicKey
 The public information of an Schnorr key pair. More...
 
struct  GNUNET_CRYPTO_CsBlindingSecret
 Secret used for blinding (alpha and beta). More...
 
struct  GNUNET_CRYPTO_CsRSecret
 the private r used in the signature More...
 
struct  GNUNET_CRYPTO_CsRPublic
 the public R (derived from r) used in c More...
 
struct  GNUNET_CRYPTO_CsC
 Schnorr c to be signed. More...
 
struct  GNUNET_CRYPTO_CsS
 s in the signature More...
 
struct  GNUNET_CRYPTO_CsBlindS
 blinded s in the signature More...
 
struct  GNUNET_CRYPTO_CsSignature
 CS Signtature containing scalar s and point R. More...
 
struct  GNUNET_CRYPTO_CsSessionNonce
 Nonce for the session, picked by client, shared with the signer. More...
 
struct  GNUNET_CRYPTO_CsBlindingNonce
 Nonce for computing blinding factors. 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_EccScalar
 A ECC scalar for use in point multiplications. More...
 
struct  GNUNET_CRYPTO_HpkeContext
 
struct  GNUNET_CRYPTO_HpkeEncapsulation
 HPKE DHKEM encapsulation (X25519) See RFC 9180. More...
 
struct  GNUNET_CRYPTO_RsaBlindingKeySecret
 Constant-size pre-secret for blinding key generation. More...
 
struct  GNUNET_CRYPTO_RsaBlindedMessage
 RSA Parameters to create blinded signature. More...
 
struct  GNUNET_CRYPTO_CsBlindedMessage
 CS Parameters derived from the message during blinding to create blinded signature. More...
 
struct  GNUNET_CRYPTO_CSPublicRPairP
 Pair of Public R values for Cs denominations. More...
 
struct  GNUNET_CRYPTO_CsBlindSignature
 The Sign Answer for Clause Blind Schnorr signature. More...
 
struct  GNUNET_CRYPTO_UnblindedSignature
 Type of (unblinded) signatures. More...
 
struct  GNUNET_CRYPTO_BlindedSignature
 Type for blinded signatures. More...
 
struct  GNUNET_CRYPTO_BlindSignPublicKey
 Type of public signing keys for blind signatures. More...
 
struct  GNUNET_CRYPTO_BlindSignPrivateKey
 Type of private signing keys for blind signing. More...
 
struct  GNUNET_CRYPTO_BlindedMessage
 Blinded message ready for blind signing. More...
 
struct  GNUNET_CRYPTO_CSPrivateRPairP
 Secret r for Cs denominations. More...
 
struct  GNUNET_CRYPTO_BlindingInputValues
 Input needed for blinding a message. More...
 
union  GNUNET_CRYPTO_BlindSessionNonce
 Nonce used to deterministiacally derive input values used in multi-round blind signature protocols. More...
 
union  GNUNET_CRYPTO_BlindingSecretP
 Type of blinding secrets. More...
 

Macros

#define GNUNET_UTIL_VERSION   0x000A0104
 Version of the API (for entire gnunetutil.so library). More...
 
#define GNUNET_MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define GNUNET_MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define BYTE_SWAP_16(x)   ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
 Endian operations. More...
 
#define BYTE_SWAP_32(x)
 
#define BYTE_SWAP_64(x)
 
#define GNUNET_htobe16(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_htobe16(x)   (x)
 
#define GNUNET_htole16(x)   (x)
 
#define GNUNET_htole16(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_be16toh(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_be16toh(x)   (x)
 
#define GNUNET_le16toh(x)   (x)
 
#define GNUNET_le16toh(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_htobe32(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_htobe32(x)   (x)
 
#define GNUNET_htole32(x)   (x)
 
#define GNUNET_htole32(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_be32toh(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_be32toh(x)   (x)
 
#define GNUNET_le32toh(x)   (x)
 
#define GNUNET_le32toh(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_htobe64(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_htobe64(x)   (x)
 
#define GNUNET_htole64(x)   (x)
 
#define GNUNET_htole64(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_be64toh(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_be64toh(x)   (x)
 
#define GNUNET_le64toh(x)   (x)
 
#define GNUNET_le64toh(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_NZL(l)   GNUNET_MAX (1, l)
 Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length). More...
 
#define GNUNET_PACKED   __attribute__ ((packed))
 gcc-ism to get packed structs. More...
 
#define GNUNET_ALIGN   __attribute__ ((aligned (8)))
 gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's. More...
 
#define GNUNET_UNUSED   __attribute__ ((unused))
 gcc-ism to document unused arguments More...
 
#define GNUNET_NORETURN   __attribute__ ((noreturn))
 gcc-ism to document functions that don't return More...
 
#define GNUNET_NETWORK_STRUCT_BEGIN
 Define as empty, GNUNET_PACKED should suffice, but this won't work on W32. More...
 
#define GNUNET_NETWORK_STRUCT_END
 Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;. More...
 
#define GN_LIKELY(expr)   (expr)
 
#define GN_UNLIKELY(expr)   (expr)
 
#define GNUNET_LOG_CALL_STATUS   -1
 
#define GNUNET_log_from(kind, comp, ...)
 
#define GNUNET_log(kind, ...)
 
#define GNUNET_B2S(obj)   GNUNET_b2s ((obj), sizeof (*(obj)))
 Convert a fixed-sized object to a string using GNUNET_b2s(). More...
 
#define GNUNET_static_assert(cond)   GNUNET_assert (cond)
 Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime and resulting in an abort() on failure. More...
 
#define GNUNET_memcmp(a, b)
 Compare memory in a and b, where both must be of the same pointer type. More...
 
#define GNUNET_memcmp_priv(a, b)
 Compare memory in a and b in constant time, suitable for private data. More...
 
#define GNUNET_is_zero(a)    GNUNET_is_zero_ ((a), sizeof (*(a)))
 Check that memory in a is all zeros. More...
 
#define GNUNET_memcpy(dst, src, n)
 Call memcpy() but check for n being 0 first. More...
 
#define __func__   "<unknown>"
 
#define GNUNET_CONTAINER_LIB_H
 
#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE, comparator, comparator_cls, head, tail, element)
 Insertion sort of element into DLL from head to tail sorted by comparator. More...
 
#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_HPKE_AEAD_ID   0x0003
 
#define GNUNET_CRYPTO_HPKE_NONCE_LEN   12
 
#define GNUNET_CRYPTO_HPKE_KEY_LEN   32
 
#define GNUNET_CRYPTO_HPKE_TAG_LEN   16
 
#define GNUNET_CRYPTO_HPKE_SEAL_OVERHEAD_BYTES   GNUNET_CRYPTO_HPKE_TAG_LEN
 
#define GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES
 
#define GNUNET_CRYPTO_sign(priv, ps, sig)
 Sign a given block with GNUNET_CRYPTO_PrivateKey. More...
 
#define GNUNET_CRYPTO_signature_verify(purp, ps, sig, pub)
 Verify a given signature with GNUNET_CRYPTO_PublicKey. More...
 

Typedefs

typedef void(* GNUNET_ChildCompletedCallback) (void *cls, enum GNUNET_OS_ProcessStatusType type, long unsigned int exit_code)
 Defines a GNUNET_ChildCompletedCallback which is sent back upon death or completion of a child process. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback) (void *cls, const char *filename)
 Function called with a filename. More...
 
typedef void(* GNUNET_ContinuationCallback) (void *cls)
 Generic continuation callback. More...
 
typedef void(* GNUNET_ResultCallback) (void *cls, int64_t result_code, const void *data, uint16_t data_size)
 Function called with the result of an asynchronous operation. More...
 
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_GenericReturnValue { GNUNET_SYSERR = -1 , GNUNET_NO = 0 , GNUNET_OK = 1 , GNUNET_YES = 1 }
 Named constants for return values. More...
 
enum  GNUNET_SCHEDULER_Priority {
  GNUNET_SCHEDULER_PRIORITY_KEEP = 0 , GNUNET_SCHEDULER_PRIORITY_IDLE = 1 , GNUNET_SCHEDULER_PRIORITY_BACKGROUND = 2 , GNUNET_SCHEDULER_PRIORITY_DEFAULT = 3 ,
  GNUNET_SCHEDULER_PRIORITY_HIGH = 4 , GNUNET_SCHEDULER_PRIORITY_UI = 5 , GNUNET_SCHEDULER_PRIORITY_URGENT = 6 , GNUNET_SCHEDULER_PRIORITY_SHUTDOWN = 7 ,
  GNUNET_SCHEDULER_PRIORITY_COUNT = 8
}
 Valid task priorities. More...
 
enum  GNUNET_CRYPTO_KeyType { GNUNET_PUBLIC_KEY_TYPE_ECDSA = 65536 , GNUNET_PUBLIC_KEY_TYPE_EDDSA = 65556 }
 Key type for the generic public key union. More...
 
enum  GNUNET_CRYPTO_HpkeMode { GNUNET_CRYPTO_HPKE_MODE_BASE = 0x00 , GNUNET_CRYPTO_HPKE_MODE_PSK = 0x01 , GNUNET_CRYPTO_HPKE_MODE_AUTH = 0x02 , GNUNET_CRYPTO_HPKE_MODE_AUTH_PSK = 0x03 }
 HPKE RFC 9180. More...
 
enum  GNUNET_CRYPTO_HpkeRole { GNUNET_CRYPTO_HPKE_ROLE_R = 0 , GNUNET_CRYPTO_HPKE_ROLE_S = 1 }
 
enum  GNUNET_CRYPTO_HpkeKem { GNUNET_CRYPTO_HPKE_KEM_DH_X25519_HKDF256 = 0x0020 , GNUNET_CRYPTO_HPKE_KEM_DH_X25519ELLIGATOR_HKDF256 = 0x0030 }
 
enum  GNUNET_CRYPTO_BlindSignatureAlgorithm { GNUNET_CRYPTO_BSA_INVALID = 0 , GNUNET_CRYPTO_BSA_RSA = 1 , GNUNET_CRYPTO_BSA_CS = 2 }
 Types of public keys used for blind signatures. More...
 

Functions

void GNUNET_buffer_prealloc (struct GNUNET_Buffer *buf, size_t capacity)
 Initialize a buffer with the given capacity. More...
 
void GNUNET_buffer_ensure_remaining (struct GNUNET_Buffer *buf, size_t n)
 Make sure that at least n bytes remaining in the buffer. More...
 
void GNUNET_buffer_write (struct GNUNET_Buffer *buf, const char *data, size_t len)
 Write bytes to the buffer. More...
 
void GNUNET_buffer_write_str (struct GNUNET_Buffer *buf, const char *str)
 Write a 0-terminated string to a buffer, excluding the 0-terminator. More...
 
void GNUNET_buffer_write_data_encoded (struct GNUNET_Buffer *buf, const void *data, size_t data_len)
 Write data encoded via GNUNET_STRINGS_data_to_string to the buffer. More...
 
void GNUNET_buffer_write_path (struct GNUNET_Buffer *buf, const char *str)
 Write a path component to a buffer, ensuring that there is exactly one slash between the previous contents of the buffer and the new string. More...
 
void GNUNET_buffer_write_fstr (struct GNUNET_Buffer *buf, const char *fmt,...) __attribute__((format(printf
 Write a 0-terminated formatted string to a buffer, excluding the 0-terminator. More...
 
void void GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf, const char *fmt, va_list args)
 Write a 0-terminated formatted string to a buffer, excluding the 0-terminator. More...
 
char * GNUNET_buffer_reap_str (struct GNUNET_Buffer *buf)
 Clear the buffer and return the string it contained. More...
 
void * GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size)
 Clear the buffer and return its contents. More...
 
void GNUNET_buffer_clear (struct GNUNET_Buffer *buf)
 Free the backing memory of the given buffer. More...
 
struct GNUNET_ChildWaitHandleGNUNET_wait_child (struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, void *cb_cls)
 Starts the handling of the child processes. More...
 
void GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh)
 Stop waiting on this child. More...
 
int GNUNET_get_log_call_status (int caller_level, const char *comp, const char *file, const char *function, int line)
 Decides whether a particular logging call should or should not be allowed to be made. More...
 
const char * GNUNET_b2s (const void *buf, size_t buf_size)
 Convert a buffer to an 8-character string representative of the contents. More...
 
uint64_t GNUNET_htonll (uint64_t n)
 Convert unsigned 64-bit integer to network byte order. More...
 
uint64_t GNUNET_ntohll (uint64_t n)
 Convert unsigned 64-bit integer to host byte order. More...
 
double GNUNET_hton_double (double d)
 Convert double to network byte order. More...
 
double GNUNET_ntoh_double (double d)
 Convert double to host byte order. More...
 
int GNUNET_memcmp_ct_ (const void *b1, const void *b2, size_t len)
 Compare memory in b1 and b2 in constant time, suitable for private data. More...
 
bool GNUNET_is_zero_ (const void *a, size_t n)
 Check that memory in a is all zeros. More...
 
int int void * GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
 Allocate memory. More...
 
void ** GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize, const char *filename, int linenumber)
 Allocate memory for a two dimensional array in one block and set up pointers. More...
 
void *** GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize, const char *filename, int linenumber)
 Allocate memory for a three dimensional array in one block and set up pointers. More...
 
void * GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int linenumber)
 Allocate and initialize memory. More...
 
void * GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
 Allocate memory. More...
 
void * GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
 Reallocate memory. More...
 
void GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
 Free memory. More...
 
char * GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
 Dup a string. More...
 
char * GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int linenumber)
 Dup partially a string. More...
 
void GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, unsigned int newCount, const char *filename, int linenumber)
 Grow an array, the new elements are zeroed out. More...
 
void GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
 Set the async scope for the current thread. More...
 
void GNUNET_async_scope_restore (struct GNUNET_AsyncScopeSave *old_scope)
 Clear the current thread's async scope. More...
 
void GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret)
 Get the current async scope. More...
 
void GNUNET_async_scope_fresh (struct GNUNET_AsyncScopeId *aid_ret)
 Generate a fresh async scope identifier. More...
 
int GNUNET_try_compression (const char *data, size_t old_size, char **result, size_t *new_size)
 Try to compress the given block of data using libz. More...
 
char * GNUNET_decompress (const char *input, size_t input_size, size_t output_size)
 Decompress input, return the decompressed data as output. More...
 
size_t GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter *bf)
 Get the number of the addresses set per element in the bloom filter. More...
 
struct GNUNET_CONTAINER_MultiHashMap32IteratorGNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map)
 Create an iterator for a 32-bit multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter, uint32_t *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
 Destroy a 32-bit multihashmap iterator. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap, void **element, GNUNET_CONTAINER_HeapCostType *cost)
 Get element and cost stored at the root of heap. 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...
 
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_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't this be the standard hmac function and the above be renamed? More...
 
void GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc)
 Cancel a file hashing operation. More...
 
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros (const struct GNUNET_HashCode *h)
 Count the number of leading 0 bits in h. More...
 
unsigned int GNUNET_CRYPTO_hash_count_tailing_zeros (const struct GNUNET_HashCode *h)
 Count the number of tailing 0 bits in h. 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...
 
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...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
 Convert a string representing a private key to a private key. More...
 
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...
 
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, const struct GNUNET_CRYPTO_EccPoint *input)
 Calculate ECC discrete logarithm for small factors. More...
 
void GNUNET_CRYPTO_ecc_dexp (int val, struct GNUNET_CRYPTO_EccPoint *r)
 Multiply the generator g of the elliptic curve by val to obtain the point on the curve representing val. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_dexp_mpi (const struct GNUNET_CRYPTO_EccScalar *val, struct GNUNET_CRYPTO_EccPoint *r)
 Multiply the generator g of the elliptic curve by val to obtain the point on the curve representing val. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_pmul_mpi (const struct GNUNET_CRYPTO_EccPoint *p, const struct GNUNET_CRYPTO_EccScalar *val, struct GNUNET_CRYPTO_EccPoint *r)
 Multiply the point p on the elliptic curve by val. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_add (const struct GNUNET_CRYPTO_EccPoint *a, const struct GNUNET_CRYPTO_EccPoint *b, struct GNUNET_CRYPTO_EccPoint *r)
 Add two points on the elliptic curve. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_rnd (struct GNUNET_CRYPTO_EccPoint *r, struct GNUNET_CRYPTO_EccPoint *r_inv)
 Obtain a random point on the curve and its additive inverse. More...
 
void GNUNET_CRYPTO_ecc_rnd_mpi (struct GNUNET_CRYPTO_EccScalar *r, struct GNUNET_CRYPTO_EccScalar *r_neg)
 Obtain a random scalar for point multiplication on the curve and its additive inverse. More...
 
void GNUNET_CRYPTO_ecc_random_mod_n (struct GNUNET_CRYPTO_EccScalar *r)
 Generate a random value mod n. More...
 
void GNUNET_CRYPTO_ecc_dlog_release (struct GNUNET_CRYPTO_EccDlogContext *dlc)
 Release precalculated values. More...
 
void GNUNET_CRYPTO_ecc_scalar_from_int (int64_t val, struct GNUNET_CRYPTO_EccScalar *r)
 Create a scalar from int value. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519 (const struct GNUNET_CRYPTO_PrivateKey *sk, struct GNUNET_CRYPTO_EcdhePrivateKey *x25519)
 Convert a GNUnet identity key to a key sutiable for HPKE (X25519) More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519 (const struct GNUNET_CRYPTO_PublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *x25519)
 Convert a GNUnet identity key to a key sutiable for HPKE (X25519) More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sender_setup (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, struct GNUNET_CRYPTO_HpkeContext *ctx)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sender_setup2 (enum GNUNET_CRYPTO_HpkeKem kem, enum GNUNET_CRYPTO_HpkeMode mode, struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_CRYPTO_EcdhePrivateKey *skS, const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, struct GNUNET_CRYPTO_HpkeContext *ctx)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_receiver_setup2 (enum GNUNET_CRYPTO_HpkeKem kem, enum GNUNET_CRYPTO_HpkeMode mode, const struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_EcdhePublicKey *pkS, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeContext *ctx)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_receiver_setup (const struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const uint8_t *info, size_t info_len, struct GNUNET_CRYPTO_HpkeContext *ctx)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal (struct GNUNET_CRYPTO_HpkeContext *ctx, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open (struct GNUNET_CRYPTO_HpkeContext *ctx, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len_p)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot (const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len)
 RFC9180 HPKE encryption. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_raw (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *data, size_t size, struct GNUNET_CRYPTO_EddsaSignature *sig)
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_derived (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
 This is a signature function for ECDSA which takes a private key, derives/blinds it and signs the message. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_derived (const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
 This is a signature function for EdDSA which takes a private key and derives it using the label and context before signing. More...
 
void GNUNET_CRYPTO_eddsa_key_get_public_from_scalar (const struct GNUNET_CRYPTO_EddsaPrivateScalar *s, struct GNUNET_CRYPTO_EddsaPublicKey *pkey)
 Extract the public key of the given private scalar. 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 c1 and c2. 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...
 
bool GNUNET_CRYPTO_rsa_public_key_check (const struct GNUNET_CRYPTO_RsaPublicKey *key)
 Check if key is well-formed. 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...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_blind (const void *message, size_t message_size, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, struct GNUNET_CRYPTO_RsaBlindedMessage *bm)
 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 struct GNUNET_CRYPTO_RsaBlindedMessage *bm)
 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 void *message, size_t message_size)
 Create and sign a full domain hash of a message. More...
 
void GNUNET_CRYPTO_rsa_blinded_message_free (struct GNUNET_CRYPTO_RsaBlindedMessage *bm)
 Free memory occupied by blinded 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 void *message, size_t message_size, 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...
 
void GNUNET_CRYPTO_cs_private_key_generate (struct GNUNET_CRYPTO_CsPrivateKey *priv)
 Create a new random private key. More...
 
void GNUNET_CRYPTO_cs_private_key_get_public (const struct GNUNET_CRYPTO_CsPrivateKey *priv, struct GNUNET_CRYPTO_CsPublicKey *pub)
 Extract the public key of the given private key. More...
 
void GNUNET_CRYPTO_cs_r_derive (const struct GNUNET_CRYPTO_CsSessionNonce *nonce, const char *seed, const struct GNUNET_CRYPTO_CsPrivateKey *lts, struct GNUNET_CRYPTO_CsRSecret r[2])
 Derive a new secret r pair r0 and r1. More...
 
void GNUNET_CRYPTO_cs_r_get_public (const struct GNUNET_CRYPTO_CsRSecret *r_priv, struct GNUNET_CRYPTO_CsRPublic *r_pub)
 Extract the public R of the given secret r. More...
 
void GNUNET_CRYPTO_cs_blinding_secrets_derive (const struct GNUNET_CRYPTO_CsBlindingNonce *blind_seed, struct GNUNET_CRYPTO_CsBlindingSecret bs[2])
 Derives new random blinding factors. More...
 
void GNUNET_CRYPTO_cs_calc_blinded_c (const struct GNUNET_CRYPTO_CsBlindingSecret bs[2], const struct GNUNET_CRYPTO_CsRPublic r_pub[2], const struct GNUNET_CRYPTO_CsPublicKey *pub, const void *msg, size_t msg_len, struct GNUNET_CRYPTO_CsC blinded_c[2], struct GNUNET_CRYPTO_CSPublicRPairP *r_pub_blind)
 Calculate two blinded c's. More...
 
void GNUNET_CRYPTO_cs_sign_derive (const struct GNUNET_CRYPTO_CsPrivateKey *priv, const struct GNUNET_CRYPTO_CsRSecret r[2], const struct GNUNET_CRYPTO_CsBlindedMessage *bm, struct GNUNET_CRYPTO_CsBlindSignature *cs_blind_sig)
 Sign a blinded c. More...
 
void GNUNET_CRYPTO_cs_unblind (const struct GNUNET_CRYPTO_CsBlindS *blinded_signature_scalar, const struct GNUNET_CRYPTO_CsBlindingSecret *bs, struct GNUNET_CRYPTO_CsS *signature_scalar)
 Unblind a blind-signed signature using a c that was blinded. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_cs_verify (const struct GNUNET_CRYPTO_CsSignature *sig, const struct GNUNET_CRYPTO_CsPublicKey *pub, const void *msg, size_t msg_len)
 Verify whether the given message corresponds to the given signature and the signature is valid with respect to the given public key. More...
 
struct GNUNET_CRYPTO_BlindingInputValuesGNUNET_CRYPTO_get_blinding_input_values (const struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv, const union GNUNET_CRYPTO_BlindSessionNonce *nonce, const char *salt)
 Compute blinding input values for a given nonce and salt. More...
 
void GNUNET_CRYPTO_blind_sign_pub_decref (struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub)
 Decrement reference counter of a bsign_pub, and free it if it reaches zero. More...
 
void GNUNET_CRYPTO_blind_sign_priv_decref (struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv)
 Decrement reference counter of a bsign_priv, and free it if it reaches zero. More...
 
void GNUNET_CRYPTO_unblinded_sig_decref (struct GNUNET_CRYPTO_UnblindedSignature *ub_sig)
 Decrement reference counter of a ub_sig, and free it if it reaches zero. More...
 
void GNUNET_CRYPTO_blinded_sig_decref (struct GNUNET_CRYPTO_BlindedSignature *blind_sig)
 Decrement reference counter of a blind_sig, and free it if it reaches zero. More...
 
void GNUNET_CRYPTO_blinded_message_decref (struct GNUNET_CRYPTO_BlindedMessage *bm)
 Decrement reference counter of a bm, and free it if it reaches zero. More...
 
struct GNUNET_CRYPTO_BlindedMessageGNUNET_CRYPTO_blinded_message_incref (struct GNUNET_CRYPTO_BlindedMessage *bm)
 Increment reference counter of the given bm. More...
 
struct GNUNET_CRYPTO_BlindingInputValuesGNUNET_CRYPTO_blinding_input_values_incref (struct GNUNET_CRYPTO_BlindingInputValues *bm)
 Increment reference counter of the given bi. More...
 
void GNUNET_CRYPTO_blinding_input_values_decref (struct GNUNET_CRYPTO_BlindingInputValues *bm)
 Decrement reference counter of the given bi, and free it if it reaches zero. More...
 
struct GNUNET_CRYPTO_BlindSignPublicKeyGNUNET_CRYPTO_bsign_pub_incref (struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub)
 Increment reference counter of the given bsign_pub. More...
 
struct GNUNET_CRYPTO_BlindSignPrivateKeyGNUNET_CRYPTO_bsign_priv_incref (struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv)
 Increment reference counter of the given bsign_priv. More...
 
struct GNUNET_CRYPTO_UnblindedSignatureGNUNET_CRYPTO_ub_sig_incref (struct GNUNET_CRYPTO_UnblindedSignature *ub_sig)
 Increment reference counter of the given ub_sig. More...
 
struct GNUNET_CRYPTO_BlindedSignatureGNUNET_CRYPTO_blind_sig_incref (struct GNUNET_CRYPTO_BlindedSignature *blind_sig)
 Increment reference counter of the given blind_sig. More...
 
int GNUNET_CRYPTO_bsign_pub_cmp (const struct GNUNET_CRYPTO_BlindSignPublicKey *bp1, const struct GNUNET_CRYPTO_BlindSignPublicKey *bp2)
 Compare two denomination public keys. More...
 
int GNUNET_CRYPTO_ub_sig_cmp (const struct GNUNET_CRYPTO_UnblindedSignature *sig1, const struct GNUNET_CRYPTO_UnblindedSignature *sig2)
 Compare two denomination signatures. More...
 
int GNUNET_CRYPTO_blind_sig_cmp (const struct GNUNET_CRYPTO_BlindedSignature *sig1, const struct GNUNET_CRYPTO_BlindedSignature *sig2)
 Compare two blinded denomination signatures. More...
 
int GNUNET_CRYPTO_blinded_message_cmp (const struct GNUNET_CRYPTO_BlindedMessage *bp1, const struct GNUNET_CRYPTO_BlindedMessage *bp2)
 Compare two blinded messages. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blind_sign_keys_create (struct GNUNET_CRYPTO_BlindSignPrivateKey **bsign_priv, struct GNUNET_CRYPTO_BlindSignPublicKey **bsign_pub, enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,...)
 Initialize public-private key pair for blind signatures. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blind_sign_keys_create_va (struct GNUNET_CRYPTO_BlindSignPrivateKey **bsign_priv, struct GNUNET_CRYPTO_BlindSignPublicKey **bsign_pub, enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher, va_list ap)
 Initialize public-private key pair for blind signatures. More...
 
struct GNUNET_CRYPTO_BlindedMessageGNUNET_CRYPTO_message_blind_to_sign (const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub, const union GNUNET_CRYPTO_BlindingSecretP *bks, const union GNUNET_CRYPTO_BlindSessionNonce *nonce, const void *message, size_t message_size, const struct GNUNET_CRYPTO_BlindingInputValues *alg_values)
 Blind message for blind signing with dk using blinding secret coin_bks. More...
 
struct GNUNET_CRYPTO_BlindedSignatureGNUNET_CRYPTO_blind_sign (const struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv, const char *salt, const struct GNUNET_CRYPTO_BlindedMessage *blinded_message)
 Create blind signature. More...
 
struct GNUNET_CRYPTO_UnblindedSignatureGNUNET_CRYPTO_blind_sig_unblind (const struct GNUNET_CRYPTO_BlindedSignature *blinded_sig, const union GNUNET_CRYPTO_BlindingSecretP *bks, const void *message, size_t message_size, const struct GNUNET_CRYPTO_BlindingInputValues *alg_values, const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub)
 Unblind blind signature. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blind_sig_verify (const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub, const struct GNUNET_CRYPTO_UnblindedSignature *ub_sig, const void *message, size_t message_size)
 Verify signature made blindly. More...
 
ssize_t GNUNET_CRYPTO_public_key_get_length (const struct GNUNET_CRYPTO_PublicKey *key)
 Get the compacted length of a GNUNET_CRYPTO_PublicKey. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_public_key_from_buffer (const void *buffer, size_t len, struct GNUNET_CRYPTO_PublicKey *key, size_t *read)
 Reads a GNUNET_CRYPTO_PublicKey from a compact buffer. More...
 
ssize_t GNUNET_CRYPTO_private_key_get_length (const struct GNUNET_CRYPTO_PrivateKey *key)
 Get the compacted length of a GNUNET_CRYPTO_PrivateKey. More...
 
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer (const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
 Writes a GNUNET_CRYPTO_PublicKey to a compact buffer. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer (const void *buffer, size_t len, struct GNUNET_CRYPTO_PrivateKey *key, size_t *read)
 Reads a GNUNET_CRYPTO_PrivateKey from a compact buffer. More...
 
ssize_t GNUNET_CRYPTO_write_private_key_to_buffer (const struct GNUNET_CRYPTO_PrivateKey *key, void *buffer, size_t len)
 Writes a GNUNET_CRYPTO_PrivateKey to a compact buffer. More...
 
ssize_t GNUNET_CRYPTO_signature_get_length (const struct GNUNET_CRYPTO_Signature *sig)
 Get the compacted length of a GNUNET_CRYPTO_Signature. More...
 
ssize_t GNUNET_CRYPTO_signature_get_raw_length_by_type (uint32_t type)
 Get the compacted length of a signature by type. More...
 
ssize_t GNUNET_CRYPTO_read_signature_from_buffer (struct GNUNET_CRYPTO_Signature *sig, const void *buffer, size_t len)
 Reads a GNUNET_CRYPTO_Signature from a compact buffer. More...
 
ssize_t GNUNET_CRYPTO_write_signature_to_buffer (const struct GNUNET_CRYPTO_Signature *sig, void *buffer, size_t len)
 Writes a GNUNET_CRYPTO_Signature to a compact buffer. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_ (const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_Signature *sig)
 Sign a given block. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_raw_ (const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, unsigned char *sig)
 Sign a given block. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_signature_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_Signature *sig, const struct GNUNET_CRYPTO_PublicKey *pub)
 Verify a given signature. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_signature_verify_raw_ (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const unsigned char *sig, const struct GNUNET_CRYPTO_PublicKey *pub)
 Verify a given signature. More...
 
char * GNUNET_CRYPTO_public_key_to_string (const struct GNUNET_CRYPTO_PublicKey *key)
 Creates a (Base32) string representation of the public key. More...
 
char * GNUNET_CRYPTO_private_key_to_string (const struct GNUNET_CRYPTO_PrivateKey *key)
 Creates a (Base32) string representation of the private key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string (const char *str, struct GNUNET_CRYPTO_PublicKey *key)
 Parses a (Base32) string representation of the public key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_private_key_from_string (const char *str, struct GNUNET_CRYPTO_PrivateKey *key)
 Parses a (Base32) string representation of the private key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public (const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
 Retrieves the public key representation of a private key. More...
 
struct GNUNET_OP_Handle * GNUNET_OP_create ()
 Create new operations handle. More...
 
void GNUNET_OP_destroy (struct GNUNET_OP_Handle *h)
 Destroy operations handle. More...
 
uint64_t GNUNET_OP_get_next_id (struct GNUNET_OP_Handle *h)
 Get a unique operation ID to distinguish between asynchronous requests. More...
 
int GNUNET_OP_get (struct GNUNET_OP_Handle *h, uint64_t op_id, GNUNET_ResultCallback *result_cb, void **cls, void **ctx)
 Find operation by ID. More...
 
uint64_t GNUNET_OP_add (struct GNUNET_OP_Handle *h, GNUNET_ResultCallback result_cb, void *cls, void *ctx)
 Add a new operation. More...
 
int GNUNET_OP_result (struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx)
 Call the result callback of an operation and remove it. More...
 
int GNUNET_OP_remove (struct GNUNET_OP_Handle *h, uint64_t op_id)
 Remove / cancel an operation. More...
 

Variables

uint32_t GNUNET_HashCode::bits [512/8/sizeof(uint32_t)]
 
uint32_t GNUNET_ShortHashCode::bits [256/8/sizeof(uint32_t)]
 
uint32_t GNUNET_Uuid::value [4]
 128 random bits. More...
 
uint16_t GNUNET_MessageHeader::size
 The length of the struct (in bytes, including the length field itself), in big-endian format. More...
 
uint16_t GNUNET_MessageHeader::type
 The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format. More...
 
struct GNUNET_MessageHeader GNUNET_OperationResultMessage::header
 
uint32_t GNUNET_OperationResultMessage::reserved
 
uint64_t GNUNET_OperationResultMessage::op_id
 Operation ID. More...
 
uint64_t GNUNET_OperationResultMessage::result_code
 Status code for the operation. More...
 
uint32_t GNUNET_AsyncScopeId::bits [16/sizeof(uint32_t)]
 
struct GNUNET_AsyncScopeId GNUNET_AsyncScopeSave::scope_id
 Saved scope. More...
 
int GNUNET_AsyncScopeSave::have_scope
 GNUNET_YES unless this saved scope is the unnamed root scope. More...
 
GNUNET_MQ_MessageValidationCallback GNUNET_MQ_MessageHandler::mv
 Callback to validate a message of the specified type. More...
 
GNUNET_MQ_MessageCallback GNUNET_MQ_MessageHandler::cb
 Callback, called every time a new message of the specified type has been received. More...
 
void * GNUNET_MQ_MessageHandler::cls
 Closure for mv and cb. More...
 
uint16_t GNUNET_MQ_MessageHandler::type
 Type of the message this handler covers, in host byte order. More...
 
uint16_t GNUNET_MQ_MessageHandler::expected_size
 Expected size of messages of this type. More...
 

Detailed Description

Multi-function utilities library for GNUnet programs.

Author
Christian Grothoff

Common buffer management functions.

Author
Florian Dold
Christian Grothoff
Nils Durner
Philipp Toelke
Christian Grothoff
Florian Dold
Christian Grothoff
Christian Grothoff
Krista Bennett
Gerd Knorr kraxe.nosp@m.l@by.nosp@m.tesex.nosp@m..org
Ioana Patrascu
Tzvetan Horozov
Milan
Christian Grothoff
Tobias Frisch
Jeffrey Burdges
Christian Grothoff
Krista Bennett
Gerd Knorr kraxe.nosp@m.l@by.nosp@m.tesex.nosp@m..org
Ioana Patrascu
Tzvetan Horozov

Macro Definition Documentation

◆ GNUNET_UTIL_VERSION

#define GNUNET_UTIL_VERSION   0x000A0104

Version of the API (for entire gnunetutil.so library).

Definition at line 96 of file gnunet_common.h.

◆ GNUNET_MIN

#define GNUNET_MIN (   a,
 
)    (((a) < (b)) ? (a) : (b))

Definition at line 115 of file gnunet_common.h.

◆ GNUNET_MAX

#define GNUNET_MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

Definition at line 117 of file gnunet_common.h.

◆ BYTE_SWAP_16

#define BYTE_SWAP_16 (   x)    ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))

Endian operations.

Definition at line 166 of file gnunet_common.h.

◆ BYTE_SWAP_32

#define BYTE_SWAP_32 (   x)
Value:
((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
| (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))

Definition at line 168 of file gnunet_common.h.

◆ BYTE_SWAP_64

#define BYTE_SWAP_64 (   x)
Value:
((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \
40) \
| (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \
<< 8) \
| (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \
>> 24) \
| (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \
>> \
56))

Definition at line 172 of file gnunet_common.h.

◆ GNUNET_htobe16 [1/2]

#define GNUNET_htobe16 (   x)    BYTE_SWAP_16 (x)

Definition at line 201 of file gnunet_common.h.

◆ GNUNET_htobe16 [2/2]

#define GNUNET_htobe16 (   x)    (x)

Definition at line 201 of file gnunet_common.h.

◆ GNUNET_htole16 [1/2]

#define GNUNET_htole16 (   x)    (x)

Definition at line 202 of file gnunet_common.h.

◆ GNUNET_htole16 [2/2]

#define GNUNET_htole16 (   x)    BYTE_SWAP_16 (x)

Definition at line 202 of file gnunet_common.h.

◆ GNUNET_be16toh [1/2]

#define GNUNET_be16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_be16toh [2/2]

#define GNUNET_be16toh (   x)    (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_le16toh [1/2]

#define GNUNET_le16toh (   x)    (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_le16toh [2/2]

#define GNUNET_le16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_htobe32 [1/2]

#define GNUNET_htobe32 (   x)    BYTE_SWAP_32 (x)

Definition at line 206 of file gnunet_common.h.

◆ GNUNET_htobe32 [2/2]

#define GNUNET_htobe32 (   x)    (x)

Definition at line 206 of file gnunet_common.h.

◆ GNUNET_htole32 [1/2]

#define GNUNET_htole32 (   x)    (x)

Definition at line 207 of file gnunet_common.h.

◆ GNUNET_htole32 [2/2]

#define GNUNET_htole32 (   x)    BYTE_SWAP_32 (x)

Definition at line 207 of file gnunet_common.h.

◆ GNUNET_be32toh [1/2]

#define GNUNET_be32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 208 of file gnunet_common.h.

◆ GNUNET_be32toh [2/2]

#define GNUNET_be32toh (   x)    (x)

Definition at line 208 of file gnunet_common.h.

◆ GNUNET_le32toh [1/2]

#define GNUNET_le32toh (   x)    (x)

Definition at line 209 of file gnunet_common.h.

◆ GNUNET_le32toh [2/2]

#define GNUNET_le32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 209 of file gnunet_common.h.

◆ GNUNET_htobe64 [1/2]

#define GNUNET_htobe64 (   x)    BYTE_SWAP_64 (x)

Definition at line 211 of file gnunet_common.h.

◆ GNUNET_htobe64 [2/2]

#define GNUNET_htobe64 (   x)    (x)

Definition at line 211 of file gnunet_common.h.

◆ GNUNET_htole64 [1/2]

#define GNUNET_htole64 (   x)    (x)

Definition at line 212 of file gnunet_common.h.

◆ GNUNET_htole64 [2/2]

#define GNUNET_htole64 (   x)    BYTE_SWAP_64 (x)

Definition at line 212 of file gnunet_common.h.

◆ GNUNET_be64toh [1/2]

#define GNUNET_be64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 213 of file gnunet_common.h.

◆ GNUNET_be64toh [2/2]

#define GNUNET_be64toh (   x)    (x)

Definition at line 213 of file gnunet_common.h.

◆ GNUNET_le64toh [1/2]

#define GNUNET_le64toh (   x)    (x)

Definition at line 214 of file gnunet_common.h.

◆ GNUNET_le64toh [2/2]

#define GNUNET_le64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 214 of file gnunet_common.h.

◆ GNUNET_NZL

#define GNUNET_NZL (   l)    GNUNET_MAX (1, l)

Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).

Basically, C standard says that "int[n] x;" is undefined if n=0. This was supposed to prevent issues with pointer aliasing. However, C compilers may conclude that n!=0 as n=0 would be undefined, and then optimize under the assumption n!=0, which could cause actual issues. Hence, when initializing an array on the stack with a variable-length that might be zero, write "int[GNUNET_NZL(n)] x;" instead of "int[n] x".

Definition at line 230 of file gnunet_common.h.

◆ GNUNET_PACKED

#define GNUNET_PACKED   __attribute__ ((packed))

gcc-ism to get packed structs.

Definition at line 236 of file gnunet_common.h.

◆ GNUNET_ALIGN

#define GNUNET_ALIGN   __attribute__ ((aligned (8)))

gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.

See also gcc bug #33594.

Definition at line 251 of file gnunet_common.h.

◆ GNUNET_UNUSED

#define GNUNET_UNUSED   __attribute__ ((unused))

gcc-ism to document unused arguments

Definition at line 257 of file gnunet_common.h.

◆ GNUNET_NORETURN

#define GNUNET_NORETURN   __attribute__ ((noreturn))

gcc-ism to document functions that don't return

Definition at line 262 of file gnunet_common.h.

◆ GNUNET_NETWORK_STRUCT_BEGIN

#define GNUNET_NETWORK_STRUCT_BEGIN

Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.

Definition at line 267 of file gnunet_common.h.

◆ GNUNET_NETWORK_STRUCT_END

#define GNUNET_NETWORK_STRUCT_END

Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.

Definition at line 272 of file gnunet_common.h.

◆ GN_LIKELY

#define GN_LIKELY (   expr)    (expr)

Definition at line 515 of file gnunet_common.h.

◆ GN_UNLIKELY

#define GN_UNLIKELY (   expr)    (expr)

Definition at line 516 of file gnunet_common.h.

◆ GNUNET_LOG_CALL_STATUS

#define GNUNET_LOG_CALL_STATUS   -1

Definition at line 520 of file gnunet_common.h.

◆ GNUNET_log_from

#define GNUNET_log_from (   kind,
  comp,
  ... 
)
Value:
do \
{ \
static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
if ((GNUNET_EXTRA_LOGGING > 0) || \
((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
{ \
if (GN_UNLIKELY (log_call_enabled == -1)) \
log_call_enabled = \
GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
(comp), \
__FILE__, \
__FUNCTION__, \
__LINE__); \
{ \
GNUNET_log_skip (-1, GNUNET_NO); \
} \
else \
{ \
if (GN_UNLIKELY (log_call_enabled)) \
GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
} \
} \
} while (0)
#define GNUNET_LOG_CALL_STATUS
#define GN_UNLIKELY(expr)
@ GNUNET_NO
int GNUNET_get_log_skip(void)
Get the number of log calls that are going to be skipped.
#define GNUNET_EXTRA_LOGGING
define GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source tree where gnunet_config....
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_DEBUG

Definition at line 543 of file gnunet_common.h.

◆ GNUNET_log

#define GNUNET_log (   kind,
  ... 
)
Value:
do \
{ \
static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
if ((GNUNET_EXTRA_LOGGING > 0) || \
((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
{ \
if (GN_UNLIKELY (log_call_enabled == -1)) \
log_call_enabled = \
GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
NULL, \
__FILE__, \
__FUNCTION__, \
__LINE__); \
{ \
GNUNET_log_skip (-1, GNUNET_NO); \
} \
else \
{ \
if (GN_UNLIKELY (log_call_enabled)) \
GNUNET_log_nocheck ((kind), __VA_ARGS__); \
} \
} \
} while (0)

Definition at line 569 of file gnunet_common.h.

◆ GNUNET_B2S

#define GNUNET_B2S (   obj)    GNUNET_b2s ((obj), sizeof (*(obj)))

Convert a fixed-sized object to a string using GNUNET_b2s().

Parameters
objaddress of object to convert
Returns
string representing the binary obj buffer

Definition at line 662 of file gnunet_common.h.

◆ GNUNET_static_assert

#define GNUNET_static_assert (   cond)    GNUNET_assert (cond)

Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime and resulting in an abort() on failure.

This is the case where the compiler does not support static assertions.

Parameters
condcondition to test, 0 implies failure

Definition at line 1053 of file gnunet_common.h.

◆ GNUNET_memcmp

#define GNUNET_memcmp (   a,
 
)
Value:
({ \
const typeof (*b) * _a = (a); \
const typeof (*a) * _b = (b); \
memcmp (_a, _b, sizeof(*a)); \
})

Compare memory in a and b, where both must be of the same pointer type.

Do NOT use this function on arrays, it would only compare the first element!

Definition at line 1267 of file gnunet_common.h.

◆ GNUNET_memcmp_priv

#define GNUNET_memcmp_priv (   a,
 
)
Value:
({ \
const typeof (*b) * _a = (a); \
const typeof (*a) * _b = (b); \
GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
})

Compare memory in a and b in constant time, suitable for private data.

Both a and b must be of the same pointer type.

Do NOT use this function on arrays, it would only compare the first element!

Definition at line 1296 of file gnunet_common.h.

◆ GNUNET_is_zero

#define GNUNET_is_zero (   a)     GNUNET_is_zero_ ((a), sizeof (*(a)))

Check that memory in a is all zeros.

a must be a pointer.

Parameters
apointer to a struct which should be tested for the entire memory being zero'ed out.
Returns
GNUNET_YES if a is zero, GNUNET_NO otherwise

Definition at line 1324 of file gnunet_common.h.

◆ GNUNET_memcpy

#define GNUNET_memcpy (   dst,
  src,
 
)
Value:
do \
{ \
if (0 != n) \
{ \
(void) memcpy (dst, src, n); \
} \
} while (0)

Call memcpy() but check for n being 0 first.

In the latter case, it is now safe to pass NULL for src or dst. Unlike traditional memcpy(), returns nothing.

Parameters
dstdestination of the copy, may be NULL if n is zero
srcsource of the copy, may be NULL if n is zero
nnumber of bytes to copy

Definition at line 1337 of file gnunet_common.h.

◆ __func__

#define __func__   "<unknown>"

Definition at line 1852 of file gnunet_common.h.

◆ GNUNET_CONTAINER_LIB_H

#define GNUNET_CONTAINER_LIB_H

Definition at line 61 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_DLL_insert_sorted

#define GNUNET_CONTAINER_DLL_insert_sorted (   TYPE,
  comparator,
  comparator_cls,
  head,
  tail,
  element 
)
Value:
do \
{ \
if ((NULL == head) || (0 < comparator (comparator_cls, element, head))) \
{ \
/* insert at head, element < head */ \
GNUNET_CONTAINER_DLL_insert (head, tail, element); \
} \
else \
{ \
TYPE *pos; \
\
for (pos = head; NULL != pos; pos = pos->next) \
if (0 < comparator (comparator_cls, element, pos)) \
break; /* element < pos */ \
if (NULL == pos) /* => element > tail */ \
{ \
GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); \
} \
else /* prev < element < pos */ \
{ \
GNUNET_CONTAINER_DLL_insert_after (head, tail, pos->prev, element); \
} \
} \
} while (0)

Insertion sort of element into DLL from head to tail sorted by comparator.

Parameters
TYPEelement type of the elements, e.g. struct ListElement
comparatorfunction like memcmp() to compare elements; takes three arguments, the comparator_cls and two elements, returns an int (-1, 0 or 1)
comparator_clsclosure for comparator
[in,out]headhead of DLL
[in,out]tailtail of DLL
elementelement to insert

Definition at line 2097 of file gnunet_container_lib.h.

◆ 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 77 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_AES_KEY_LENGTH

#define GNUNET_CRYPTO_AES_KEY_LENGTH   (256 / 8)

length of the sessionkey in bytes (256 BIT sessionkey)

Definition at line 110 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HASH_LENGTH

#define GNUNET_CRYPTO_HASH_LENGTH   (512 / 8)

Length of a hash value.

Definition at line 115 of file gnunet_crypto_lib.h.

◆ 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 121 of file gnunet_crypto_lib.h.

◆ 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 519 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_AEAD_ID

#define GNUNET_CRYPTO_HPKE_AEAD_ID   0x0003

Definition at line 2108 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_NONCE_LEN

#define GNUNET_CRYPTO_HPKE_NONCE_LEN   12

Definition at line 2111 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_KEY_LEN

#define GNUNET_CRYPTO_HPKE_KEY_LEN   32

Definition at line 2114 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_TAG_LEN

#define GNUNET_CRYPTO_HPKE_TAG_LEN   16

Definition at line 2117 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_SEAL_OVERHEAD_BYTES

#define GNUNET_CRYPTO_HPKE_SEAL_OVERHEAD_BYTES   GNUNET_CRYPTO_HPKE_TAG_LEN

Definition at line 2120 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES

#define GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES
Value:
#define GNUNET_CRYPTO_HPKE_SEAL_OVERHEAD_BYTES
HPKE DHKEM encapsulation (X25519) See RFC 9180.

Definition at line 2123 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_sign

#define GNUNET_CRYPTO_sign (   priv,
  ps,
  sig 
)
Value:
do { \
/* check size is set correctly */ \
GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
/* check 'ps' begins with the purpose */ \
GNUNET_static_assert (((void*) (ps)) == \
((void*) &(ps)->purpose)); \
GNUNET_assert (GNUNET_OK == \
&(ps)->purpose, \
sig)); \
} while (0)
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_(const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_Signature *sig)
Sign a given block.
Definition: crypto_pkey.c:308
@ GNUNET_OK

Sign a given block with GNUNET_CRYPTO_PrivateKey.

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

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

Definition at line 4784 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_signature_verify

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

Verify a given signature with GNUNET_CRYPTO_PublicKey.

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

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

Definition at line 4857 of file gnunet_crypto_lib.h.

Typedef Documentation

◆ GNUNET_ChildCompletedCallback

typedef void(* GNUNET_ChildCompletedCallback) (void *cls, enum GNUNET_OS_ProcessStatusType type, long unsigned int exit_code)

Defines a GNUNET_ChildCompletedCallback which is sent back upon death or completion of a child process.

Parameters
clshandle for the callback
typetype of the process
exit_codestatus code of the process

Definition at line 53 of file gnunet_child_management_lib.h.

◆ GNUNET_FileNameCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback) (void *cls, const char *filename)

Function called with a filename.

Parameters
clsclosure
filenamecomplete filename (absolute path)
Returns
GNUNET_OK to continue to iterate, GNUNET_NO to stop iteration with no error, GNUNET_SYSERR to abort iteration with error!

Definition at line 1 of file gnunet_common.h.

◆ GNUNET_ContinuationCallback

typedef void(* GNUNET_ContinuationCallback) (void *cls)

Generic continuation callback.

Parameters
clsClosure.

Definition at line 402 of file gnunet_common.h.

◆ GNUNET_ResultCallback

typedef void(* GNUNET_ResultCallback) (void *cls, int64_t result_code, const void *data, uint16_t data_size)

Function called with the result of an asynchronous operation.

Parameters
clsClosure.
result_codeResult code for the operation.
dataData result for the operation.
data_sizeSize of data.

Definition at line 418 of file gnunet_common.h.

◆ 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 1134 of file gnunet_crypto_lib.h.

Enumeration Type Documentation

◆ GNUNET_GenericReturnValue

Named constants for return values.

The following invariants hold: GNUNET_NO == 0 (to allow if (GNUNET_NO)) GNUNET_OK != GNUNET_SYSERR, GNUNET_OK != GNUNET_NO, GNUNET_NO != GNUNET_SYSERR and finally GNUNET_YES != GNUNET_NO.

Enumerator
GNUNET_SYSERR 
GNUNET_NO 
GNUNET_OK 
GNUNET_YES 

Definition at line 105 of file gnunet_common.h.

106{
107 GNUNET_SYSERR = -1,
108 GNUNET_NO = 0,
109 GNUNET_OK = 1,
110 /* intentionally identical to #GNUNET_OK! */
111 GNUNET_YES = 1,
112};
@ GNUNET_YES
@ GNUNET_SYSERR

◆ GNUNET_SCHEDULER_Priority

Valid task priorities.

Use these, do not pass random integers! For various reasons (#3862 – building with QT Creator, and our restricted cross-compilation with emscripten) this cannot be in gnunet_scheduler_lib.h, but it works if we declare it here. Naturally, logically this is part of the scheduler.

Enumerator
GNUNET_SCHEDULER_PRIORITY_KEEP 

Run with the same priority as the current job.

GNUNET_SCHEDULER_PRIORITY_IDLE 

Run when otherwise idle.

GNUNET_SCHEDULER_PRIORITY_BACKGROUND 

Run as background job (higher than idle, lower than default).

GNUNET_SCHEDULER_PRIORITY_DEFAULT 

Run with the default priority (normal P2P operations).

Any task that is scheduled without an explicit priority being specified will run with this priority.

GNUNET_SCHEDULER_PRIORITY_HIGH 

Run with high priority (important requests).

Higher than DEFAULT.

GNUNET_SCHEDULER_PRIORITY_UI 

Run with priority for interactive tasks.

Higher than "HIGH".

GNUNET_SCHEDULER_PRIORITY_URGENT 

Run with priority for urgent tasks.

Use for things like aborts and shutdowns that need to preempt "UI"-level tasks. Higher than "UI".

GNUNET_SCHEDULER_PRIORITY_SHUTDOWN 

This is an internal priority level that is only used for tasks that are being triggered due to shutdown (they have automatically highest priority).

User code must not use this priority level directly. Tasks run with this priority level that internally schedule other tasks will see their original priority level be inherited (unless otherwise specified).

GNUNET_SCHEDULER_PRIORITY_COUNT 

Number of priorities (must be the last priority).

This priority must not be used by clients.

Definition at line 1864 of file gnunet_common.h.

1865{
1870
1875
1881
1889
1895
1901
1909
1919
1925};
@ GNUNET_SCHEDULER_PRIORITY_UI
Run with priority for interactive tasks.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
@ GNUNET_SCHEDULER_PRIORITY_URGENT
Run with priority for urgent tasks.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
@ GNUNET_SCHEDULER_PRIORITY_COUNT
Number of priorities (must be the last priority).
@ GNUNET_SCHEDULER_PRIORITY_KEEP
Run with the same priority as the current job.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
@ GNUNET_SCHEDULER_PRIORITY_SHUTDOWN
This is an internal priority level that is only used for tasks that are being triggered due to shutdo...

◆ GNUNET_CRYPTO_KeyType

Key type for the generic public key union.

Enumerator
GNUNET_PUBLIC_KEY_TYPE_ECDSA 

The identity type.

The value is the same as the PKEY record type.

GNUNET_PUBLIC_KEY_TYPE_EDDSA 

EDDSA identity.

The value is the same as the EDKEY record type.

Definition at line 366 of file gnunet_crypto_lib.h.

367{
373
379};
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.

◆ GNUNET_CRYPTO_HpkeMode

HPKE RFC 9180.

The HPKE Mode "PSK" stands for "Pre-Shared Key". The "AUTH" variants use an authenticating KEM construction.

Enumerator
GNUNET_CRYPTO_HPKE_MODE_BASE 
GNUNET_CRYPTO_HPKE_MODE_PSK 
GNUNET_CRYPTO_HPKE_MODE_AUTH 
GNUNET_CRYPTO_HPKE_MODE_AUTH_PSK 

Definition at line 2099 of file gnunet_crypto_lib.h.

2100{
2105};
@ GNUNET_CRYPTO_HPKE_MODE_PSK
@ GNUNET_CRYPTO_HPKE_MODE_AUTH_PSK
@ GNUNET_CRYPTO_HPKE_MODE_BASE
@ GNUNET_CRYPTO_HPKE_MODE_AUTH

◆ GNUNET_CRYPTO_HpkeRole

Enumerator
GNUNET_CRYPTO_HPKE_ROLE_R 
GNUNET_CRYPTO_HPKE_ROLE_S 

Definition at line 2127 of file gnunet_crypto_lib.h.

2128{
2131};
@ GNUNET_CRYPTO_HPKE_ROLE_R
@ GNUNET_CRYPTO_HPKE_ROLE_S

◆ GNUNET_CRYPTO_HpkeKem

Enumerator
GNUNET_CRYPTO_HPKE_KEM_DH_X25519_HKDF256 
GNUNET_CRYPTO_HPKE_KEM_DH_X25519ELLIGATOR_HKDF256 

Definition at line 2142 of file gnunet_crypto_lib.h.

2143{
2146};
@ GNUNET_CRYPTO_HPKE_KEM_DH_X25519_HKDF256
@ GNUNET_CRYPTO_HPKE_KEM_DH_X25519ELLIGATOR_HKDF256

◆ GNUNET_CRYPTO_BlindSignatureAlgorithm

Types of public keys used for blind signatures.

Enumerator
GNUNET_CRYPTO_BSA_INVALID 

Invalid type of signature.

GNUNET_CRYPTO_BSA_RSA 

RSA blind signature.

GNUNET_CRYPTO_BSA_CS 

Clause Blind Schnorr signature.

Definition at line 3975 of file gnunet_crypto_lib.h.

3976{
3977
3982
3987
3992};
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.

Function Documentation

◆ GNUNET_buffer_prealloc()

void GNUNET_buffer_prealloc ( struct GNUNET_Buffer buf,
size_t  capacity 
)

Initialize a buffer with the given capacity.

When a buffer is allocated with this function, a warning is logged when the buffer exceeds the initial capacity.

Parameters
bufthe buffer to initialize
capacitythe capacity (in bytes) to allocate for buf

Definition at line 35 of file buffer.c.

37{
38 /* Buffer should be zero-initialized */
39 GNUNET_assert (0 == buf->mem);
40 GNUNET_assert (0 == buf->capacity);
41 GNUNET_assert (0 == buf->position);
42 buf->mem = GNUNET_malloc (capacity);
43 buf->capacity = capacity;
44 buf->warn_grow = GNUNET_YES;
45}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
size_t capacity
Capacity of the buffer.
int warn_grow
Log a warning if the buffer is grown over its initially allocated capacity.
size_t position
Current write position.
char * mem
Backing memory.

References GNUNET_Buffer::capacity, GNUNET_assert, GNUNET_malloc, GNUNET_YES, GNUNET_Buffer::mem, GNUNET_Buffer::position, and GNUNET_Buffer::warn_grow.

◆ GNUNET_buffer_ensure_remaining()

void GNUNET_buffer_ensure_remaining ( struct GNUNET_Buffer buf,
size_t  n 
)

Make sure that at least n bytes remaining in the buffer.

Parameters
bufbuffer to potentially grow
nnumber of bytes that should be available to write

Definition at line 55 of file buffer.c.

57{
58 size_t new_capacity = buf->position + n;
59
60 /* guard against overflow */
61 GNUNET_assert (new_capacity >= buf->position);
62 if (new_capacity <= buf->capacity)
63 return;
64 /* warn if calculation of expected size was wrong */
66 if (new_capacity < buf->capacity * 2)
67 new_capacity = buf->capacity * 2;
68 buf->capacity = new_capacity;
69 if (NULL != buf->mem)
70 buf->mem = GNUNET_realloc (buf->mem, new_capacity);
71 else
72 buf->mem = GNUNET_malloc (new_capacity);
73}
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.

References GNUNET_Buffer::capacity, GNUNET_assert, GNUNET_break, GNUNET_malloc, GNUNET_realloc, GNUNET_YES, GNUNET_Buffer::mem, GNUNET_Buffer::position, and GNUNET_Buffer::warn_grow.

Referenced by GNUNET_buffer_reap_str(), GNUNET_buffer_write(), GNUNET_buffer_write_data_encoded(), GNUNET_buffer_write_path(), and GNUNET_buffer_write_vfstr().

Here is the caller graph for this function:

◆ GNUNET_buffer_write()

void GNUNET_buffer_write ( struct GNUNET_Buffer buf,
const char *  data,
size_t  len 
)

Write bytes to the buffer.

Grows the buffer if necessary.

Parameters
bufbuffer to write to
datadata to read from
lennumber of bytes to copy from data to buf

Definition at line 86 of file buffer.c.

89{
91 memcpy (buf->mem + buf->position, data, len);
92 buf->position += len;
93}
static char * data
The data to insert into the dht.
void GNUNET_buffer_ensure_remaining(struct GNUNET_Buffer *buf, size_t n)
Make sure that at least n bytes remaining in the buffer.
Definition: buffer.c:55

References data, GNUNET_buffer_ensure_remaining(), GNUNET_Buffer::mem, and GNUNET_Buffer::position.

Referenced by GNUNET_buffer_write_path(), GNUNET_buffer_write_str(), GNUNET_STRINGS_urlencode(), and write_to_buffer().

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

◆ GNUNET_buffer_write_str()

void GNUNET_buffer_write_str ( struct GNUNET_Buffer buf,
const char *  str 
)

Write a 0-terminated string to a buffer, excluding the 0-terminator.

Grows the buffer if necessary.

Parameters
bufthe buffer to write to
strthe string to write to buf
bufthe buffer to write to
strthe string to write to buf

Definition at line 103 of file buffer.c.

105{
106 size_t len = strlen (str);
107
108 GNUNET_buffer_write (buf, str, len);
109}
void GNUNET_buffer_write(struct GNUNET_Buffer *buf, const char *data, size_t len)
Write bytes to the buffer.
Definition: buffer.c:86

References GNUNET_buffer_write().

Referenced by GNUNET_CONFIGURATION_serialize_diagnostics(), and login_redirect().

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

◆ GNUNET_buffer_write_data_encoded()

void GNUNET_buffer_write_data_encoded ( struct GNUNET_Buffer buf,
const void *  data,
size_t  data_len 
)

Write data encoded via GNUNET_STRINGS_data_to_string to the buffer.

Grows the buffer if necessary.

Parameters
bufbuffer to write to
datadata to read from
data_lennumber of bytes to copy from data to buf

Definition at line 264 of file buffer.c.

267{
268 size_t outlen = data_len * 8;
269
270 if (outlen % 5 > 0)
271 outlen += 5 - outlen % 5;
272 outlen /= 5;
274 outlen);
275 GNUNET_assert (NULL !=
277 data_len,
278 (buf->mem
279 + buf->position),
280 outlen));
281 buf->position += outlen;
282 GNUNET_assert (buf->position <= buf->capacity);
283}
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:709

References GNUNET_Buffer::capacity, data, GNUNET_assert, GNUNET_buffer_ensure_remaining(), GNUNET_STRINGS_data_to_string(), GNUNET_Buffer::mem, and GNUNET_Buffer::position.

Here is the call graph for this function:

◆ GNUNET_buffer_write_path()

void GNUNET_buffer_write_path ( struct GNUNET_Buffer buf,
const char *  str 
)

Write a path component to a buffer, ensuring that there is exactly one slash between the previous contents of the buffer and the new string.

Parameters
bufbuffer to write to
strstring containing the new path component

Definition at line 180 of file buffer.c.

181{
182 size_t len = strlen (str);
183
184 while ( (0 != len) && ('/' == str[0]) )
185 {
186 str++;
187 len--;
188 }
189 if ( (0 == buf->position) || ('/' != buf->mem[buf->position - 1]) )
190 {
192 buf->mem[buf->position++] = '/';
193 }
194 GNUNET_buffer_write (buf, str, len);
195}

References GNUNET_buffer_ensure_remaining(), GNUNET_buffer_write(), GNUNET_Buffer::mem, and GNUNET_Buffer::position.

Here is the call graph for this function:

◆ GNUNET_buffer_write_fstr()

void GNUNET_buffer_write_fstr ( struct GNUNET_Buffer buf,
const char *  fmt,
  ... 
)

Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.

Grows the buffer if necessary.

Parameters
bufthe buffer to write to
fmtformat string
...format arguments

Referenced by GNUNET_CONFIGURATION_serialize_diagnostics(), GNUNET_STRINGS_urlencode(), and login_redirect().

Here is the caller graph for this function:

◆ GNUNET_buffer_write_vfstr()

void void GNUNET_buffer_write_vfstr ( struct GNUNET_Buffer buf,
const char *  fmt,
va_list  args 
)

Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.

Grows the buffer if necessary.

Parameters
bufthe buffer to write to
fmtformat string
argsformat argument list

Definition at line 230 of file buffer.c.

233{
234 int res;
235 va_list args2;
236
237 va_copy (args2, args);
238 res = vsnprintf (NULL, 0, fmt, args2);
239 va_end (args2);
240
241 GNUNET_assert (res >= 0);
243
244 va_copy (args2, args);
245 res = vsnprintf (buf->mem + buf->position, res + 1, fmt, args2);
246 va_end (args2);
247
248 GNUNET_assert (res >= 0);
249 buf->position += res;
250 GNUNET_assert (buf->position <= buf->capacity);
251}
static char * res
Currently read line or NULL on EOF.

References consensus-simulation::args, GNUNET_Buffer::capacity, GNUNET_assert, GNUNET_buffer_ensure_remaining(), GNUNET_Buffer::mem, GNUNET_Buffer::position, and res.

Referenced by GNUNET_buffer_write_fstr().

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

◆ GNUNET_buffer_reap_str()

char * GNUNET_buffer_reap_str ( struct GNUNET_Buffer buf)

Clear the buffer and return the string it contained.

The caller is responsible to eventually GNUNET_free the returned string.

The returned string is always 0-terminated.

Parameters
bufthe buffer to reap the string from
Returns
the buffer contained in the string

Definition at line 123 of file buffer.c.

124{
125 char *res;
126
127 /* ensure 0-termination */
128 if ( (0 == buf->position) || ('\0' != buf->mem[buf->position - 1]))
129 {
131 buf->mem[buf->position++] = '\0';
132 }
133 res = buf->mem;
134 memset (buf, 0, sizeof (struct GNUNET_Buffer));
135 return res;
136}
Dynamically growing buffer.

References GNUNET_buffer_ensure_remaining(), GNUNET_Buffer::mem, GNUNET_Buffer::position, and res.

Referenced by GNUNET_CONFIGURATION_serialize_diagnostics(), GNUNET_STRINGS_urlencode(), and login_redirect().

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

◆ GNUNET_buffer_reap()

void * GNUNET_buffer_reap ( struct GNUNET_Buffer buf,
size_t *  size 
)

Clear the buffer and return its contents.

The caller is responsible to eventually GNUNET_free the returned data.

Parameters
bufthe buffer to reap the contents from
sizewhere to store the size of the returned data
Returns
the data contained in the string

Definition at line 149 of file buffer.c.

150{
151 *size = buf->position;
152 void *res = buf->mem;
153 memset (buf, 0, sizeof (struct GNUNET_Buffer));
154 return res;
155}
static unsigned int size
Size of the "table".
Definition: peer.c:68

References GNUNET_Buffer::mem, GNUNET_Buffer::position, res, and size.

Referenced by GNUNET_BIO_get_buffer_contents().

Here is the caller graph for this function:

◆ GNUNET_buffer_clear()

void GNUNET_buffer_clear ( struct GNUNET_Buffer buf)

Free the backing memory of the given buffer.

Does not free the memory of the buffer control structure, which is typically stack-allocated.

Definition at line 164 of file buffer.c.

165{
166 GNUNET_free (buf->mem);
167 memset (buf, 0, sizeof (struct GNUNET_Buffer));
168}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free, and GNUNET_Buffer::mem.

Referenced by GNUNET_BIO_write_close(), and GNUNET_STRINGS_urlencode().

Here is the caller graph for this function:

◆ GNUNET_wait_child()

struct GNUNET_ChildWaitHandle * GNUNET_wait_child ( struct GNUNET_OS_Process proc,
GNUNET_ChildCompletedCallback  cb,
void *  cb_cls 
)

Starts the handling of the child processes.

Function checks the status of the child process and sends back a GNUNET_ChildCompletedCallback upon completion/death of the child.

Parameters
procchild process which is monitored
cbreference to the callback which is called after completion
cb_clsclosure for the callback
Returns
GNUNET_ChildWaitHandle is returned

Definition at line 198 of file child_management.c.

201{
202 struct GNUNET_ChildWaitHandle *cwh;
203 bool may_race = (NULL == sigpipe);
204
206 cwh = GNUNET_new (struct GNUNET_ChildWaitHandle);
207 cwh->proc = proc;
208 cwh->cb = cb;
209 cwh->cb_cls = cb_cls;
211 cwh_tail,
212 cwh);
213 if (NULL == sig_task)
214 {
220 NULL);
221 }
222 /* Handle race-condition case where the child terminated just before we
223 installed the signal handler and thus we missed the signal. */
224 if (may_race)
226 return cwh;
227}
static void sighandler_child_death(void)
Signal handler called for SIGCHLD.
static void child_management_start(void)
Initializing the signal pipe for child handling.
static struct GNUNET_ChildWaitHandle * cwh_tail
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
static struct GNUNET_ChildWaitHandle * cwh_head
static struct GNUNET_SCHEDULER_Task * sig_task
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:1617
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1662
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Struct which defines a Child Wait handle.
GNUNET_ChildCompletedCallback cb
Callback which is called upon completion/death of the child task.
void * cb_cls
Closure for the handle.
struct GNUNET_OS_Process * proc
Child process which is managed.

References GNUNET_ChildWaitHandle::cb, GNUNET_ChildWaitHandle::cb_cls, child_management_start(), cwh_head, cwh_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_new, GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_UNIT_FOREVER_REL, maint_child_death(), GNUNET_ChildWaitHandle::proc, sig_task, sighandler_child_death(), and sigpipe.

Referenced by exec_bash_script_run(), handle_uri(), and netjail_start_run().

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

◆ GNUNET_wait_child_cancel()

void GNUNET_wait_child_cancel ( struct GNUNET_ChildWaitHandle cwh)

Stop waiting on this child.

Definition at line 231 of file child_management.c.

232{
234 cwh_tail,
235 cwh);
236 GNUNET_free (cwh);
237 if (NULL != cwh_head)
238 return;
240}
static void child_management_done(void)
Clean up.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.

References child_management_done(), cwh_head, cwh_tail, GNUNET_CONTAINER_DLL_remove, and GNUNET_free.

Referenced by exec_bash_script_cleanup(), netjail_start_cleanup(), and shutdown_program().

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

◆ GNUNET_get_log_call_status()

int GNUNET_get_log_call_status ( int  caller_level,
const char *  comp,
const char *  file,
const char *  function,
int  line 
)

Decides whether a particular logging call should or should not be allowed to be made.

Used internally by GNUNET_log*()

Parameters
caller_levelloglevel the caller wants to use
compcomponent name the caller uses (NULL means that global component name is used)
filefile name containing the logging call, usually FILE
functionfunction which tries to make a logging call, usually FUNCTION
lineline at which the call is made, usually LINE
Returns
0 to disallow the call, 1 to allow it

Definition at line 500 of file common_logging.c.

505{
506 struct LogDef *ld;
507 int i;
508 int force_only;
509
510 if (NULL == comp)
511 /* Use default component */
512 comp = component_nopid;
513
514 /* We have no definitions to override globally configured log level,
515 * so just use it right away.
516 */
518 return caller_level <= min_level;
519
520 /* Only look for forced definitions? */
521 force_only = min_level >= 0;
522 for (i = 0; i < logdefs_len; i++)
523 {
524 ld = &logdefs[i];
525 if (((! force_only) || ld->force) &&
526 ((line >= ld->from_line) && (line <= ld->to_line) ) &&
527 (0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) &&
528 (0 == regexec (&ld->file_regex, file, 0, NULL, 0)) &&
529 (0 == regexec (&ld->function_regex, function, 0, NULL, 0)))
530 {
531 /* We're finished */
532 return caller_level <= ld->level;
533 }
534 }
535 /* No matches - use global level, if defined */
536 if (min_level >= 0)
537 return caller_level <= min_level;
538 /* All programs/services previously defaulted to WARNING.
539 * Now *we* default to WARNING, and THEY default to NULL.
540 * Or rather we default to MESSAGE, since things aren't always bad.
541 */
542 return caller_level <= GNUNET_ERROR_TYPE_MESSAGE;
543}
static int gnunet_force_log_present
GNUNET_YES if at least one definition with forced == 1 is available.
static int logdefs_len
The number of units used in logdefs array.
static struct LogDef * logdefs
Dynamic array of logging definitions.
static char * component_nopid
Running component (without pid).
static enum GNUNET_ErrorType min_level
Minimum log level.
static char * line
Desired phone line (string to be converted to a hash).
@ GNUNET_ERROR_TYPE_MESSAGE
Represents a single logging definition.
int to_line
Highest line at which this definition matches.
int from_line
Lowest line at which this definition matches.
int force
1 if this definition comes from GNUNET_FORCE_LOG, which means that it overrides any configuration opt...
regex_t file_regex
File name regex.
regex_t function_regex
Function name regex.
int level
Maximal log level allowed for calls that match this definition.
regex_t component_regex
Component name regex.

References component_nopid, LogDef::component_regex, LogDef::file_regex, LogDef::force, LogDef::from_line, LogDef::function_regex, GNUNET_ERROR_TYPE_MESSAGE, gnunet_force_log_present, GNUNET_NO, LogDef::level, line, logdefs, logdefs_len, min_level, and LogDef::to_line.

Referenced by GCC_debug(), GCCH_debug(), GCT_debug(), and get_nick_record().

Here is the caller graph for this function:

◆ GNUNET_b2s()

const char * GNUNET_b2s ( const void *  buf,
size_t  buf_size 
)

Convert a buffer to an 8-character string representative of the contents.

This is used for logging binary data when debugging.

Parameters
bufbuffer to log
buf_sizenumber of bytes in buf
Returns
text representation of buf, valid until next call to this function

Definition at line 324 of file common_logging.c.

326{
327 static GNUNET_THREAD_LOCAL char ret[9];
328 struct GNUNET_HashCode hc;
329 char *tmp;
330
332 buf_size,
333 &hc);
335 sizeof (hc));
336 memcpy (ret,
337 tmp,
338 8);
339 GNUNET_free (tmp);
340 ret[8] = '\0';
341 return ret;
342}
static int ret
Final status code.
Definition: gnunet-arm.c:94
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
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:764
#define GNUNET_THREAD_LOCAL
Definition: platform.h:247
A 512-bit hashcode.

References GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_THREAD_LOCAL, and ret.

Here is the call graph for this function:

◆ GNUNET_htonll()

uint64_t GNUNET_htonll ( uint64_t  n)

Convert unsigned 64-bit integer to network byte order.

Parameters
nThe value in host byte order.
Returns
The same value in network byte order.

Definition at line 37 of file common_endian.c.

38{
39#if __BYTE_ORDER == __BIG_ENDIAN
40 return n;
41#elif __BYTE_ORDER == __LITTLE_ENDIAN
42 return (((uint64_t) htonl (n)) << 32) + htonl (n >> 32);
43#else
44 #error byteorder undefined
45#endif
46}

Referenced by abd_string_to_value(), block_proc(), change_service(), commit_set(), consider_sending_fc(), create_loc_uri(), determine_id(), GCCH_handle_channel_plaintext_data_ack(), GNUNET_ABD_delegate_issue(), GNUNET_ABD_delegate_serialize(), GNUNET_ABD_delegates_serialize(), GNUNET_ARM_request_service_list(), GNUNET_BIO_write_int64(), GNUNET_CRYPTO_ecc_scalar_from_int(), GNUNET_CRYPTO_random_timeflake(), GNUNET_DATASTORE_get_key(), GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_DATASTORE_reserve(), GNUNET_FS_tree_encoder_next(), GNUNET_GNSRECORD_pow_round(), GNUNET_GNSRECORD_records_serialize(), GNUNET_hton_double(), GNUNET_NAMESTORE_zone_iterator_next(), GNUNET_NAMESTORE_zone_monitor_next(), GNUNET_PEERSTORE_iteration_next(), GNUNET_PEERSTORE_monitor_next(), GNUNET_RECLAIM_attribute_store(), GNUNET_RECLAIM_credential_store(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_hton(), handle_client_accept(), hash_for_index_cb(), increment_seq(), notify_change(), print_record(), qconv_abs_time(), qconv_array(), qconv_int64(), qconv_rel_time(), qconv_uint64(), queue_send_msg(), run(), save(), send_add_queue(), send_channel_data_ack(), send_client_done(), send_client_element(), send_update_queue(), signal_result(), transmit(), transmit_item(), transmit_set(), unindex_process(), union_accept(), uri_chk_parse(), and uri_loc_parse().

◆ GNUNET_ntohll()

uint64_t GNUNET_ntohll ( uint64_t  n)

Convert unsigned 64-bit integer to host byte order.

Parameters
nThe value in network byte order.
Returns
The same value in host byte order.

Definition at line 54 of file common_endian.c.

55{
56#if __BYTE_ORDER == __BIG_ENDIAN
57 return n;
58#elif __BYTE_ORDER == __LITTLE_ENDIAN
59 return (((uint64_t) ntohl (n)) << 32) + ntohl (n >> 32);
60#else
61 #error byteorder undefined
62#endif
63}

Referenced by abd_value_to_string(), backward_resolution(), cb_intersection_element_removed(), cmp_pow_value(), copy_element_cb(), extract_abs_time(), extract_array_generic(), extract_int64(), extract_rel_time(), extract_timestamp(), extract_uint64(), find_proof(), GNUNET_ABD_delegate_deserialize(), GNUNET_ABD_delegates_deserialize(), GNUNET_BIO_read_int64(), GNUNET_CRYPTO_hash_count_leading_zeros(), GNUNET_CRYPTO_hash_count_tailing_zeros(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_publish_stop(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_GNSRECORD_check_pow(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_ntoh_double(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_ntoh(), GNUNET_xfree_(), GNUNET_xrealloc_(), handle_add_queue_message(), handle_alice_client_message(), handle_arm_list_result(), handle_arm_result(), handle_attribute_store_message(), handle_bob_client_message(), handle_client_index_start(), handle_client_loc_sign(), handle_credential_store_message(), handle_data(), handle_flow_control(), handle_get(), handle_get_key(), handle_get_zero_anonymity(), handle_iterate_next(), handle_iteration_next(), handle_monitor_next(), handle_reserve(), handle_result(), handle_send_message_ack(), handle_set(), handle_start(), handle_statistics_value(), handle_statistics_watch_value(), handle_stop(), handle_union_p2p_strata_estimator(), handle_update_queue_message(), increment_seq(), print_record(), process_result_with_request(), queue_send_msg(), reconstruct_cb(), set_result_cb(), try_match_block(), uri_chk_to_string(), uri_loc_to_string(), and verify_message_crypto().

◆ GNUNET_hton_double()

double GNUNET_hton_double ( double  d)

Convert double to network byte order.

Parameters
dThe value in host byte order.
Returns
The same value in network byte order.

Definition at line 70 of file common_endian.c.

71{
72 double res;
73 uint64_t *in = (uint64_t *) &d;
74 uint64_t *out = (uint64_t *) &res;
75
76 out[0] = GNUNET_htonll (in[0]);
77
78 return res;
79}
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37

References d, GNUNET_htonll(), and res.

Referenced by setup_estimate_message().

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

◆ GNUNET_ntoh_double()

double GNUNET_ntoh_double ( double  d)

Convert double to host byte order.

Parameters
dThe value in network byte order.
Returns
The same value in host byte order.

Definition at line 83 of file common_endian.c.

84{
85 double res;
86 uint64_t *in = (uint64_t *) &d;
87 uint64_t *out = (uint64_t *) &res;
88
89 out[0] = GNUNET_ntohll (in[0]);
90
91 return res;
92}
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54

References d, GNUNET_ntohll(), and res.

Referenced by handle_estimate().

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

◆ GNUNET_memcmp_ct_()

int GNUNET_memcmp_ct_ ( const void *  b1,
const void *  b2,
size_t  len 
)

Compare memory in b1 and b2 in constant time, suitable for private data.

Parameters
b1some buffer of size len
b2another buffer of size len
lennumber of bytes in b1 and b2
Returns
0 if buffers are equal,

Definition at line 131 of file consttime_memcmp.c.

132{
133 const uint8_t *c1, *c2;
134 uint16_t d, r, m;
135
136#if USE_VOLATILE_TEMPORARY
137 volatile uint16_t v;
138#else
139 uint16_t v;
140#endif
141
142 c1 = b1;
143 c2 = b2;
144
145 r = 0;
146 while (len)
147 {
148 /*
149 * Take the low 8 bits of r (in the range 0x00 to 0xff,
150 * or 0 to 255);
151 * As explained elsewhere, the low 8 bits of r will be zero
152 * if and only if all bytes compared so far were identical;
153 * Zero-extend to a 16-bit type (in the range 0x0000 to
154 * 0x00ff);
155 * Add 255, yielding a result in the range 255 to 510;
156 * Save that in a volatile variable to prevent
157 * the compiler from trying any shortcuts (the
158 * use of a volatile variable depends on "#ifdef
159 * USE_VOLATILE_TEMPORARY", and most compilers won't
160 * need it);
161 * Divide by 256 yielding a result of 1 if the original
162 * value of r was non-zero, or 0 if r was zero;
163 * Subtract 1, yielding 0 if r was non-zero, or -1 if r
164 * was zero;
165 * Convert to uint16_t, yielding 0x0000 if r was
166 * non-zero, or 0xffff if r was zero;
167 * Save in m.
168 */v = ((uint16_t) (uint8_t) r) + 255;
169 m = v / 256 - 1;
170
171 /*
172 * Get the values from *c1 and *c2 as uint8_t (each will
173 * be in the range 0 to 255, or 0x00 to 0xff);
174 * Convert them to signed int values (still in the
175 * range 0 to 255);
176 * Subtract them using signed arithmetic, yielding a
177 * result in the range -255 to +255;
178 * Convert to uint16_t, yielding a result in the range
179 * 0xff01 to 0xffff (for what was previously -255 to
180 * -1), or 0, or in the range 0x0001 to 0x00ff (for what
181 * was previously +1 to +255).
182 */d = (uint16_t) ((int) *c1 - (int) *c2);
183
184 /*
185 * If the low 8 bits of r were previously 0, then m
186 * is now 0xffff, so (d & m) is the same as d, so we
187 * effectively copy d to r;
188 * Otherwise, if r was previously non-zero, then m is
189 * now 0, so (d & m) is zero, so leave r unchanged.
190 * Note that the low 8 bits of d will be zero if and
191 * only if d == 0, which happens when *c1 == *c2.
192 * The low 8 bits of r are thus zero if and only if the
193 * entirety of r is zero, which happens if and only if
194 * all bytes compared so far were equal. As soon as a
195 * non-zero value is stored in r, it remains unchanged
196 * for the remainder of the loop.
197 */r |= (d & m);
198
199 /*
200 * Increment pointers, decrement length, and loop.
201 */
202 ++c1;
203 ++c2;
204 --len;
205 }
206
207 /*
208 * At this point, r is an unsigned value, which will be 0 if the
209 * final result should be zero, or in the range 0x0001 to 0x00ff
210 * (1 to 255) if the final result should be positive, or in the
211 * range 0xff01 to 0xffff (65281 to 65535) if the final result
212 * should be negative.
213 *
214 * We want to convert the unsigned values in the range 0xff01
215 * to 0xffff to signed values in the range -255 to -1, while
216 * converting the other unsigned values to equivalent signed
217 * values (0, or +1 to +255).
218 *
219 * On a machine with two's complement arithmetic, simply copying
220 * the underlying bits (with sign extension if int is wider than
221 * 16 bits) would do the job, so something like this might work:
222 *
223 * return (int16_t)r;
224 *
225 * However, that invokes implementation-defined behaviour,
226 * because values larger than 32767 can't fit in a signed 16-bit
227 * integer without overflow.
228 *
229 * To avoid any implementation-defined behaviour, we go through
230 * these contortions:
231 *
232 * a. Calculate ((uint32_t)r + 0x8000). The cast to uint32_t
233 * it to prevent problems on platforms where int is narrower
234 * than 32 bits. If int is a larger than 32-bits, then the
235 * usual arithmetic conversions cause this addition to be
236 * done in unsigned int arithmetic. If int is 32 bits
237 * or narrower, then this addition is done in uint32_t
238 * arithmetic. In either case, no overflow or wraparound
239 * occurs, and the result from this step has a value that
240 * will be one of 0x00008000 (32768), or in the range
241 * 0x00008001 to 0x000080ff (32769 to 33023), or in the range
242 * 0x00017f01 to 0x00017fff (98049 to 98303).
243 *
244 * b. Cast the result from (a) to uint16_t. This effectively
245 * discards the high bits of the result, in a way that is
246 * well defined by the C language. The result from this step
247 * will be of type uint16_t, and its value will be one of
248 * 0x8000 (32768), or in the range 0x8001 to 0x80ff (32769 to
249 * 33023), or in the range 0x7f01 to 0x7fff (32513 to
250 * 32767).
251 *
252 * c. Cast the result from (b) to int32_t. We use int32_t
253 * instead of int because we need a type that's strictly
254 * larger than 16 bits, and the C standard allows
255 * implementations where int is only 16 bits. The result
256 * from this step will be of type int32_t, and its value will
257 * be one of 0x00008000 (32768), or in the range 0x00008001
258 * to 0x000080ff (32769 to 33023), or in the range 0x00007f01
259 * to 0x00007fff (32513 to 32767).
260 *
261 * d. Take the result from (c) and subtract 0x8000 (32768) using
262 * signed int32_t arithmetic. The result from this step will
263 * be of type int32_t and the value will be one of
264 * 0x00000000 (0), or in the range 0x00000001 to 0x000000ff
265 * (+1 to +255), or in the range 0xffffff01 to 0xffffffff
266 * (-255 to -1).
267 *
268 * e. Cast the result from (d) to int. This does nothing
269 * interesting, except to make explicit what would have been
270 * implicit in the return statement. The final result is an
271 * int in the range -255 to +255.
272 *
273 * Unfortunately, compilers don't seem to be good at figuring
274 * out that most of this can be optimised away by careful choice
275 * of register width and sign extension.
276 *
277 */return (/*e*/ int) (/*d*/
278 (/*c*/ int32_t) (/*b*/ uint16_t) (/*a*/ (uint32_t) r + 0x8000)
279 - 0x8000);
280}
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104

References d, consensus-simulation::int, and m.

◆ GNUNET_is_zero_()

bool GNUNET_is_zero_ ( const void *  a,
size_t  n 
)

Check that memory in a is all zeros.

a must be a pointer.

Parameters
apointer to n bytes which should be tested for the entire memory being zero'ed out.
nnumber of bytes in to be tested
Returns
true if a is zero, false_NO otherwise

Definition at line 425 of file common_allocation.c.

427{
428 const char *b = a;
429
430 for (size_t i = 0; i < n; i++)
431 if (b[i])
432 return false;
433 return true;
434}

◆ GNUNET_xmalloc_()

int int void * GNUNET_xmalloc_ ( size_t  size,
const char *  filename,
int  linenumber 
)

Allocate memory.

Checks the return value, aborts if no more memory is available. Don't use GNUNET_xmalloc_ directly. Use the GNUNET_malloc macro. The memory will be zero'ed out.

Parameters
sizenumber of bytes to allocate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Definition at line 48 of file common_allocation.c.

51{
52 void *ret;
53
54 /* As a security precaution, we generally do not allow very large
55 * allocations using the default 'GNUNET_malloc()' macro */
58 linenumber);
61 linenumber);
62 if (NULL == ret)
63 {
65 "malloc");
66 GNUNET_assert (0);
67 }
68 return ret;
69}
#define LOG_STRERROR(kind, syscall)
static char * filename
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Allocate memory.
#define GNUNET_assert_at(cond, f, l)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.

References filename, GNUNET_assert, GNUNET_assert_at, GNUNET_ERROR_TYPE_ERROR, GNUNET_MAX_MALLOC_CHECKED, GNUNET_xmalloc_unchecked_(), LOG_STRERROR, ret, and size.

Referenced by GNUNET_xgrow_(), GNUNET_xnew_array_2d_(), GNUNET_xnew_array_3d_(), GNUNET_xstrdup_(), and GNUNET_xstrndup_().

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

◆ GNUNET_xnew_array_2d_()

void ** GNUNET_xnew_array_2d_ ( size_t  n,
size_t  m,
size_t  elementSize,
const char *  filename,
int  linenumber 
)

Allocate memory for a two dimensional array in one block and set up pointers.

Aborts if no more memory is available. Don't use GNUNET_xnew_array_2d_ directly. Use the GNUNET_new_array_2d macro. The memory of the elements will be zero'ed out.

Parameters
nsize of the first dimension
msize of the second dimension
elementSizesize of a single element in bytes
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Definition at line 73 of file common_allocation.c.

78{
79 /* use char pointer internally to avoid void pointer arithmetic warnings */
80 char **ret = GNUNET_xmalloc_ (n * sizeof(void *) /* 1. dim header */
81 + n * m * elementSize, /* element data */
83 linenumber);
84
85 for (size_t i = 0; i < n; i++)
86 ret[i] = (char *) ret /* base address */
87 + n * sizeof(void *) /* skip 1. dim header */
88 + i * m * elementSize; /* skip to 2. dim row header */
89 return (void **) ret;
90}
void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.

References filename, GNUNET_xmalloc_(), m, and ret.

Here is the call graph for this function:

◆ GNUNET_xnew_array_3d_()

void *** GNUNET_xnew_array_3d_ ( size_t  n,
size_t  m,
size_t  o,
size_t  elementSize,
const char *  filename,
int  linenumber 
)

Allocate memory for a three dimensional array in one block and set up pointers.

Aborts if no more memory is available. Don't use GNUNET_xnew_array_3d_ directly. Use the GNUNET_new_array_3d macro. The memory of the elements will be zero'ed out.

Parameters
nsize of the first dimension
msize of the second dimension
osize of the third dimension
elementSizesize of a single element in bytes
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Definition at line 94 of file common_allocation.c.

100{
101 /* use char pointer internally to avoid void pointer arithmetic warnings */
102 char ***ret = GNUNET_xmalloc_ (n * sizeof(void **) /* 1. dim header */
103 + n * m * sizeof(void *) /* 2. dim header */
104 + n * m * o * elementSize, /* element data */
105 filename,
106 linenumber);
107
108 for (size_t i = 0; i < n; i++)
109 {
110 /* need to cast to (char *) temporarily for byte level accuracy */
111 ret[i] = (char **) ((char *) ret /* base address */
112 + n * sizeof(void **) /* skip 1. dim header */
113 + i * m * sizeof(void *)); /* skip to 2. dim header */
114 for (size_t j = 0; j < m; j++)
115 ret[i][j] = (char *) ret /* base address */
116 + n * sizeof(void **) /* skip 1. dim header */
117 + n * m * sizeof(void *) /* skip 2. dim header */
118 + i * m * o * elementSize /* skip to 2. dim part */
119 + j * o * elementSize; /* skip to 3. dim row data */
120 }
121 return (void ***) ret;
122}

References filename, GNUNET_xmalloc_(), m, and ret.

Here is the call graph for this function:

◆ GNUNET_xmemdup_()

void * GNUNET_xmemdup_ ( const void *  buf,
size_t  size,
const char *  filename,
int  linenumber 
)

Allocate and initialize memory.

Checks the return value, aborts if no more memory is available. Don't use GNUNET_xmemdup_ directly. Use the GNUNET_memdup macro.

Parameters
bufbuffer to initialize from (must contain size bytes)
sizenumber of bytes to allocate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Definition at line 126 of file common_allocation.c.

130{
131 void *ret;
132
133 /* As a security precaution, we generally do not allow very large
134 * allocations here */
136 filename,
137 linenumber);
139 filename,
140 linenumber);
141 ret = malloc (size);
142 if (NULL == ret)
143 {
145 "malloc");
146 GNUNET_assert (0);
147 }
149 buf,
150 size);
151 return ret;
152}
#define INT_MAX
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.

References filename, GNUNET_assert, GNUNET_assert_at, GNUNET_ERROR_TYPE_ERROR, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, INT_MAX, LOG_STRERROR, ret, and size.

◆ GNUNET_xmalloc_unchecked_()

void * GNUNET_xmalloc_unchecked_ ( size_t  size,
const char *  filename,
int  linenumber 
)

Allocate memory.

This function does not check if the allocation request is within reasonable bounds, allowing allocations larger than 40 MB. If you don't expect the possibility of very large allocations, use GNUNET_malloc instead. The memory will be zero'ed out.

Parameters
sizenumber of bytes to allocate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
pointer to size bytes of memory, NULL if we do not have enough memory

Definition at line 156 of file common_allocation.c.

159{
160 void *result;
161
162 (void) filename;
163 (void) linenumber;
164 result = malloc (size);
165 if (NULL == result)
166 return NULL;
167 memset (result,
168 0,
169 size);
170 return result;
171}
static int result
Global testing status.

References filename, result, and size.

Referenced by GNUNET_xmalloc_().

Here is the caller graph for this function:

◆ GNUNET_xrealloc_()

void * GNUNET_xrealloc_ ( void *  ptr,
size_t  n,
const char *  filename,
int  linenumber 
)

Reallocate memory.

Checks the return value, aborts if no more memory is available.

Definition at line 175 of file common_allocation.c.

179{
180 (void) filename;
181 (void) linenumber;
182
183#if defined(M_SIZE)
184#if ENABLE_POISONING
185 {
186 uint64_t *base = ptr;
187 size_t s = M_SIZE (ptr);
188
189 if (s > n)
190 {
191 const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
192 char *cbase = ptr;
193
194 GNUNET_memcpy (&cbase[n],
195 &baadfood,
196 GNUNET_MIN (8 - (n % 8),
197 s - n));
198 for (size_t i = 1 + (n + 7) / 8; i < s / 8; i++)
199 base[i] = baadfood;
200 GNUNET_memcpy (&base[s / 8],
201 &baadfood,
202 s % 8);
203 }
204 }
205#endif
206#endif
207 ptr = realloc (ptr, n);
208 if ((NULL == ptr) && (n > 0))
209 {
211 "realloc");
212 GNUNET_assert (0);
213 }
214 return ptr;
215}
#define GNUNET_MIN(a, b)

References filename, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_memcpy, GNUNET_MIN, GNUNET_ntohll(), and LOG_STRERROR.

Here is the call graph for this function:

◆ GNUNET_xfree_()

void GNUNET_xfree_ ( void *  ptr,
const char *  filename,
int  linenumber 
)

Free memory.

Merely a wrapper for the case that we want to keep track of allocations. Don't use GNUNET_xfree_ directly. Use the GNUNET_free macro.

Parameters
ptrpointer to memory to free
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)

Definition at line 235 of file common_allocation.c.

238{
239 if (NULL == ptr)
240 return;
241#if defined(M_SIZE)
242#if ENABLE_POISONING
243 {
244 const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
245 uint64_t *base = ptr;
246 size_t s = M_SIZE (ptr);
247
248 for (size_t i = 0; i < s / 8; i++)
249 base[i] = baadfood;
250 GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
251 }
252#endif
253#endif
254 free (ptr);
255}

References GNUNET_memcpy, and GNUNET_ntohll().

Referenced by GNUNET_xgrow_().

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

◆ GNUNET_xstrdup_()

char * GNUNET_xstrdup_ ( const char *  str,
const char *  filename,
int  linenumber 
)

Dup a string.

Don't call GNUNET_xstrdup_ directly. Use the GNUNET_strdup macro.

Parameters
strstring to duplicate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
the duplicated string

Definition at line 259 of file common_allocation.c.

262{
263 size_t slen = strlen (str) + 1;
264 char *res;
265
266 GNUNET_assert_at (str != NULL,
267 filename,
268 linenumber);
269 res = GNUNET_xmalloc_ (slen,
270 filename,
271 linenumber);
273 str,
274 slen);
275 return res;
276}

References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_xmalloc_(), and res.

Here is the call graph for this function:

◆ GNUNET_xstrndup_()

char * GNUNET_xstrndup_ ( const char *  str,
size_t  len,
const char *  filename,
int  linenumber 
)

Dup partially a string.

Don't call GNUNET_xstrndup_ directly. Use the GNUNET_strndup macro.

Parameters
strstring to duplicate
lenlength of the string to duplicate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
the duplicated string

Definition at line 299 of file common_allocation.c.

303{
304 char *res;
305
306 if (0 == len)
307 return GNUNET_strdup ("");
308 GNUNET_assert_at (NULL != str,
309 filename,
310 linenumber);
311 len = strnlen (str, len);
312 res = GNUNET_xmalloc_ (len + 1,
313 filename,
314 linenumber);
315 GNUNET_memcpy (res, str, len);
316 /* res[len] = '\0'; 'malloc' zeros out anyway */
317 return res;
318}
static size_t strnlen(const char *s, size_t n)
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_strdup, GNUNET_xmalloc_(), res, and strnlen().

Here is the call graph for this function:

◆ GNUNET_xgrow_()

void GNUNET_xgrow_ ( void **  old,
size_t  elementSize,
unsigned int *  oldCount,
unsigned int  newCount,
const char *  filename,
int  linenumber 
)

Grow an array, the new elements are zeroed out.

Grows old by (*oldCount-newCount)*elementSize bytes and sets *oldCount to newCount.

Don't call GNUNET_xgrow_ directly. Use the GNUNET_array_grow macro.

Parameters
oldaddress of the pointer to the array *old may be NULL
elementSizethe size of the elements of the array
oldCountaddress of the number of elements in the *old array
newCountnumber of elements in the new array, may be 0 (then *old will be NULL afterwards)
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)

Definition at line 322 of file common_allocation.c.

328{
329 void *tmp;
330 size_t size;
331
332 GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber);
333 size = newCount * elementSize;
334 if (0 == size)
335 {
336 tmp = NULL;
337 }
338 else
339 {
340 tmp = GNUNET_xmalloc_ (size,
341 filename,
342 linenumber);
343 if (NULL != *old)
344 {
345 GNUNET_memcpy (tmp,
346 *old,
347 elementSize * GNUNET_MIN (*oldCount,
348 newCount));
349 }
350 }
351
352 if (NULL != *old)
353 {
354 GNUNET_xfree_ (*old,
355 filename,
356 linenumber);
357 }
358 *old = tmp;
359 *oldCount = newCount;
360}
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.

References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_MIN, GNUNET_xfree_(), GNUNET_xmalloc_(), INT_MAX, and size.

Here is the call graph for this function:

◆ GNUNET_async_scope_enter()

void GNUNET_async_scope_enter ( const struct GNUNET_AsyncScopeId aid,
struct GNUNET_AsyncScopeSave old_scope 
)

Set the async scope for the current thread.

Parameters
aidthe async scope identifier
[out]old_scopelocation to save the old scope

Definition at line 1478 of file common_logging.c.

1480{
1481 *old_scope = current_async_scope;
1484}
static GNUNET_THREAD_LOCAL struct GNUNET_AsyncScopeSave current_async_scope
Asynchronous scope of the current thread, or NULL if we have not entered an async scope yet.
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
struct GNUNET_AsyncScopeId scope_id
Saved scope.

References current_async_scope, GNUNET_YES, GNUNET_AsyncScopeSave::have_scope, and GNUNET_AsyncScopeSave::scope_id.

Referenced by GNUNET_SCHEDULER_begin_async_scope(), and GNUNET_SCHEDULER_do_work().

Here is the caller graph for this function:

◆ GNUNET_async_scope_restore()

void GNUNET_async_scope_restore ( struct GNUNET_AsyncScopeSave old_scope)

Clear the current thread's async scope.

Parameters
old_scopescope to restore

Definition at line 1493 of file common_logging.c.

1494{
1495 current_async_scope = *old_scope;
1496}

References current_async_scope.

Referenced by GNUNET_SCHEDULER_do_work().

Here is the caller graph for this function:

◆ GNUNET_async_scope_get()

void GNUNET_async_scope_get ( struct GNUNET_AsyncScopeSave scope_ret)

Get the current async scope.

Parameters
[out]scope_retpointer to where the result is stored

Definition at line 1519 of file common_logging.c.

1520{
1521 *scope_ret = current_async_scope;
1522}

References current_async_scope.

Referenced by add_without_sets(), GNUNET_SCHEDULER_add_at_with_priority(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_do_work(), and setup_job_headers().

Here is the caller graph for this function:

◆ GNUNET_async_scope_fresh()

void GNUNET_async_scope_fresh ( struct GNUNET_AsyncScopeId aid_ret)

Generate a fresh async scope identifier.

Parameters
[out]aid_retpointer to where the result is stored

Definition at line 1505 of file common_logging.c.

1506{
1508 aid_ret,
1509 sizeof(struct GNUNET_AsyncScopeId));
1510}
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Identifier for an asynchronous execution context.

References GNUNET_CRYPTO_QUALITY_WEAK, and GNUNET_CRYPTO_random_block().

Here is the call graph for this function:

◆ GNUNET_try_compression()

int GNUNET_try_compression ( const char *  data,
size_t  old_size,
char **  result,
size_t *  new_size 
)

Try to compress the given block of data using libz.

Only returns the compressed block if compression worked and the new block is actually smaller. Decompress using GNUNET_decompress().

Parameters
datablock to compress; if compression resulted in a smaller block, the first bytes of data are updated to the compressed data
old_sizenumber of bytes in data
[out]resultset to the compressed data, if compression worked
[out]new_sizeset to size of result, if compression worked
Returns
GNUNET_YES if compression reduce the size, GNUNET_NO if compression did not help

Definition at line 33 of file compress.c.

37{
38 char *tmp;
39 uLongf dlen;
40
41 *result = NULL;
42 *new_size = 0;
43#ifdef compressBound
44 dlen = compressBound (old_size);
45#else
46 dlen = old_size + (old_size / 100) + 20;
47 /* documentation says 100.1% oldSize + 12 bytes, but we
48 * should be able to overshoot by more to be safe */
49#endif
50 tmp = GNUNET_malloc (dlen);
51 if (Z_OK ==
52 compress2 ((Bytef *) tmp,
53 &dlen,
54 (const Bytef *) data,
55 old_size, 9))
56 {
57 if (dlen < old_size)
58 {
59 *result = tmp;
60 *new_size = dlen;
61 return GNUNET_YES;
62 }
63 }
64 GNUNET_free (tmp);
65 return GNUNET_NO;
66}

References data, GNUNET_free, GNUNET_malloc, GNUNET_NO, GNUNET_YES, and result.

Referenced by GNUNET_FS_meta_data_serialize(), and strata_estimator_write().

Here is the caller graph for this function:

◆ GNUNET_decompress()

char * GNUNET_decompress ( const char *  input,
size_t  input_size,
size_t  output_size 
)

Decompress input, return the decompressed data as output.

Dual to GNUNET_try_compression(). Caller must set output_size to the number of bytes that were originally compressed.

Parameters
inputcompressed data
input_sizenumber of bytes in input
output_sizeexpected size of the output
Returns
NULL on error, buffer of output_size decompressed bytes otherwise

Definition at line 70 of file compress.c.

73{
74 char *output;
75 uLongf olen;
76
77 olen = output_size;
78 output = GNUNET_malloc (olen);
79 if (Z_OK ==
80 uncompress ((Bytef *) output,
81 &olen,
82 (const Bytef *) input,
83 input_size))
84 return output;
85 GNUNET_free (output);
86 return NULL;
87}

References GNUNET_free, and GNUNET_malloc.

Referenced by GNUNET_FS_meta_data_deserialize(), and strata_estimator_read().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_get_element_addresses()

size_t GNUNET_CONTAINER_bloomfilter_get_element_addresses ( const struct GNUNET_CONTAINER_BloomFilter bf)

Get the number of the addresses set per element in the bloom filter.

Parameters
bfthe filter
Returns
addresses set per element in the bf

Definition at line 88 of file container_bloomfilter.c.

90{
91 if (bf == NULL)
92 return 0;
93 return bf->addressesPerElement;
94}
unsigned int addressesPerElement
How many bits we set for each stored element.

References GNUNET_CONTAINER_BloomFilter::addressesPerElement.

◆ GNUNET_CONTAINER_multihashmap32_iterator_create()

struct GNUNET_CONTAINER_MultiHashMap32Iterator * GNUNET_CONTAINER_multihashmap32_iterator_create ( const struct GNUNET_CONTAINER_MultiHashMap32 map)

Create an iterator for a 32-bit multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multihashmap32_iterate). Note that the iterator can not be used anymore if elements have been removed from 'map' after the creation of the iterator, or 'map' has been destroyed. Adding elements to 'map' may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Create an iterator for a 32-bit multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multihashmap_iterate()). Note that the iterator can not be used anymore if elements have been removed from 'map' after the creation of the iterator, or 'map' has been destroyed. Adding elements to 'map' may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 536 of file container_multihashmap32.c.

538{
540
542 iter->map = map;
544 iter->me = map->map[0];
545 return iter;
546}
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:63
struct MapEntry * me
Position in the bucket idx.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
const struct GNUNET_CONTAINER_MultiHashMap32 * map
Map that we are iterating over.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
union MapEntry * map
All of our buckets.

References GNUNET_new, GNUNET_CONTAINER_MultiHashMap32Iterator::map, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiHashMap32Iterator::me, GNUNET_CONTAINER_MultiHashMap32Iterator::modification_counter, and GNUNET_CONTAINER_MultiPeerMap::modification_counter.

◆ GNUNET_CONTAINER_multihashmap32_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_iterator_next ( struct GNUNET_CONTAINER_MultiHashMap32Iterator iter,
uint32_t *  key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and 'key' and 'value' are not modified. This operation is only allowed if no elements have been removed from the multihashmap since the creation of 'iter', and the map has not been destroyed. Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 564 of file container_multihashmap32.c.

568{
569 /* make sure the map has not been modified */
571
572 /* look for the next entry, skipping empty buckets */
573 while (1)
574 {
575 if (iter->idx >= iter->map->map_length)
576 return GNUNET_NO;
577 if (NULL != iter->me)
578 {
579 if (NULL != key)
580 *key = iter->me->key;
581 if (NULL != value)
582 *value = iter->me->value;
583 iter->me = iter->me->next;
584 return GNUNET_YES;
585 }
586 iter->idx += 1;
587 if (iter->idx < iter->map->map_length)
588 iter->me = iter->map->map[iter->idx];
589 }
590}
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
struct MapEntry ** map
All of our buckets.
unsigned int map_length
Length of the map array.
void * value
Value of the entry.
uint32_t key
Key for the entry.
struct MapEntry * next
If there is a hash collision, we create a linked list.

References GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiHashMap32Iterator::idx, key, MapEntry::key, GNUNET_CONTAINER_MultiHashMap32::map, GNUNET_CONTAINER_MultiHashMap32Iterator::map, GNUNET_CONTAINER_MultiHashMap32::map_length, GNUNET_CONTAINER_MultiHashMap32Iterator::me, GNUNET_CONTAINER_MultiHashMap32::modification_counter, GNUNET_CONTAINER_MultiHashMap32Iterator::modification_counter, MapEntry::next, value, and MapEntry::value.

◆ GNUNET_CONTAINER_multihashmap32_iterator_destroy()

void GNUNET_CONTAINER_multihashmap32_iterator_destroy ( struct GNUNET_CONTAINER_MultiHashMapIterator iter)

Destroy a 32-bit multihashmap iterator.

Parameters
iterthe iterator to destroy

Destroy a 32-bit multihashmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 599 of file container_multihashmap32.c.

601{
602 GNUNET_free (iter);
603}

References GNUNET_free.

◆ GNUNET_CONTAINER_heap_peek2()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_heap_peek2 ( const struct GNUNET_CONTAINER_Heap heap,
void **  element,
GNUNET_CONTAINER_HeapCostType cost 
)

Get element and cost stored at the root of heap.

Parameters
[in]heapHeap to inspect.
[out]elementRoot element is returned here.
[out]costCost of element is returned here.
Returns
GNUNET_YES if an element is returned, GNUNET_NO if the heap is empty.

Definition at line 171 of file container_heap.c.

174{
175 if (NULL == heap->root)
176 return GNUNET_NO;
177 if (NULL != element)
178 *element = heap->root->element;
179 if (NULL != cost)
180 *cost = heap->root->cost;
181 return GNUNET_YES;
182}
void * element
Our element.
GNUNET_CONTAINER_HeapCostType cost
Cost for this element.
struct GNUNET_CONTAINER_HeapNode * root
Root of the heap.

References GNUNET_CONTAINER_HeapNode::cost, GNUNET_CONTAINER_HeapNode::element, GNUNET_NO, GNUNET_YES, and GNUNET_CONTAINER_Heap::root.

Referenced by GCP_attach_path().

Here is the caller graph for this function:

◆ 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)

Definition at line 110 of file crypto_crc.c.

111{
112 const uint16_t *hdr = buf;
113
114 for (; len >= 2; len -= 2)
115 sum += *(hdr++);
116 if (len == 1)
117 sum += ntohs(*((uint8_t *)hdr) << 8);
118 return sum;
119}

References consensus-simulation::sum.

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().

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

Definition at line 123 of file crypto_crc.c.

124{
125 sum = (sum >> 16) + (sum & 0xFFFF);
126 sum += (sum >> 16);
127
128 return ~sum;
129}

References consensus-simulation::sum.

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().

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

Definition at line 221 of file crypto_symmetric.c.

229{
230 char aes_salt[salt_len + 4];
231 char twofish_salt[salt_len + 4];
232
233 GNUNET_memcpy (aes_salt, salt, salt_len);
234 GNUNET_memcpy (&aes_salt[salt_len], "AES!", 4);
235 GNUNET_memcpy (twofish_salt, salt, salt_len);
236 GNUNET_memcpy (&twofish_salt[salt_len], "FISH", 4);
238 sizeof(iv->aes_iv),
239 aes_salt,
240 salt_len + 4,
241 skey->aes_key,
242 sizeof(skey->aes_key),
243 argp);
245 sizeof(iv->twofish_iv),
246 twofish_salt,
247 salt_len + 4,
248 skey->twofish_key,
249 sizeof(skey->twofish_key),
250 argp);
251}
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calculations.
Definition: gnunet-scrypt.c:34
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:38
unsigned char twofish_key[(256/8)]
Actual key for TwoFish.
unsigned char aes_key[(256/8)]
Actual key for AES.

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

Referenced by GNUNET_CRYPTO_symmetric_derive_iv().

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 42 of file crypto_pow.c.

46{
47 /* Threads hardcoded at 1 in libsodium */
48 GNUNET_break (0 ==
49 crypto_pwhash_argon2id ((unsigned char *) result,
50 sizeof (struct GNUNET_HashCode),
51 buf,
52 buf_len,
53 (unsigned char*) salt,
54 3, /* iterations */
55 1024 * 1024, /* memory (1 MiB) */
56 crypto_pwhash_argon2id_ALG_ARGON2ID13));
57}

References GNUNET_break, result, and salt.

Referenced by check_proof_of_work(), find_proof(), GNUNET_GNSRECORD_check_pow(), and GNUNET_GNSRECORD_pow_round().

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 350 of file crypto_hash.c.

351{
352 struct GNUNET_HashContext *hc;
353
354 BENCHMARK_START (hash_context_start);
355 hc = GNUNET_new (struct GNUNET_HashContext);
356 GNUNET_assert (0 ==
357 gcry_md_open (&hc->hd,
358 GCRY_MD_SHA512,
359 0));
360 BENCHMARK_END (hash_context_start);
361 return hc;
362}
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
gcry_md_hd_t hd
Internal state of the hash function.
Definition: crypto_hash.c:345

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

Referenced by create_randomized_element_iterator(), decode_and_send(), GCCH_hash_port(), GNUNET_CRYPTO_edx25519_private_key_derive(), GNUNET_SET_element_hash(), GNUNET_SETI_element_hash(), GNUNET_SETU_element_hash(), handle_union_p2p_inquiry(), hash_addresses(), mq_init(), and setup_sender().

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 377 of file crypto_hash.c.

378{
379 struct GNUNET_HashContext *cp;
380
381 cp = GNUNET_new (struct GNUNET_HashContext);
382 GNUNET_assert (0 ==
383 gcry_md_copy (&cp->hd,
384 hc->hd));
385 return cp;
386}

References GNUNET_assert, GNUNET_new, and GNUNET_HashContext::hd.

◆ 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 366 of file crypto_hash.c.

369{
370 BENCHMARK_START (hash_context_read);
371 gcry_md_write (hc->hd, buf, size);
372 BENCHMARK_END (hash_context_read);
373}

References BENCHMARK_END, BENCHMARK_START, GNUNET_HashContext::hd, and size.

Referenced by create_randomized_element_iterator(), decode_and_send(), GCCH_hash_port(), GNUNET_CRYPTO_edx25519_private_key_derive(), GNUNET_SET_element_hash(), GNUNET_SETI_element_hash(), GNUNET_SETU_element_hash(), handle_union_p2p_inquiry(), hash_addresses(), mq_init(), and setup_sender().

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 390 of file crypto_hash.c.

392{
393 const void *res = gcry_md_read (hc->hd, 0);
394
395 BENCHMARK_START (hash_context_finish);
396
397 GNUNET_assert (NULL != res);
398 if (NULL != r_hash)
399 GNUNET_memcpy (r_hash,
400 res,
401 sizeof(struct GNUNET_HashCode));
403 BENCHMARK_END (hash_context_finish);
404}
void GNUNET_CRYPTO_hash_context_abort(struct GNUNET_HashContext *hc)
Abort hashing, do not bother calculating final result.
Definition: crypto_hash.c:408

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

Referenced by create_randomized_element_iterator(), decode_and_send(), GCCH_hash_port(), GNUNET_CRYPTO_edx25519_private_key_derive(), GNUNET_SET_element_hash(), GNUNET_SETI_element_hash(), GNUNET_SETU_element_hash(), handle_union_p2p_inquiry(), hash_addresses(), mq_init(), and setup_sender().

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 408 of file crypto_hash.c.

409{
410 gcry_md_close (hc->hd);
411 GNUNET_free (hc);
412}

References GNUNET_free, and GNUNET_HashContext::hd.

Referenced by GNUNET_CRYPTO_hash_context_finish().

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't 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 300 of file crypto_hash.c.

303{
304 static int once;
305 static gcry_md_hd_t md;
306 const unsigned char *mc;
307
308 if (! once)
309 {
310 once = 1;
311 GNUNET_assert (GPG_ERR_NO_ERROR ==
312 gcry_md_open (&md,
313 GCRY_MD_SHA512,
314 GCRY_MD_FLAG_HMAC));
315 }
316 else
317 {
318 gcry_md_reset (md);
319 }
320 GNUNET_assert (GPG_ERR_NO_ERROR ==
321 gcry_md_setkey (md, key, key_len));
322 gcry_md_write (md, plaintext, plaintext_len);
323 mc = gcry_md_read (md, GCRY_MD_SHA512);
324 GNUNET_assert (NULL != mc);
325 GNUNET_memcpy (hmac->bits, mc, sizeof(hmac->bits));
326}
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:67
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
uint32_t bits[512/8/sizeof(uint32_t)]

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

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

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 225 of file crypto_hash_file.c.

226{
228 GNUNET_free (fhc->filename);
231 gcry_md_close (fhc->md);
232 GNUNET_free (fhc);
233}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
gcry_md_hd_t md
Cumulated hash.
struct GNUNET_DISK_FileHandle * fh
File descriptor.
struct GNUNET_SCHEDULER_Task * task
Current task for hashing.
char * filename
Name of the file we are hashing.

References GNUNET_CRYPTO_FileHashContext::fh, GNUNET_CRYPTO_FileHashContext::filename, GNUNET_break, GNUNET_DISK_file_close(), GNUNET_free, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_CRYPTO_FileHashContext::md, 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().

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

◆ GNUNET_CRYPTO_hash_count_leading_zeros()

unsigned int GNUNET_CRYPTO_hash_count_leading_zeros ( const struct GNUNET_HashCode h)

Count the number of leading 0 bits in h.

Parameters
ha hash
Returns
number of leading 0 bits in h

Definition at line 177 of file crypto_hash.c.

178{
179 const unsigned long long *llp = (const unsigned long long *) h;
180 unsigned int ret = 0;
181 unsigned int i;
182
183 GNUNET_static_assert (8 == sizeof (unsigned long long));
184 GNUNET_static_assert (0 == sizeof (*h) % sizeof (unsigned long long));
185 for (i = 0; i<sizeof (*h) / sizeof (*llp); i++)
186 {
187 if (0LLU != llp[i])
188 break;
189 ret += sizeof (*llp) * 8;
190 }
191 if (ret == 8 * sizeof (*h))
192 return ret;
193 ret += __builtin_clzll (GNUNET_ntohll ((uint64_t) llp[i]));
194 return ret;
195}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define GNUNET_static_assert(cond)
Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime an...

References GNUNET_ntohll(), GNUNET_static_assert, h, and ret.

Referenced by check_proof_of_work(), find_bucket(), find_proof(), GDS_DATACACHE_handle_put(), get_matching_bits(), GNUNET_GNSRECORD_check_pow(), GNUNET_GNSRECORD_pow_round(), and select_peer().

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

◆ GNUNET_CRYPTO_hash_count_tailing_zeros()

unsigned int GNUNET_CRYPTO_hash_count_tailing_zeros ( const struct GNUNET_HashCode h)

Count the number of tailing 0 bits in h.

Parameters
ha hash
Returns
number of tailing 0 bits in h

Definition at line 199 of file crypto_hash.c.

200{
201 const unsigned long long *llp = (const unsigned long long *) h;
202 unsigned int ret = 0;
203 int i;
204
205 GNUNET_static_assert (8 == sizeof (unsigned long long));
206 GNUNET_static_assert (0 == sizeof (*h) % sizeof (unsigned long long));
207 for (i = sizeof (*h) / sizeof (*llp) - 1; i>=0; i--)
208 {
209 if (0LLU != llp[i])
210 break;
211 ret += sizeof (*llp) * 8;
212 }
213 if (ret == 8 * sizeof (*h))
214 return ret;
215 ret += __builtin_ctzll (GNUNET_ntohll ((uint64_t) llp[i]));
216 return ret;
217}

References GNUNET_ntohll(), GNUNET_static_assert, h, and ret.

Here is the call 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 38 of file crypto_kdf.c.

45{
46 /*
47 * "Finally, we point out to a particularly advantageous instantiation using
48 * HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from SHA-512 is
49 * truncated to 256 bits). This makes sense in two ways: First, the extraction part is where we need a
50 * stronger hash function due to the unconventional demand from the hash function in the extraction
51 * setting. Second, as shown in Section 6, using HMAC with a truncated output as an extractor
52 * allows to prove the security of HKDF under considerably weaker assumptions on the underlying
53 * hash function."
54 *
55 * http://eprint.iacr.org/2010/264
56 */
57 return GNUNET_CRYPTO_hkdf_gnunet_v (result, out_len, xts, xts_len, skm, skm_len, argp);
58}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_gnunet_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_hkdf.c:172

References GNUNET_CRYPTO_hkdf_gnunet_v(), and result.

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

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 87 of file crypto_kdf.c.

92{
93 gcry_error_t rc;
94 unsigned int nbits;
95 size_t rsize;
96 uint16_t ctr;
97
98 nbits = gcry_mpi_get_nbits (n);
99 /* GNUNET_assert (nbits > 512); */
100 ctr = 0;
101 while (1)
102 {
103 /* Ain't clear if n is always divisible by 8 */
104 size_t bsize = (nbits - 1) / 8 + 1;
105 uint8_t buf[bsize];
106 uint16_t ctr_nbo = htons (ctr);
107
108 rc = GNUNET_CRYPTO_kdf (buf,
109 bsize,
110 xts, xts_len,
111 skm, skm_len,
112 ctx, strlen (ctx),
113 &ctr_nbo, sizeof(ctr_nbo),
114 NULL, 0);
116 rc = gcry_mpi_scan (r,
117 GCRYMPI_FMT_USG,
118 (const unsigned char *) buf,
119 bsize,
120 &rsize);
121 GNUNET_assert (GPG_ERR_NO_ERROR == rc); /* Allocation error? */
122 GNUNET_assert (rsize == bsize);
123 gcry_mpi_clear_highbit (*r,
124 nbits);
125 GNUNET_assert (0 ==
126 gcry_mpi_test_bit (*r,
127 nbits));
128 ++ctr;
129 /* We reject this FDH if either *r > n and retry with another ctr */
130 if (0 > gcry_mpi_cmp (*r, n))
131 break;
132 gcry_mpi_release (*r);
133 }
134}
static struct GNUNET_FS_Handle * ctx
static unsigned int bsize
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.
Definition: crypto_kdf.c:62

References bsize, ctx, GNUNET_assert, GNUNET_CRYPTO_kdf(), and GNUNET_YES.

Referenced by cs_full_domain_hash(), rsa_blinding_key_derive(), and rsa_full_domain_hash().

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 228 of file crypto_ecc.c.

230{
231 char *pubkeybuf;
232 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
233 char *end;
234
235 if (keylen % 5 > 0)
236 keylen += 5 - keylen % 5;
237 keylen /= 5;
238 pubkeybuf = GNUNET_malloc (keylen + 1);
239 end =
240 GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
241 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
242 pubkeybuf,
243 keylen);
244 if (NULL == end)
245 {
246 GNUNET_free (pubkeybuf);
247 return NULL;
248 }
249 *end = '\0';
250 return pubkeybuf;
251}
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...

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

Referenced by get_ego().

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 309 of file crypto_ecc.c.

311{
312 char *privkeybuf;
313 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)) * 8;
314 char *end;
315
316 if (keylen % 5 > 0)
317 keylen += 5 - keylen % 5;
318 keylen /= 5;
319 privkeybuf = GNUNET_malloc (keylen + 1);
320 end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
321 sizeof(
323 privkeybuf,
324 keylen);
325 if (NULL == end)
326 {
327 GNUNET_free (privkeybuf);
328 return NULL;
329 }
330 *end = '\0';
331 return privkeybuf;
332}
Private ECC key encoded for transmission.

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

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 282 of file crypto_ecc.c.

284{
285 char *privkeybuf;
286 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
287 char *end;
288
289 if (keylen % 5 > 0)
290 keylen += 5 - keylen % 5;
291 keylen /= 5;
292 privkeybuf = GNUNET_malloc (keylen + 1);
293 end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
294 sizeof(
296 privkeybuf,
297 keylen);
298 if (NULL == end)
299 {
300 GNUNET_free (privkeybuf);
301 return NULL;
302 }
303 *end = '\0';
304 return privkeybuf;
305}
Private ECC key encoded for transmission.

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

Referenced by run().

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 255 of file crypto_ecc.c.

257{
258 char *pubkeybuf;
259 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
260 char *end;
261
262 if (keylen % 5 > 0)
263 keylen += 5 - keylen % 5;
264 keylen /= 5;
265 pubkeybuf = GNUNET_malloc (keylen + 1);
266 end =
267 GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
268 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
269 pubkeybuf,
270 keylen);
271 if (NULL == end)
272 {
273 GNUNET_free (pubkeybuf);
274 return NULL;
275 }
276 *end = '\0';
277 return pubkeybuf;
278}
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...

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

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

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 336 of file crypto_ecc.c.

340{
341 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
342
343 if (keylen % 5 > 0)
344 keylen += 5 - keylen % 5;
345 keylen /= 5;
346 if (enclen != keylen)
347 return GNUNET_SYSERR;
348
349 if (GNUNET_OK !=
351 enclen,
352 pub,
353 sizeof(
355 return GNUNET_SYSERR;
356 return GNUNET_OK;
357}
static OpusEncoder * enc
OPUS encoder.
enum GNUNET_GenericReturnValue 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:789

References enc, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, and pub.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_eddsa_private_key_from_string()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_private_key_from_string ( const char *  enc,
size_t  enclen,
struct GNUNET_CRYPTO_EddsaPrivateKey priv 
)

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

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 386 of file crypto_ecc.c.

390{
391 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
392
393 if (keylen % 5 > 0)
394 keylen += 5 - keylen % 5;
395 keylen /= 5;
396 if (enclen != keylen)
397 return GNUNET_SYSERR;
398
399 if (GNUNET_OK !=
401 enclen,
402 priv,
403 sizeof(
405 return GNUNET_SYSERR;
406#if CRYPTO_BUG
407 if (GNUNET_OK != check_eddsa_key (priv))
408 {
409 GNUNET_break (0);
410 return GNUNET_OK;
411 }
412#endif
413 return GNUNET_OK;
414}

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

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 361 of file crypto_ecc.c.

365{
366 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
367
368 if (keylen % 5 > 0)
369 keylen += 5 - keylen % 5;
370 keylen /= 5;
371 if (enclen != keylen)
372 return GNUNET_SYSERR;
373
374 if (GNUNET_OK !=
376 enclen,
377 pub,
378 sizeof(
380 return GNUNET_SYSERR;
381 return GNUNET_OK;
382}

References enc, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, and pub.

Referenced by conversation_string_to_value(), create_keys(), gns_string_to_value(), messenger_string_to_value(), on_identity(), run(), s2i_full(), show_peer(), and uri_loc_parse().

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 65 of file crypto_ecc_dlog.c.

67{
69 int K = ((max + (mem - 1)) / mem);
70
71 GNUNET_assert (max < INT32_MAX);
73 edc->max = max;
74 edc->mem = mem;
76 GNUNET_NO);
77 for (int i = -(int) mem; i <= (int) mem; i++)
78 {
81
83 &Ki);
84 if (0 == i) /* libsodium does not like to multiply with zero */
86 0 ==
87 crypto_core_ed25519_sub ((unsigned char *) &key,
88 (unsigned char *) &key,
89 (unsigned char *) &key));
90 else
92 0 ==
93 crypto_scalarmult_ed25519_base_noclamp ((unsigned char*) &key,
94 Ki.v));
96 "K*i: %d (mem=%u, i=%d) => %s\n",
97 K * i,
98 mem,
99 i,
100 GNUNET_i2s (&key));
103 &key,
104 (void *) (long) i + max,
106 }
107 return edc;
108}
static struct GNUNET_CRYPTO_EccDlogContext * edc
Context for DLOG operations on a curve.
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).
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_ecc_scalar_from_int(int64_t val, struct GNUNET_CRYPTO_EccScalar *r)
Create a scalar from int value.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define max(x, y)
Internal structure used to cache pre-calculated values for DLOG calculation.
struct GNUNET_CONTAINER_MultiPeerMap * map
Map mapping points (here "interpreted" as EdDSA public keys) to a "void * = long" which corresponds t...
unsigned int mem
How much memory should we use (relates to the number of entries in the map).
unsigned int max
Maximum absolute value the calculation supports.
A ECC scalar for use in point multiplications.
The identity of the host (wraps the signing key of the peer).

References edc, GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CRYPTO_ecc_scalar_from_int(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, consensus-simulation::int, key, GNUNET_CRYPTO_EccDlogContext::map, GNUNET_CRYPTO_EccDlogContext::max, max, GNUNET_CRYPTO_EccDlogContext::mem, and GNUNET_CRYPTO_EccScalar::v.

Referenced by run().

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,
const struct GNUNET_CRYPTO_EccPoint input 
)

Calculate ECC discrete logarithm for small factors.

Opposite of GNUNET_CRYPTO_ecc_dexp().

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 112 of file crypto_ecc_dlog.c.

114{
115 unsigned int K = ((edc->max + (edc->mem - 1)) / edc->mem);
116 int res;
117 struct GNUNET_CRYPTO_EccPoint g;
119 struct GNUNET_CRYPTO_EccPoint nq;
120
121 {
122 struct GNUNET_CRYPTO_EccScalar fact;
123
124 memset (&fact,
125 0,
126 sizeof (fact));
127 sodium_increment (fact.v,
128 sizeof (fact.v));
129 GNUNET_assert (0 ==
130 crypto_scalarmult_ed25519_base_noclamp (g.v,
131 fact.v));
132 }
133 /* make compiler happy: initialize q and nq, technically not needed! */
134 memset (&q,
135 0,
136 sizeof (q));
137 memset (&nq,
138 0,
139 sizeof (nq));
140 res = INT_MAX;
141 for (unsigned int i = 0; i <= edc->max / edc->mem; i++)
142 {
144 void *retp;
145
146 GNUNET_assert (sizeof (key) == crypto_scalarmult_BYTES);
147 if (0 == i)
148 {
149 memcpy (&key,
150 input,
151 sizeof (key));
152 }
153 else
154 {
155 memcpy (&key,
156 &q,
157 sizeof (key));
158 }
160 "Trying offset i=%u): %s\n",
161 i,
162 GNUNET_i2s (&key));
164 &key);
165 if (NULL != retp)
166 {
167 res = (((long) retp) - edc->max) * K - i;
168 /* we continue the loop here to make the implementation
169 "constant-time". If we do not care about this, we could just
170 'break' here and do fewer operations... */
171 }
172 if (i == edc->max / edc->mem)
173 break;
174 /* q = q + g */
175 if (0 == i)
176 {
177 GNUNET_assert (0 ==
178 crypto_core_ed25519_add (q.v,
179 input->v,
180 g.v));
181 }
182 else
183 {
184 GNUNET_assert (0 ==
185 crypto_core_ed25519_add (q.v,
186 q.v,
187 g.v));
188 }
189 }
190 return res;
191}
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
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.
Point on a curve (always for Curve25519) encoded in a format suitable for network transmission (ECDH)...
unsigned char v[256/8]
Q consists of an x- and a y-value, each mod p (256 bits), given here in affine coordinates and Ed2551...

References edc, GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, INT_MAX, key, GNUNET_CRYPTO_EccDlogContext::map, GNUNET_CRYPTO_EccDlogContext::max, GNUNET_CRYPTO_EccDlogContext::mem, q, res, GNUNET_CRYPTO_EccPoint::v, and GNUNET_CRYPTO_EccScalar::v.

Referenced by handle_bobs_cryptodata_message().

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

◆ GNUNET_CRYPTO_ecc_dexp()

void GNUNET_CRYPTO_ecc_dexp ( int  val,
struct GNUNET_CRYPTO_EccPoint r 
)

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
valvalue to encode into a point
rwhere to write the point (must be allocated)

Definition at line 210 of file crypto_ecc_dlog.c.

212{
213 struct GNUNET_CRYPTO_EccScalar fact;
214
216 &fact);
217 crypto_scalarmult_ed25519_base_noclamp (r->v,
218 fact.v);
219}

References GNUNET_CRYPTO_ecc_scalar_from_int(), GNUNET_CRYPTO_EccPoint::v, and GNUNET_CRYPTO_EccScalar::v.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_ecc_dexp_mpi()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_dexp_mpi ( const struct GNUNET_CRYPTO_EccScalar val,
struct GNUNET_CRYPTO_EccPoint r 
)

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

Parameters
val(positive) value to encode into a point
rwhere to write the point (must be allocated)
Returns
GNUNET_OK on success.

Definition at line 223 of file crypto_ecc_dlog.c.

225{
226 if (0 ==
227 crypto_scalarmult_ed25519_base_noclamp (r->v,
228 val->v))
229 return GNUNET_OK;
230 return GNUNET_SYSERR;
231}
unsigned char v[256/8]

References GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_EccPoint::v, and GNUNET_CRYPTO_EccScalar::v.

Referenced by send_alices_cryptodata_message().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_pmul_mpi()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_pmul_mpi ( const struct GNUNET_CRYPTO_EccPoint p,
const struct GNUNET_CRYPTO_EccScalar val,
struct GNUNET_CRYPTO_EccPoint r 
)

Multiply the point p on the elliptic curve by val.

Parameters
ppoint to multiply
val(positive) value to encode into a point
rwhere to write the point (must be allocated)
Returns
GNUNET_OK on success.

Definition at line 249 of file crypto_ecc_dlog.c.

252{
253 if (0 ==
254 crypto_scalarmult_ed25519_noclamp (r->v,
255 val->v,
256 p->v))
257 return GNUNET_OK;
258 return GNUNET_SYSERR;
259}
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38

References GNUNET_OK, GNUNET_SYSERR, p, GNUNET_CRYPTO_EccPoint::v, and GNUNET_CRYPTO_EccScalar::v.

Referenced by handle_alices_cryptodata_message(), and handle_bobs_cryptodata_message().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_add()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_add ( const struct GNUNET_CRYPTO_EccPoint a,
const struct GNUNET_CRYPTO_EccPoint b,
struct GNUNET_CRYPTO_EccPoint r 
)

Add two points on the elliptic curve.

Parameters
asome value
bsome value
rwhere to write the point (must be allocated)
Returns
GNUNET_OK on success.

Definition at line 235 of file crypto_ecc_dlog.c.

238{
239 if (0 ==
240 crypto_core_ed25519_add (r->v,
241 a->v,
242 b->v))
243 return GNUNET_OK;
244 return GNUNET_SYSERR;
245}

References GNUNET_OK, GNUNET_SYSERR, and GNUNET_CRYPTO_EccPoint::v.

Referenced by handle_alices_cryptodata_message(), and handle_bobs_cryptodata_message().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_rnd()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_rnd ( struct GNUNET_CRYPTO_EccPoint r,
struct GNUNET_CRYPTO_EccPoint r_inv 
)

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

Parameters
[out]rset to a random point on the curve
[out]r_invset to the additive inverse of r
Returns
GNUNET_OK on success.

Definition at line 263 of file crypto_ecc_dlog.c.

265{
267 unsigned char inv_s[crypto_scalarmult_ed25519_SCALARBYTES];
268
270 if (0 !=
271 crypto_scalarmult_ed25519_base_noclamp (r->v,
272 s.v))
273 return GNUNET_SYSERR;
274 crypto_core_ed25519_scalar_negate (inv_s,
275 s.v);
276 if (0 !=
277 crypto_scalarmult_ed25519_base_noclamp (r_inv->v,
278 inv_s))
279 return GNUNET_SYSERR;
280 return GNUNET_OK;
281}
void GNUNET_CRYPTO_ecc_random_mod_n(struct GNUNET_CRYPTO_EccScalar *r)
Generate a random value mod n.

References GNUNET_CRYPTO_ecc_random_mod_n(), GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_EccPoint::v, and GNUNET_CRYPTO_EccScalar::v.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_ecc_rnd_mpi()

void GNUNET_CRYPTO_ecc_rnd_mpi ( struct GNUNET_CRYPTO_EccScalar r,
struct GNUNET_CRYPTO_EccScalar r_neg 
)

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

Parameters
[out]rset to a random scalar on the curve
[out]r_negset to the negation of

Definition at line 285 of file crypto_ecc_dlog.c.

287{
289 crypto_core_ed25519_scalar_negate (r_neg->v,
290 r->v);
291}

References GNUNET_CRYPTO_ecc_random_mod_n(), and GNUNET_CRYPTO_EccScalar::v.

Referenced by run().

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

◆ GNUNET_CRYPTO_ecc_random_mod_n()

void GNUNET_CRYPTO_ecc_random_mod_n ( struct GNUNET_CRYPTO_EccScalar r)

Generate a random value mod n.

Parameters
[out]rrandom value mod n.

Definition at line 195 of file crypto_ecc_dlog.c.

196{
197 crypto_core_ed25519_scalar_random (r->v);
198}

References GNUNET_CRYPTO_EccScalar::v.

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecc_dlog_release()

void GNUNET_CRYPTO_ecc_dlog_release ( struct GNUNET_CRYPTO_EccDlogContext dlc)

Release precalculated values.

Parameters
dlcdlog context

Definition at line 202 of file crypto_ecc_dlog.c.

203{
206}
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.

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

Referenced by shutdown_task().

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

◆ GNUNET_CRYPTO_ecc_scalar_from_int()

void GNUNET_CRYPTO_ecc_scalar_from_int ( int64_t  val,
struct GNUNET_CRYPTO_EccScalar r 
)

Create a scalar from int value.

Parameters
valthe int value
[out]rwhere to write the salar

Definition at line 295 of file crypto_ecc_dlog.c.

297{
298 unsigned char fact[crypto_scalarmult_ed25519_SCALARBYTES];
299 uint64_t valBe;
300
301 GNUNET_assert (sizeof (*r) == sizeof (fact));
302 if (val < 0)
303 {
304 if (INT64_MIN == val)
305 valBe = GNUNET_htonll ((uint64_t) INT64_MAX);
306 else
307 valBe = GNUNET_htonll ((uint64_t) (-val));
308 }
309 else
310 {
311 valBe = GNUNET_htonll ((uint64_t) val);
312 }
313 memset (fact,
314 0,
315 sizeof (fact));
316 for (unsigned int i = 0; i < sizeof (val); i++)
317 fact[i] = ((unsigned char*) &valBe)[sizeof (val) - 1 - i];
318 if (val < 0)
319 {
320 if (INT64_MIN == val)
321 /* See above: fact is one too small, increment now that we can */
322 sodium_increment (fact,
323 sizeof (fact));
324 crypto_core_ed25519_scalar_negate (r->v,
325 fact);
326 }
327 else
328 {
329 memcpy (r,
330 fact,
331 sizeof (fact));
332 }
333}

References GNUNET_assert, GNUNET_htonll(), and GNUNET_CRYPTO_EccScalar::v.

Referenced by GNUNET_CRYPTO_ecc_dexp(), GNUNET_CRYPTO_ecc_dlog_prepare(), handle_alices_cryptodata_message(), and send_alices_cryptodata_message().

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

◆ GNUNET_CRYPTO_hpke_sk_to_x25519()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519 ( const struct GNUNET_CRYPTO_PrivateKey sk,
struct GNUNET_CRYPTO_EcdhePrivateKey x25519 
)

Convert a GNUnet identity key to a key sutiable for HPKE (X25519)

Parameters
skthe private key
x25519the new key
Returns
GNUNET_OK on success

Definition at line 973 of file crypto_hpke.c.

975{
976 switch (ntohl (sk->type))
977 {
979 memcpy (x25519->d, sk->ecdsa_key.d,
980 sizeof sk->ecdsa_key.d);
982 if (0 != crypto_sign_ed25519_sk_to_curve25519 (x25519->d,
983 sk->eddsa_key.d))
984 return GNUNET_SYSERR;
985 return GNUNET_OK;
986 default:
987 return GNUNET_SYSERR;
988 }
989 return GNUNET_SYSERR;
990
991}
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.
struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key
An ECDSA identity key.

References GNUNET_CRYPTO_EcdhePrivateKey::d, GNUNET_CRYPTO_EcdsaPrivateKey::d, GNUNET_CRYPTO_EddsaPrivateKey::d, GNUNET_CRYPTO_PrivateKey::ecdsa_key, GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_OK, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, and GNUNET_CRYPTO_PrivateKey::type.

Referenced by decrypt_message(), eddsa_priv_to_hpke_key(), and read_encrypted_message().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_pk_to_x25519()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519 ( const struct GNUNET_CRYPTO_PublicKey pk,
struct GNUNET_CRYPTO_EcdhePublicKey x25519 
)

Convert a GNUnet identity key to a key sutiable for HPKE (X25519)

Parameters
pkthe public key
x25519the new key
Returns
GNUNET_OK on success

Definition at line 951 of file crypto_hpke.c.

953{
954 switch (ntohl (pk->type))
955 {
957 memcpy (x25519->q_y, pk->ecdsa_key.q_y,
958 sizeof pk->ecdsa_key.q_y);
960 if (0 != crypto_sign_ed25519_pk_to_curve25519 (x25519->q_y,
961 pk->eddsa_key.q_y))
962 return GNUNET_SYSERR;
963 return GNUNET_OK;
964 default:
965 return GNUNET_SYSERR;
966 }
967 return GNUNET_SYSERR;
968
969}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
unsigned char q_y[256/8]
Q consists of an x- and a y-value, each mod p (256 bits), given here in affine coordinates and Ed2551...

References GNUNET_CRYPTO_PrivateKey::ecdsa_key, GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_OK, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, pk, GNUNET_CRYPTO_EcdhePublicKey::q_y, and GNUNET_CRYPTO_PrivateKey::type.

Referenced by eddsa_pub_to_hpke_key(), encrypt_message(), and write_encrypted_message().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hpke_sender_setup()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sender_setup ( const struct GNUNET_CRYPTO_EcdhePublicKey pkR,
const uint8_t *  info,
size_t  info_len,
struct GNUNET_CRYPTO_HpkeEncapsulation enc,
struct GNUNET_CRYPTO_HpkeContext ctx 
)

RFC9180 HPKE encryption.

This sets the encryption context up for a sender of encrypted messages. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be created and sent using "ctx"

Parameters
pkRthe X25519 receiver public key
infothe info context separator
info_lenlength of info in bytes
encthe encapsulation to exchange with the other party
ctxthe encryption context allocated by caller
Returns
GNUNET_OK on success

Definition at line 717 of file crypto_hpke.c.

721{
723 // skE, pkE = GenerateKeyPair()
725
729 &sk, NULL,
730 pkR, info, info_len,
731 NULL, 0,
732 NULL, 0,
733 enc,
734 ctx);
735}
#define info
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:454
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sender_setup2(enum GNUNET_CRYPTO_HpkeKem kem, enum GNUNET_CRYPTO_HpkeMode mode, struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_CRYPTO_EcdhePrivateKey *skS, const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, struct GNUNET_CRYPTO_HpkeContext *ctx)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:656
Private ECC key encoded for transmission.

References ctx, enc, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_HPKE_KEM_DH_X25519_HKDF256, GNUNET_CRYPTO_HPKE_MODE_BASE, GNUNET_CRYPTO_hpke_sender_setup2(), and info.

Referenced by GNUNET_CRYPTO_hpke_seal_oneshot().

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

◆ GNUNET_CRYPTO_hpke_sender_setup2()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sender_setup2 ( enum GNUNET_CRYPTO_HpkeKem  kem,
enum GNUNET_CRYPTO_HpkeMode  mode,
struct GNUNET_CRYPTO_EcdhePrivateKey skE,
struct GNUNET_CRYPTO_EcdhePrivateKey skS,
const struct GNUNET_CRYPTO_EcdhePublicKey pkR,
const uint8_t *  info,
size_t  info_len,
const uint8_t *  psk,
size_t  psk_len,
const uint8_t *  psk_id,
size_t  psk_id_len,
struct GNUNET_CRYPTO_HpkeEncapsulation enc,
struct GNUNET_CRYPTO_HpkeContext ctx 
)

RFC9180 HPKE encryption.

This sets the encryption context up for a sender of encrypted messages. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be created and sent using "ctx"

Parameters
kemthe HPKE KEM to use
modethe HPKE mode
skEthe X25519 ephemeral key to use as encapsulation
skRthe X25519 sender private key (may be null for non-Auth modes)
infothe info context separator
info_lenlength of info in bytes
pskthe pre-shared key (must not be set non-PSK modes)
psk_lenlength of psk in bytes
psk_idthe ID of the pre-shared key (must be set of psk is set)
psk_id_lenlength of psk_id in bytes
encthe encapsulation to exchange with the other party
ctxthe encryption context allocated by caller
Returns
GNUNET_OK on success

Definition at line 656 of file crypto_hpke.c.

667{
668 struct GNUNET_ShortHashCode shared_secret;
669
670 switch (mode)
671 {
675 {
677 &shared_secret))
678 return GNUNET_SYSERR;
679 break;
680 }
681 else if (kem ==
683 {
684 if (GNUNET_OK !=
686 enc,
687 skE,
688 &shared_secret))
689 return GNUNET_SYSERR;
690 }
691 break;
694 if (NULL == skS)
695 return GNUNET_SYSERR;
697 enc, skE,
698 &shared_secret))
699 return GNUNET_SYSERR;
700 break;
701 default:
702 return GNUNET_SYSERR;
703 }
705 mode,
706 &shared_secret,
707 info, info_len,
708 psk, psk_len,
709 psk_id, psk_id_len,
710 ctx))
711 return GNUNET_SYSERR;
712 return GNUNET_OK;
713}
enum GNUNET_GenericReturnValue key_schedule(enum GNUNET_CRYPTO_HpkeRole role, enum GNUNET_CRYPTO_HpkeMode mode, const struct GNUNET_ShortHashCode *shared_secret, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeContext *ctx)
Definition: crypto_hpke.c:571
static enum @44 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_encaps_norand(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
Deterministic variant of GNUNET_CRYPTO_hpke_kem_encaps.
Definition: crypto_hpke.c:282
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_authkem_encaps_norand(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const struct GNUNET_CRYPTO_EcdhePrivateKey *skS, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
Encapsulate authenticated key material for a X25519 public key.
Definition: crypto_hpke.c:212
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephem...
Definition: crypto_hpke.c:423
A 256-bit hashcode.

References ctx, enc, GNUNET_CRYPTO_hpke_authkem_encaps_norand(), GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand(), GNUNET_CRYPTO_HPKE_KEM_DH_X25519_HKDF256, GNUNET_CRYPTO_HPKE_KEM_DH_X25519ELLIGATOR_HKDF256, GNUNET_CRYPTO_hpke_kem_encaps_norand(), GNUNET_CRYPTO_HPKE_MODE_AUTH, GNUNET_CRYPTO_HPKE_MODE_AUTH_PSK, GNUNET_CRYPTO_HPKE_MODE_BASE, GNUNET_CRYPTO_HPKE_MODE_PSK, GNUNET_CRYPTO_HPKE_ROLE_S, GNUNET_OK, GNUNET_SYSERR, info, key_schedule(), and mode.

Referenced by GNUNET_CRYPTO_hpke_sender_setup().

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

◆ GNUNET_CRYPTO_hpke_receiver_setup2()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_receiver_setup2 ( enum GNUNET_CRYPTO_HpkeKem  kem,
enum GNUNET_CRYPTO_HpkeMode  mode,
const struct GNUNET_CRYPTO_HpkeEncapsulation enc,
const struct GNUNET_CRYPTO_EcdhePrivateKey skR,
const struct GNUNET_CRYPTO_EcdhePublicKey pkS,
const uint8_t *  info,
size_t  info_len,
const uint8_t *  psk,
size_t  psk_len,
const uint8_t *  psk_id,
size_t  psk_id_len,
struct GNUNET_CRYPTO_HpkeContext ctx 
)

RFC9180 HPKE encryption.

This sets the encryption context up for a receiver of encrypted messages. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be decrypted using "ctx"

Parameters
kemthe HPKE KEM to use
modethe HPKE mode
encthe encapsulation from the sender
skRthe X25519 receiver secret key
pkSthe X25519 sender public key (may be NULL for non-Auth modes)
infothe info context separator
info_lenlength of info in bytes
pskthe pre-shared key (must not be set non-PSK modes)
psk_lenlength of psk in bytes
psk_idthe ID of the pre-shared key (must be set of psk is set)
psk_id_lenlength of psk_id in bytes
ctxthe encryption context allocated by caller
Returns
GNUNET_OK on success

Definition at line 739 of file crypto_hpke.c.

749{
750 struct GNUNET_ShortHashCode shared_secret;
751
752 switch (mode)
753 {
757 {
759 &shared_secret))
760 return GNUNET_SYSERR;
761 }
762 else if (kem ==
764 {
766 enc,
767 &shared_secret))
768 return GNUNET_SYSERR;
769 }
770 break;
773 if (NULL == pkS)
774 return GNUNET_SYSERR;
776 enc,
777 &shared_secret))
778 return GNUNET_SYSERR;
779 break;
780 default:
781 return GNUNET_SYSERR;
782 }
784 mode,
785 &shared_secret,
786 info, info_len,
787 psk, psk_len,
788 psk_id, psk_id_len,
789 ctx))
790 return GNUNET_SYSERR;
791 return GNUNET_OK;
792}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_elligator_kem_decaps(const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh decapsulation with own private key and the representative of the received public key...
Definition: crypto_hpke.c:459
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_authkem_decaps(const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_EcdhePublicKey *pkS, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Decapsulate a key for a private X25519 key.
Definition: crypto_hpke.c:327
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_kem_decaps(const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret)
Decapsulate a key for a private X25519 key.
Definition: crypto_hpke.c:370

References ctx, enc, GNUNET_CRYPTO_hpke_authkem_decaps(), GNUNET_CRYPTO_hpke_elligator_kem_decaps(), GNUNET_CRYPTO_hpke_kem_decaps(), GNUNET_CRYPTO_HPKE_KEM_DH_X25519_HKDF256, GNUNET_CRYPTO_HPKE_KEM_DH_X25519ELLIGATOR_HKDF256, GNUNET_CRYPTO_HPKE_MODE_AUTH, GNUNET_CRYPTO_HPKE_MODE_AUTH_PSK, GNUNET_CRYPTO_HPKE_MODE_BASE, GNUNET_CRYPTO_HPKE_MODE_PSK, GNUNET_CRYPTO_HPKE_ROLE_R, GNUNET_OK, GNUNET_SYSERR, info, key_schedule(), and mode.

Referenced by GNUNET_CRYPTO_hpke_receiver_setup().

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

◆ GNUNET_CRYPTO_hpke_receiver_setup()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_receiver_setup ( const struct GNUNET_CRYPTO_HpkeEncapsulation enc,
const struct GNUNET_CRYPTO_EcdhePrivateKey skR,
const uint8_t *  info,
size_t  info_len,
struct GNUNET_CRYPTO_HpkeContext ctx 
)

RFC9180 HPKE encryption.

This sets the encryption context up for a receiver of encrypted messages. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be decrypted using "ctx"

Parameters
encthe encapsulation from the sender
skRthe X25519 receiver secret key
infothe info context separator
info_lenlength of info in bytes
ctxthe encryption context allocated by caller
Returns
GNUNET_OK on success

Definition at line 796 of file crypto_hpke.c.

801{
805 enc, skR, NULL,
806 info, info_len,
807 NULL, 0, NULL, 0, ctx);
808}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_receiver_setup2(enum GNUNET_CRYPTO_HpkeKem kem, enum GNUNET_CRYPTO_HpkeMode mode, const struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_EcdhePublicKey *pkS, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeContext *ctx)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:739

References ctx, enc, GNUNET_CRYPTO_HPKE_KEM_DH_X25519_HKDF256, GNUNET_CRYPTO_HPKE_MODE_BASE, GNUNET_CRYPTO_hpke_receiver_setup2(), and info.

Referenced by GNUNET_CRYPTO_hpke_open_oneshot().

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

◆ GNUNET_CRYPTO_hpke_seal()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal ( struct GNUNET_CRYPTO_HpkeContext ctx,
const uint8_t *  aad,
size_t  aad_len,
const uint8_t *  pt,
size_t  pt_len,
uint8_t *  ct,
unsigned long long *  ct_len 
)

RFC9180 HPKE encryption.

Encrypt messages in a context. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be decrypted using "ctx"

Parameters
ctxthe encryption context
aadaddition authenticated data to send (not encrypted)
aad_lenlength of aad in bytes
ptplaintext data to encrypt
pt_lenlength of pt in bytes
ctciphertext to send (to be allocated by caller)
ct_len[out]length of written bytes in ct. may be NULL
Returns
GNUNET_OK on success

Definition at line 842 of file crypto_hpke.c.

846{
847 uint8_t comp_nonce[GNUNET_CRYPTO_HPKE_NONCE_LEN];
848 if (ctx->role != GNUNET_CRYPTO_HPKE_ROLE_S)
849 {
851 "HPKE: Wrong role; called as receiver (%d)!\n",
852 ctx->role);
853 return GNUNET_SYSERR;
854 }
855 compute_nonce (ctx, comp_nonce);
856 crypto_aead_chacha20poly1305_ietf_encrypt (ct, ct_len_p,
857 pt, pt_len,
858 aad, aad_len,
859 NULL,
860 comp_nonce,
861 ctx->key);
862 if (GNUNET_OK != increment_seq (ctx))
863 {
865 "HPKE: Seq increment failed!\n");
866 return GNUNET_SYSERR;
867 }
868 return GNUNET_OK;
869}
static void compute_nonce(struct GNUNET_CRYPTO_HpkeContext *ctx, uint8_t *nonce)
Definition: crypto_hpke.c:825
static enum GNUNET_GenericReturnValue increment_seq(struct GNUNET_CRYPTO_HpkeContext *ctx)
Definition: crypto_hpke.c:812
#define GNUNET_CRYPTO_HPKE_NONCE_LEN

References compute_nonce(), ctx, GNUNET_CRYPTO_HPKE_NONCE_LEN, GNUNET_CRYPTO_HPKE_ROLE_S, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and increment_seq().

Referenced by GNUNET_CRYPTO_hpke_seal_oneshot().

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

◆ GNUNET_CRYPTO_hpke_seal_oneshot()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot ( const struct GNUNET_CRYPTO_EcdhePublicKey pkR,
const uint8_t *  info,
size_t  info_len,
const uint8_t *  aad,
size_t  aad_len,
const uint8_t *  pt,
size_t  pt_len,
uint8_t *  ct,
unsigned long long *  ct_len 
)

RFC9180 HPKE encryption.

Encrypt messages in a context. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be decrypted using "ctx"

Parameters
pkRthe X25519 receiver secret key
infothe info context separator
info_lenlength of info in bytes
aadaddition authenticated data to send (not encrypted)
aad_lenlength of aad in bytes
ptplaintext data to encrypt
pt_lenlength of pt in bytes
ctciphertext to send (to be allocated by caller)
ct_len[out]length of written bytes in ct. may be NULL
Returns
GNUNET_OK on success

Definition at line 899 of file crypto_hpke.c.

904{
907 uint8_t *ct_off;
908
910 ct_off = (uint8_t*) &enc[1];
912 info, info_len,
913 enc, &ctx))
914 return GNUNET_SYSERR;
916 aad, aad_len,
917 pt, pt_len,
918 ct_off,
919 ct_len_p);
920}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal(struct GNUNET_CRYPTO_HpkeContext *ctx, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len_p)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:842
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sender_setup(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, struct GNUNET_CRYPTO_HpkeContext *ctx)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:717

References ctx, enc, GNUNET_CRYPTO_hpke_seal(), GNUNET_CRYPTO_hpke_sender_setup(), GNUNET_OK, GNUNET_SYSERR, and info.

Referenced by encrypt_message(), and write_encrypted_message().

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

◆ GNUNET_CRYPTO_hpke_open()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open ( struct GNUNET_CRYPTO_HpkeContext ctx,
const uint8_t *  aad,
size_t  aad_len,
const uint8_t *  ct,
size_t  ct_len,
uint8_t *  pt,
unsigned long long *  pt_len_p 
)

RFC9180 HPKE encryption.

Decrypt messages in a context. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be decrypted using "ctx"

Parameters
ctxthe encryption context
aadaddition authenticated data to send (not encrypted)
aad_lenlength of aad in bytes
ctciphertext to decrypt
ct_lenlength of ct in bytes
ptplaintext (to be allocated by caller)
pt_lenlength of written bytes in pt. May be NULL
Returns
GNUNET_OK on success

Definition at line 873 of file crypto_hpke.c.

877{
878 uint8_t comp_nonce[GNUNET_CRYPTO_HPKE_NONCE_LEN];
879 if (ctx->role != GNUNET_CRYPTO_HPKE_ROLE_R)
880 return GNUNET_SYSERR;
881 compute_nonce (ctx, comp_nonce);
882 if (0 != crypto_aead_chacha20poly1305_ietf_decrypt (pt, pt_len,
883 NULL,
884 ct, ct_len,
885 aad, aad_len,
886 comp_nonce,
887 ctx->key))
888 {
889 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "OpenError\n");
890 return GNUNET_SYSERR;
891 }
892 if (GNUNET_OK != increment_seq (ctx))
893 return GNUNET_SYSERR;
894 return GNUNET_OK;
895}

References compute_nonce(), ctx, GNUNET_CRYPTO_HPKE_NONCE_LEN, GNUNET_CRYPTO_HPKE_ROLE_R, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and increment_seq().

Referenced by GNUNET_CRYPTO_hpke_open_oneshot().

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

◆ GNUNET_CRYPTO_hpke_open_oneshot()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot ( const struct GNUNET_CRYPTO_EcdhePrivateKey skR,
const uint8_t *  info,
size_t  info_len,
const uint8_t *  aad,
size_t  aad_len,
const uint8_t *  ct,
size_t  ct_len,
uint8_t *  pt,
unsigned long long *  pt_len 
)

RFC9180 HPKE encryption.

Decrypt messages in a context. Algorithm: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305

The encapsulation "enc" must be exchanged with the receiver. From then on, encrypted messages can be decrypted using "ctx"

Parameters
skRthe X25519 receiver secret key
infothe info context separator
info_lenlength of info in bytes
aadaddition authenticated data to send (not encrypted)
aad_lenlength of aad in bytes
ctciphertext to decrypt
ct_lenlength of ct in bytes
ptplaintext (to be allocated by caller)
pt_lenlength of written bytes in pt. May be NULL
Returns
GNUNET_OK on success

Definition at line 924 of file crypto_hpke.c.

930{
933 uint8_t *ct_off;
934
936 ct_off = (uint8_t*) &enc[1];
938 info, info_len,
939 &ctx))
940 return GNUNET_SYSERR;
942 aad, aad_len,
943 ct_off,
944 ct_len - sizeof *enc,
945 pt,
946 pt_len_p);
947}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open(struct GNUNET_CRYPTO_HpkeContext *ctx, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:873
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_receiver_setup(const struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const uint8_t *info, size_t info_len, struct GNUNET_CRYPTO_HpkeContext *ctx)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:796

References ctx, enc, GNUNET_CRYPTO_hpke_open(), GNUNET_CRYPTO_hpke_receiver_setup(), GNUNET_OK, GNUNET_SYSERR, and info.

Referenced by decrypt_message(), and read_encrypted_message().

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

◆ GNUNET_CRYPTO_eddsa_sign_raw()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_raw ( const struct GNUNET_CRYPTO_EddsaPrivateKey priv,
void *  data,
size_t  size,
struct GNUNET_CRYPTO_EddsaSignature sig 
)
Parameters
priv
data
size
sig
Returns
enum GNUNET_GenericReturnValue

Definition at line 604 of file crypto_ecc.c.

609{
610 unsigned char sk[crypto_sign_SECRETKEYBYTES];
611 unsigned char pk[crypto_sign_PUBLICKEYBYTES];
612 int res;
613
614 GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
615 res = crypto_sign_detached ((uint8_t *) sig,
616 NULL,
617 (uint8_t *) data,
618 size,
619 sk);
620 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
621}

References GNUNET_CRYPTO_EddsaPrivateKey::d, data, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, pk, res, and size.

Referenced by ego_sign_data_cb().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_sign_derived()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_derived ( const struct GNUNET_CRYPTO_EcdsaPrivateKey pkey,
const char *  label,
const char *  context,
const struct GNUNET_CRYPTO_EccSignaturePurpose purpose,
struct GNUNET_CRYPTO_EcdsaSignature sig 
)

This is a signature function for ECDSA which takes a private key, derives/blinds it and signs the message.

Parameters
pkeyoriginal private key
labellabel to use for key deriviation
contextadditional context to use for HKDF of 'h'; typically the name of the subsystem/application
purposethe signature purpose
sigthe resulting signature
Returns
GNUNET_OK on success

Definition at line 175 of file crypto_ecc_gnsrecord.c.

181{
185 label,
186 context);
188 purpose,
189 sig);
191 return res;
192}
static pa_context * context
Pulseaudio context.
struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_private_key_derive(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const char *label, const char *context)
Derive a private key from a given private key and a label.
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.
Definition: crypto_ecc.c:554
GNUNET_GenericReturnValue
Named constants for return values.

References context, GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_sign_(), GNUNET_free, key, and res.

Referenced by block_sign_ecdsa().

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

◆ GNUNET_CRYPTO_eddsa_sign_derived()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_derived ( const struct GNUNET_CRYPTO_EddsaPrivateKey pkey,
const char *  label,
const char *  context,
const struct GNUNET_CRYPTO_EccSignaturePurpose purpose,
struct GNUNET_CRYPTO_EddsaSignature sig 
)

This is a signature function for EdDSA which takes a private key and derives it using the label and context before signing.

Parameters
pkeyoriginal private key
labellabel to use for key deriviation
contextadditional context to use for HKDF of 'h'; typically the name of the subsystem/application
purposethe signature purpose
sigthe resulting signature
Returns
GNUNET_OK on success

Derive the private key

Instead of expanding the private here, we already have the secret scalar as input. Use it. Note that sk is not plain SHA512 (d). sk[0..31] contains the derived private scalar sk[0..31] = h * SHA512 (d)[0..31] sk[32..63] = SHA512 (d)[32..63]

Calculate the derived zone key zk' from the derived private scalar.

Calculate r: r = SHA512 (sk[32..63] | M) where M is our message (purpose). Note that sk[32..63] is the other half of the expansion from the original, non-derived private key "d".

Temporarily put zk into S

Reduce the scalar value r

Calculate R := r * G of the signature

Calculate hram := SHA512 (R | zk' | M)

Reduce the resulting scalar value

Calculate S := r + hram * s mod L

Definition at line 72 of file crypto_ecc_gnsrecord.c.

78{
80 crypto_hash_sha512_state hs;
81 unsigned char sk[64];
82 unsigned char r[64];
83 unsigned char hram[64];
84 unsigned char R[32];
85 unsigned char zk[32];
86 unsigned char tmp[32];
87
92 label,
93 context,
94 &priv);
95
96 crypto_hash_sha512_init (&hs);
97
106 memcpy (sk, priv.s, 64);
107
112 crypto_scalarmult_ed25519_base_noclamp (zk,
113 sk);
114
123 crypto_hash_sha512_update (&hs, sk + 32, 32);
124 crypto_hash_sha512_update (&hs, (uint8_t*) purpose, ntohl (purpose->size));
125 crypto_hash_sha512_final (&hs, r);
126
130 memcpy (sig->s, zk, 32);
131
135 unsigned char r_mod[64];
136 crypto_core_ed25519_scalar_reduce (r_mod, r);
137
141 crypto_scalarmult_ed25519_base_noclamp (R, r_mod);
142 memcpy (sig->r, R, sizeof (R));
143
148 crypto_hash_sha512_init (&hs);
149 crypto_hash_sha512_update (&hs, (uint8_t*) sig, 64);
150 crypto_hash_sha512_update (&hs, (uint8_t*) purpose,
151 ntohl (purpose->size));
152 crypto_hash_sha512_final (&hs, hram);
153
157 unsigned char hram_mod[64];
158 crypto_core_ed25519_scalar_reduce (hram_mod, hram);
159
164 crypto_core_ed25519_scalar_mul (tmp, hram_mod, sk);
165 crypto_core_ed25519_scalar_add (sig->s, tmp, r_mod);
166
167 sodium_memzero (sk, sizeof (sk));
168 sodium_memzero (r, sizeof (r));
169 sodium_memzero (r_mod, sizeof (r_mod));
170 return GNUNET_OK;
171}
static char * pkey
Public key of the zone to look in, in ASCII.
void GNUNET_CRYPTO_eddsa_private_key_derive(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPrivateScalar *result)
Derive a private scalar from a given private key and a label.
Private ECC scalar encoded for transmission.
unsigned char s[256/8]
S value.
unsigned char r[256/8]
R value.

References context, GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_OK, pkey, GNUNET_CRYPTO_EddsaSignature::r, GNUNET_CRYPTO_EddsaSignature::s, GNUNET_CRYPTO_EddsaPrivateScalar::s, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by block_sign_eddsa().

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

◆ GNUNET_CRYPTO_eddsa_key_get_public_from_scalar()

void GNUNET_CRYPTO_eddsa_key_get_public_from_scalar ( const struct GNUNET_CRYPTO_EddsaPrivateScalar s,
struct GNUNET_CRYPTO_EddsaPublicKey pkey 
)

Extract the public key of the given private scalar.

Parameters
sthe private scalar
pkeythe resulting public key

Calculate the derived zone key zk' from the derived private scalar.

Definition at line 437 of file crypto_ecc_gnsrecord.c.

440{
441 unsigned char sk[32];
442
443 memcpy (sk, priv->s, 32);
444
449 crypto_scalarmult_ed25519_base_noclamp (pkey->q_y,
450 sk);
451}

References pkey, and GNUNET_CRYPTO_EddsaPrivateScalar::s.

◆ 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 79 of file crypto_mpi.c.

82{
83 size_t rsize;
84 int rc;
85
86 if (gcry_mpi_get_flag (val, GCRYMPI_FLAG_OPAQUE))
87 {
88 /* Store opaque MPIs left aligned into the buffer. */
89 unsigned int nbits;
90 const void *p;
91
92 p = gcry_mpi_get_opaque (val, &nbits);
94 rsize = (nbits + 7) / 8;
95 if (rsize > size)
96 rsize = size;
97 GNUNET_memcpy (buf, p, rsize);
98 if (rsize < size)
99 memset (buf + rsize, 0, size - rsize);
100 }
101 else
102 {
103 /* Store regular MPIs as unsigned integers right aligned into
104 the buffer. */
105 rsize = size;
106 if (0 !=
107 (rc = gcry_mpi_print (GCRYMPI_FMT_USG,
108 buf,
109 rsize, &rsize,
110 val)))
111 {
113 "gcry_mpi_print",
114 rc);
115 GNUNET_assert (0);
116 }
117 adjust (buf, rsize, size);
118 }
119}
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Definition: crypto_mpi.c:40
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:55

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

Referenced by cs_full_domain_hash(), decrypt_conclude(), encrypt_fair(), GNUNET_CRYPTO_ecdsa_key_get_anonymous(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_ecdsa_sign_(), GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_CRYPTO_eddsa_public_key_derive(), 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().

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 132 of file crypto_mpi.c.

135{
136 int rc;
137
138 if (0 != (rc = gcry_mpi_scan (result,
139 GCRYMPI_FMT_USG,
140 data, size, &size)))
141 {
143 "gcry_mpi_scan",
144 rc);
145 GNUNET_assert (0);
146 }
147}

References data, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, LOG_GCRY, result, and size.

Referenced by cs_full_domain_hash(), decrypt_conclude(), decrypt_new_element(), encrypt_fair(), get_fair_encryption_challenge(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_CRYPTO_eddsa_public_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().

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 40 of file crypto_paillier.c.

44{
45 gcry_mpi_t p;
46 gcry_mpi_t q;
47 gcry_mpi_t phi;
48 gcry_mpi_t mu;
49 gcry_mpi_t n;
50
51 /* Generate two distinct primes. The probability that the loop body
52 is executed more than once is very very low... */
53 p = NULL;
54 q = NULL;
55 do
56 {
57 if (NULL != p)
58 gcry_mpi_release (p);
59 if (NULL != q)
60 gcry_mpi_release (q);
61 GNUNET_assert (0 ==
62 gcry_prime_generate (&p,
64 0, NULL, NULL, NULL,
65 GCRY_STRONG_RANDOM, 0));
66 GNUNET_assert (0 ==
67 gcry_prime_generate (&q,
69 0, NULL, NULL, NULL,
70 GCRY_STRONG_RANDOM, 0));
71 }
72 while (0 == gcry_mpi_cmp (p, q));
73 /* n = p * q */
74 GNUNET_assert (NULL != (n = gcry_mpi_new (0)));
75 gcry_mpi_mul (n,
76 p,
77 q);
79 sizeof(struct
81 n);
82
83 /* compute phi(n) = (p-1)(q-1) */
84 GNUNET_assert (NULL != (phi = gcry_mpi_new (0)));
85 gcry_mpi_sub_ui (p, p, 1);
86 gcry_mpi_sub_ui (q, q, 1);
87 gcry_mpi_mul (phi, p, q);
88 gcry_mpi_release (p);
89 gcry_mpi_release (q);
90
91 /* lambda equals phi(n) in the simplified key generation */
94 phi);
95 /* mu = phi^{-1} mod n, as we use g = n + 1 */
96 GNUNET_assert (NULL != (mu = gcry_mpi_new (0)));
97 GNUNET_assert (0 != gcry_mpi_invm (mu,
98 phi,
99 n));
100 gcry_mpi_release (phi);
101 gcry_mpi_release (n);
104 mu);
105 gcry_mpi_release (mu);
106}
#define GNUNET_CRYPTO_PAILLIER_BITS
Size of paillier plain texts and public keys.
void GNUNET_CRYPTO_mpi_print_unsigned(void *buf, size_t size, gcry_mpi_t val)
Output the given MPI value to the given buffer in network byte order.
Definition: crypto_mpi.c:79
unsigned char mu[2048/8]
Mu-component of the private key.
unsigned char lambda[2048/8]
Lambda-component of the private key.

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().

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 221 of file crypto_paillier.c.

227{
228 int possible_opts;
229 gcry_mpi_t n_square;
230 gcry_mpi_t r;
231 gcry_mpi_t rn;
232 gcry_mpi_t g;
233 gcry_mpi_t gm;
234 gcry_mpi_t c;
235 gcry_mpi_t n;
236 gcry_mpi_t max_num;
237 unsigned int highbit;
238
239 /* set max_num = 2^{GNUNET_CRYPTO_PAILLIER_BITS}, the largest
240 number we can have as a result */
241 GNUNET_assert (NULL != (max_num = gcry_mpi_set_ui (NULL, 1)));
242 gcry_mpi_mul_2exp (max_num,
243 max_num,
245
246 /* Determine how many operations we could allow, assuming the other
247 number has the same length (or is smaller), by counting the
248 number of possible operations. We essentially divide max_num by
249 2 until the result is no longer larger than 'm', incrementing the
250 maximum number of operations in each round, starting at -2 */for (possible_opts = -2; gcry_mpi_cmp (max_num, m) > 0; possible_opts++)
251 gcry_mpi_div (max_num,
252 NULL,
253 max_num,
254 GCRYMPI_CONST_TWO,
255 0);
256 gcry_mpi_release (max_num);
257
258 if (possible_opts < 1)
259 possible_opts = 0;
260 /* Enforce soft-cap by caller */
261 possible_opts = GNUNET_MIN (desired_ops, possible_opts);
262 ciphertext->remaining_ops = htonl (possible_opts);
263
265 public_key,
266 sizeof(struct
268
269 /* check public key for number of bits, bail out if key is all zeros */
270 highbit = GNUNET_CRYPTO_PAILLIER_BITS - 1;
271 while ((! gcry_mpi_test_bit (n, highbit)) &&
272 (0 != highbit))
273 highbit--;
274 if (0 == highbit)
275 {
276 /* invalid public key */
277 GNUNET_break_op (0);
278 gcry_mpi_release (n);
279 return GNUNET_SYSERR;
280 }
281
282 /* generate r < n (without bias) */
283 GNUNET_assert (NULL != (r = gcry_mpi_new (0)));
284 do
285 {
286 gcry_mpi_randomize (r, highbit + 1, GCRY_STRONG_RANDOM);
287 }
288 while (gcry_mpi_cmp (r, n) >= 0);
289
290 /* g = n + 1 */
291 GNUNET_assert (0 != (g = gcry_mpi_new (0)));
292 gcry_mpi_add_ui (g, n, 1);
293
294 /* n_square = n^2 */
295 GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
296 gcry_mpi_mul (n_square,
297 n,
298 n);
299
300 /* gm = g^m mod n^2 */
301 GNUNET_assert (0 != (gm = gcry_mpi_new (0)));
302 gcry_mpi_powm (gm, g, m, n_square);
303 gcry_mpi_release (g);
304
305 /* rn <- r^n mod n^2 */
306 GNUNET_assert (0 != (rn = gcry_mpi_new (0)));
307 gcry_mpi_powm (rn, r, n, n_square);
308 gcry_mpi_release (r);
309 gcry_mpi_release (n);
310
311 /* c <- rn * gm mod n^2 */
312 GNUNET_assert (0 != (c = gcry_mpi_new (0)));
313 gcry_mpi_mulm (c, rn, gm, n_square);
314 gcry_mpi_release (n_square);
315 gcry_mpi_release (gm);
316 gcry_mpi_release (rn);
317
319 sizeof(ciphertext->bits),
320 c);
321 gcry_mpi_release (c);
322
323 return possible_opts;
324}
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:132
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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.

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, m, and GNUNET_CRYPTO_PaillierCiphertext::remaining_ops.

Referenced by compute_service_response(), and send_alices_cryptodata_message().

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_key.

Definition at line 328 of file crypto_paillier.c.

335{
336 gcry_mpi_t mu;
337 gcry_mpi_t lambda;
338 gcry_mpi_t n;
339 gcry_mpi_t n_square;
340 gcry_mpi_t c;
341 gcry_mpi_t cmu;
342 gcry_mpi_t cmum1;
343 gcry_mpi_t mod;
344
346 private_key->lambda,
347 sizeof(private_key->lambda));
349 private_key->mu,
350 sizeof(private_key->mu));
352 public_key,
353 sizeof(struct
356 ciphertext->bits,
357 sizeof(ciphertext->bits));
358
359 /* n_square = n * n */
360 GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
361 gcry_mpi_mul (n_square, n, n);
362
363 /* cmu = c^lambda mod n^2 */
364 GNUNET_assert (0 != (cmu = gcry_mpi_new (0)));
365 gcry_mpi_powm (cmu,
366 c,
367 lambda,
368 n_square);
369 gcry_mpi_release (n_square);
370 gcry_mpi_release (lambda);
371 gcry_mpi_release (c);
372
373 /* cmum1 = cmu - 1 */
374 GNUNET_assert (0 != (cmum1 = gcry_mpi_new (0)));
375 gcry_mpi_sub_ui (cmum1, cmu, 1);
376 gcry_mpi_release (cmu);
377
378 /* mod = cmum1 / n (mod n) */
379 GNUNET_assert (0 != (mod = gcry_mpi_new (0)));
380 gcry_mpi_div (mod, NULL, cmum1, n, 0);
381 gcry_mpi_release (cmum1);
382
383 /* m = mod * mu mod n */
384 gcry_mpi_mulm (m, mod, mu, n);
385 gcry_mpi_release (mod);
386 gcry_mpi_release (mu);
387 gcry_mpi_release (n);
388}

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

Referenced by compute_scalar_product(), and keygen_round2_new_element().

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 c1 and c2.

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 392 of file crypto_paillier.c.

399{
400 gcry_mpi_t a;
401 gcry_mpi_t b;
402 gcry_mpi_t c;
403 gcry_mpi_t n;
404 gcry_mpi_t n_square;
405 int32_t o1;
406 int32_t o2;
407
408 o1 = (int32_t) ntohl (c1->remaining_ops);
409 o2 = (int32_t) ntohl (c2->remaining_ops);
410 if ((0 >= o1) || (0 >= o2))
411 {
412 GNUNET_break_op (0);
413 return GNUNET_SYSERR;
414 }
415
417 c1->bits,
418 sizeof(c1->bits));
420 c2->bits,
421 sizeof(c2->bits));
423 public_key,
424 sizeof(struct
426
427 /* n_square = n * n */
428 GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
429 gcry_mpi_mul (n_square, n, n);
430 gcry_mpi_release (n);
431
432 /* c = a * b mod n_square */
433 GNUNET_assert (0 != (c = gcry_mpi_new (0)));
434 gcry_mpi_mulm (c, a, b, n_square);
435 gcry_mpi_release (n_square);
436 gcry_mpi_release (a);
437 gcry_mpi_release (b);
438
439 result->remaining_ops = htonl (GNUNET_MIN (o1, o2) - 1);
441 sizeof(result->bits),
442 c);
443 gcry_mpi_release (c);
444 return ntohl (result->remaining_ops);
445}

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

Referenced by compute_service_response().

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 455 of file crypto_paillier.c.

457{
458 GNUNET_assert (NULL != c);
459 return ntohl (c->remaining_ops);
460}

References GNUNET_assert, and GNUNET_CRYPTO_PaillierCiphertext::remaining_ops.

◆ 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 (e.g. 2048)
Returns
fresh private key

Definition at line 144 of file crypto_rsa.c.

145{
147 gcry_sexp_t s_key;
148 gcry_sexp_t s_keyparam;
149
150 BENCHMARK_START (rsa_private_key_create);
151
152 GNUNET_assert (0 ==
153 gcry_sexp_build (&s_keyparam,
154 NULL,
155 "(genkey(rsa(nbits %d)))",
156 len));
157 GNUNET_assert (0 ==
158 gcry_pk_genkey (&s_key,
159 s_keyparam));
160 gcry_sexp_release (s_keyparam);
161#if EXTRA_CHECKS
162 GNUNET_assert (0 ==
163 gcry_pk_testkey (s_key));
164#endif
166 ret->sexp = s_key;
167 BENCHMARK_END (rsa_private_key_create);
168 return ret;
169}
The private information of an RSA key pair.
Definition: crypto_rsa.c:41

References BENCHMARK_END, BENCHMARK_START, GNUNET_assert, GNUNET_new, and ret.

Referenced by GNUNET_CRYPTO_blind_sign_keys_create_va(), and output_vectors().

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 173 of file crypto_rsa.c.

174{
175 gcry_sexp_release (key->sexp);
177}

References GNUNET_free, and key.

Referenced by checkvec(), GNUNET_CRYPTO_blind_sign_priv_decref(), GNUNET_CRYPTO_rsa_private_key_decode(), and output_vectors().

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 181 of file crypto_rsa.c.

184{
185 size_t n;
186 char *b;
187
188 n = gcry_sexp_sprint (key->sexp,
189 GCRYSEXP_FMT_DEFAULT,
190 NULL,
191 0);
192 b = GNUNET_malloc (n);
193 GNUNET_assert ((n - 1) == /* since the last byte is \0 */
194 gcry_sexp_sprint (key->sexp,
195 GCRYSEXP_FMT_DEFAULT,
196 b,
197 n));
198 *buffer = b;
199 return n;
200}

References GNUNET_assert, GNUNET_malloc, and key.

Referenced by GNUNET_CRYPTO_rsa_private_key_cmp(), output_vectors(), and qconv_blind_sign_priv().

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 204 of file crypto_rsa.c.

206{
208
210 if (0 !=
211 gcry_sexp_new (&key->sexp,
212 buf,
213 buf_size,
214 0))
215 {
217 "Decoded private key is not valid\n");
219 return NULL;
220 }
221 if (0 != gcry_pk_testkey (key->sexp))
222 {
224 "Decoded private key is not valid\n");
226 return NULL;
227 }
228 return key;
229}
#define LOG(kind,...)
Definition: crypto_rsa.c:34
void GNUNET_CRYPTO_rsa_private_key_free(struct GNUNET_CRYPTO_RsaPrivateKey *key)
Free memory occupied by the private key.
Definition: crypto_rsa.c:173
@ GNUNET_ERROR_TYPE_WARNING

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

Referenced by checkvec(), and extract_blind_sign_priv().

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 1248 of file crypto_rsa.c.

1250{
1251 struct GNUNET_CRYPTO_RsaPrivateKey *dup;
1252 gcry_sexp_t dup_sexp;
1253 size_t erroff;
1254
1255 /* check if we really are exporting a private key */
1256 dup_sexp = gcry_sexp_find_token (key->sexp, "private-key", 0);
1257 GNUNET_assert (NULL != dup_sexp);
1258 gcry_sexp_release (dup_sexp);
1259 /* copy the sexp */
1260 GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp));
1262 dup->sexp = dup_sexp;
1263 return dup;
1264}
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA private key.
Definition: crypto_rsa.c:45

References GNUNET_assert, GNUNET_new, key, and GNUNET_CRYPTO_RsaPrivateKey::sexp.

◆ 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 233 of file crypto_rsa.c.

235{
237 gcry_mpi_t ne[2];
238 int rc;
239 gcry_sexp_t result;
240
241 BENCHMARK_START (rsa_private_key_get_public);
242
243 rc = key_from_sexp (ne, priv->sexp, "public-key", "ne");
244 if (0 != rc)
245 rc = key_from_sexp (ne, priv->sexp, "private-key", "ne");
246 if (0 != rc)
247 rc = key_from_sexp (ne, priv->sexp, "rsa", "ne");
248 if (0 != rc)
249 {
250 GNUNET_break_op (0);
251 return NULL;
252 }
253 rc = gcry_sexp_build (&result,
254 NULL,
255 "(public-key(rsa(n %m)(e %m)))",
256 ne[0],
257 ne[1]);
258 gcry_mpi_release (ne[0]);
259 gcry_mpi_release (ne[1]);
261 pub->sexp = result;
262 BENCHMARK_END (rsa_private_key_get_public);
263 return pub;
264}
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:95
The public information of an RSA key pair.
Definition: crypto_rsa.c:53

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

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

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 407 of file crypto_rsa.c.

409{
410 void *buf;
411 size_t buf_size;
412
414 &buf);
416 buf_size,
417 hc);
418 GNUNET_free (buf);
419}
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:325

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

Referenced by GNUNET_CRYPTO_blind_sign_keys_create_va().

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

◆ GNUNET_CRYPTO_rsa_public_key_check()

bool GNUNET_CRYPTO_rsa_public_key_check ( const struct GNUNET_CRYPTO_RsaPublicKey key)

Check if key is well-formed.

Returns
true if key is well-formed.

Definition at line 301 of file crypto_rsa.c.

303{
304 gcry_mpi_t ne[2];
305 int ret;
306
307 ret = key_from_sexp (ne,
308 key->sexp,
309 "public-key",
310 "ne");
311 if (0 != ret)
312 ret = key_from_sexp (ne,
313 key->sexp,
314 "rsa",
315 "ne");
316 if (0 != ret)
317 return false;
318 gcry_mpi_release (ne[0]);
319 gcry_mpi_release (ne[1]);
320 return true;
321}

References key, key_from_sexp(), and ret.

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 680 of file crypto_rsa.c.

681{
682 gcry_mpi_t n;
683 unsigned int rval;
684
685 if (0 != key_from_sexp (&n, key->sexp, "rsa", "n"))
686 { /* Not an RSA public key */
687 GNUNET_break (0);
688 return 0;
689 }
690 rval = gcry_mpi_get_nbits (n);
691 gcry_mpi_release (n);
692 return rval;
693}

References GNUNET_break, key, and key_from_sexp().

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 268 of file crypto_rsa.c.

269{
270 gcry_sexp_release (key->sexp);
272}

References GNUNET_free, and key.

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

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 325 of file crypto_rsa.c.

328{
329 gcry_mpi_t ne[2];
330 size_t n_size;
331 size_t e_size;
332 size_t rsize;
333 size_t buf_size;
334 char *buf;
336 int ret;
337
338 ret = key_from_sexp (ne,
339 key->sexp,
340 "public-key",
341 "ne");
342 if (0 != ret)
343 ret = key_from_sexp (ne,
344 key->sexp,
345 "rsa",
346 "ne");
347 if (0 != ret)
348 {
349 GNUNET_break (0);
350 *buffer = NULL;
351 return 0;
352 }
353 gcry_mpi_print (GCRYMPI_FMT_USG,
354 NULL,
355 0,
356 &n_size,
357 ne[0]);
358 gcry_mpi_print (GCRYMPI_FMT_USG,
359 NULL,
360 0,
361 &e_size,
362 ne[1]);
363 if ( (e_size > UINT16_MAX) ||
364 (n_size > UINT16_MAX) )
365 {
366 GNUNET_break (0);
367 if (NULL != buffer)
368 *buffer = NULL;
369 gcry_mpi_release (ne[0]);
370 gcry_mpi_release (ne[1]);
371 return 0;
372 }
373 buf_size = n_size + e_size + sizeof (hdr);
374 if (NULL == buffer)
375 {
376 gcry_mpi_release (ne[0]);
377 gcry_mpi_release (ne[1]);
378 return buf_size;
379 }
380 buf = GNUNET_malloc (buf_size);
381 hdr.modulus_length = htons ((uint16_t) n_size);
382 hdr.public_exponent_length = htons ((uint16_t) e_size);
383 memcpy (buf,
384 &hdr,
385 sizeof (hdr));
386 GNUNET_assert (0 ==
387 gcry_mpi_print (GCRYMPI_FMT_USG,
388 (unsigned char *) &buf[sizeof (hdr)],
389 n_size,
390 &rsize,
391 ne[0]));
392
393 GNUNET_assert (0 ==
394 gcry_mpi_print (GCRYMPI_FMT_USG,
395 (unsigned char *) &buf[sizeof (hdr) + n_size],
396 e_size,
397 &rsize,
398 ne[1]));
399 *buffer = buf;
400 gcry_mpi_release (ne[0]);
401 gcry_mpi_release (ne[1]);
402 return buf_size;
403}
Format of the header of a serialized RSA public key.
Definition: crypto_rsa.c:281

References GNUNET_assert, GNUNET_break, GNUNET_malloc, key, key_from_sexp(), GNUNET_CRYPTO_RsaPublicKeyHeaderP::modulus_length, GNUNET_CRYPTO_RsaPublicKeyHeaderP::public_exponent_length, and ret.

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

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 423 of file crypto_rsa.c.

425{
428 size_t e_size;
429 size_t n_size;
430 gcry_mpi_t n;
431 gcry_mpi_t e;
432 gcry_sexp_t data;
433
434 if (len < sizeof (hdr))
435 {
436 GNUNET_break_op (0);
437 return NULL;
438 }
439 memcpy (&hdr, buf, sizeof (hdr));
440 n_size = ntohs (hdr.modulus_length);
441 e_size = ntohs (hdr.public_exponent_length);
442 if (len != sizeof (hdr) + e_size + n_size)
443 {
444 GNUNET_break_op (0);
445 return NULL;
446 }
447 if (0 !=
448 gcry_mpi_scan (&n,
449 GCRYMPI_FMT_USG,
450 &buf[sizeof (hdr)],
451 n_size,
452 NULL))
453 {
454 GNUNET_break_op (0);
455 return NULL;
456 }
457 if (0 !=
458 gcry_mpi_scan (&e,
459 GCRYMPI_FMT_USG,
460 &buf[sizeof (hdr) + n_size],
461 e_size,
462 NULL))
463 {
464 GNUNET_break_op (0);
465 gcry_mpi_release (n);
466 return NULL;
467 }
468
469 if (0 !=
470 gcry_sexp_build (&data,
471 NULL,
472 "(public-key(rsa(n %m)(e %m)))",
473 n,
474 e))
475 {
476 GNUNET_break (0);
477 gcry_mpi_release (n);
478 gcry_mpi_release (e);
479 return NULL;
480 }
481 gcry_mpi_release (n);
482 gcry_mpi_release (e);
484 key->sexp = data;
485 return key;
486}

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

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

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 1099 of file crypto_rsa.c.

1100{
1101 struct GNUNET_CRYPTO_RsaPublicKey *dup;
1102 gcry_sexp_t dup_sexp;
1103 size_t erroff;
1104
1105 /* check if we really are exporting a public key */
1106 dup_sexp = gcry_sexp_find_token (key->sexp, "public-key", 0);
1107 GNUNET_assert (NULL != dup_sexp);
1108 gcry_sexp_release (dup_sexp);
1109 /* copy the sexp */
1110 GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp));
1112 dup->sexp = dup_sexp;
1113 return dup;
1114}
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA public key.
Definition: crypto_rsa.c:57

References GNUNET_assert, GNUNET_new, key, and GNUNET_CRYPTO_RsaPublicKey::sexp.

◆ 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 602 of file crypto_rsa.c.

604{
605 void *b1;
606 void *b2;
607 size_t z1;
608 size_t z2;
609 int ret;
610
612 &b1);
614 &b2);
615 if (z1 != z2)
616 ret = 1;
617 else
618 ret = memcmp (b1,
619 b2,
620 z1);
621 GNUNET_free (b1);
622 GNUNET_free (b2);
623 return ret;
624}
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:1023

References GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, and ret.

Referenced by GNUNET_CRYPTO_blind_sig_cmp(), and GNUNET_CRYPTO_ub_sig_cmp().

Here is the call graph for this function:
Here is the caller 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 654 of file crypto_rsa.c.

656{
657 void *b1;
658 void *b2;
659 size_t z1;
660 size_t z2;
661 int ret;
662
664 &b1);
666 &b2);
667 if (z1 != z2)
668 ret = 1;
669 else
670 ret = memcmp (b1,
671 b2,
672 z1);
673 GNUNET_free (b1);
674 GNUNET_free (b2);
675 return ret;
676}
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:181

References GNUNET_CRYPTO_rsa_private_key_encode(), GNUNET_free, and ret.

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 628 of file crypto_rsa.c.

630{
631 void *b1;
632 void *b2;
633 size_t z1;
634 size_t z2;
635 int ret;
636
638 &b1);
640 &b2);
641 if (z1 != z2)
642 ret = 1;
643 else
644 ret = memcmp (b1,
645 b2,
646 z1);
647 GNUNET_free (b1);
648 GNUNET_free (b2);
649 return ret;
650}

References GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, and ret.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_blind()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_blind ( const void *  message,
size_t  message_size,
const struct GNUNET_CRYPTO_RsaBlindingKeySecret bks,
struct GNUNET_CRYPTO_RsaPublicKey pkey,
struct GNUNET_CRYPTO_RsaBlindedMessage bm 
)

Blinds the given message with the given blinding key.

Parameters
messagethe message to sign
message_sizenumber of bytes in message
bksthe blinding key
pkeythe public key of the signer
[out]bmset to the blinded message
Returns
GNUNET_YES if successful, GNUNET_NO if RSA key is malicious

Definition at line 807 of file crypto_rsa.c.

812{
813 struct RsaBlindingKey *bkey;
814 gcry_mpi_t data;
815 gcry_mpi_t ne[2];
816 gcry_mpi_t r_e;
817 gcry_mpi_t data_r_e;
818 int ret;
819
820 BENCHMARK_START (rsa_blind);
821 ret = key_from_sexp (ne,
822 pkey->sexp,
823 "public-key",
824 "ne");
825 if (0 != ret)
826 ret = key_from_sexp (ne,
827 pkey->sexp,
828 "rsa",
829 "ne");
830 if (0 != ret)
831 {
832 GNUNET_break (0);
833 bm->blinded_msg = NULL;
834 bm->blinded_msg_size = 0;
835 BENCHMARK_END (rsa_blind);
836 return GNUNET_NO;
837 }
838
840 message,
841 message_size);
842 if (NULL == data)
843 goto rsa_gcd_validate_failure;
845 bks);
846 if (NULL == bkey)
847 {
848 gcry_mpi_release (data);
849 goto rsa_gcd_validate_failure;
850 }
851 r_e = gcry_mpi_new (0);
852 gcry_mpi_powm (r_e,
853 bkey->r,
854 ne[1],
855 ne[0]);
856 data_r_e = gcry_mpi_new (0);
857 gcry_mpi_mulm (data_r_e,
858 data,
859 r_e,
860 ne[0]);
861 gcry_mpi_release (data);
862 gcry_mpi_release (ne[0]);
863 gcry_mpi_release (ne[1]);
864 gcry_mpi_release (r_e);
866
868 = numeric_mpi_alloc_n_print (data_r_e,
869 (char **) &bm->blinded_msg);
870 gcry_mpi_release (data_r_e);
871
872 BENCHMARK_END (rsa_blind);
873 return GNUNET_YES;
874
875rsa_gcd_validate_failure:
876 /* We know the RSA key is malicious here, so warn the wallet. */
877 /* GNUNET_break_op (0); */
878 gcry_mpi_release (ne[0]);
879 gcry_mpi_release (ne[1]);
880 bm->blinded_msg = NULL;
881 bm->blinded_msg_size = 0;
882 BENCHMARK_END (rsa_blind);
883 return GNUNET_NO;
884}
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:522
static void rsa_blinding_key_free(struct RsaBlindingKey *bkey)
Destroy a blinding key.
Definition: crypto_rsa.c:702
static gcry_mpi_t rsa_full_domain_hash(const struct GNUNET_CRYPTO_RsaPublicKey *pkey, const void *message, size_t message_size)
Computes a full domain hash seeded by the given public key.
Definition: crypto_rsa.c:755
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:717
size_t blinded_msg_size
Size of the blinded_msg to be signed.
void * blinded_msg
Blinded message to be signed Note: is malloc()'ed!
RSA blinding key.
Definition: crypto_rsa.c:77
gcry_mpi_t r
Random value used for blinding.
Definition: crypto_rsa.c:81

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg, GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg_size, data, GNUNET_break, GNUNET_NO, GNUNET_YES, key_from_sexp(), numeric_mpi_alloc_n_print(), pkey, RsaBlindingKey::r, ret, rsa_blinding_key_derive(), rsa_blinding_key_free(), and rsa_full_domain_hash().

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

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 struct GNUNET_CRYPTO_RsaBlindedMessage bm 
)

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

Parameters
keyprivate key to use for the signing
bmthe (blinded) message to sign
Returns
NULL on error, signature on success

Definition at line 970 of file crypto_rsa.c.

972{
973 gcry_mpi_t v = NULL;
974 struct GNUNET_CRYPTO_RsaSignature *sig;
975
976 BENCHMARK_START (rsa_sign_blinded);
977 GNUNET_assert (0 ==
978 gcry_mpi_scan (&v,
979 GCRYMPI_FMT_USG,
980 bm->blinded_msg,
982 NULL));
983 sig = rsa_sign_mpi (key,
984 v);
985 gcry_mpi_release (v);
986 BENCHMARK_END (rsa_sign_blinded);
987 return sig;
988}
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:915
an RSA signature
Definition: crypto_rsa.c:65

References BENCHMARK_END, BENCHMARK_START, GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg, GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg_size, GNUNET_assert, key, and rsa_sign_mpi().

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

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 void *  message,
size_t  message_size 
)

Create and sign a full domain hash of a message.

Parameters
keyprivate key to use for the signing
messagethe message to sign
message_sizenumber of bytes in message
Returns
NULL on error, including a malicious RSA key, signature on success

Definition at line 992 of file crypto_rsa.c.

995{
997 gcry_mpi_t v = NULL;
998 struct GNUNET_CRYPTO_RsaSignature *sig;
999
1002 message,
1003 message_size);
1005 if (NULL == v) /* rsa_gcd_validate failed meaning */
1006 return NULL; /* our *own* RSA key is malicious. */
1007
1008 sig = rsa_sign_mpi (key, v);
1009 gcry_mpi_release (v);
1010 return sig;
1011}
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268
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:233

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

Here is the call graph for this function:

◆ GNUNET_CRYPTO_rsa_blinded_message_free()

void GNUNET_CRYPTO_rsa_blinded_message_free ( struct GNUNET_CRYPTO_RsaBlindedMessage bm)

Free memory occupied by blinded message.

Only frees contents, not bm itself.

Parameters
[in]bmmemory to free

Definition at line 799 of file crypto_rsa.c.

801{
803}

References GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg, and GNUNET_free.

Referenced by checkvec(), and output_vectors().

Here is the caller 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
[in]sigmemory to free

Definition at line 1015 of file crypto_rsa.c.

1016{
1017 gcry_sexp_release (sig->sexp);
1018 GNUNET_free (sig);
1019}
gcry_sexp_t sexp
Libgcrypt S-expression for the RSA signature.
Definition: crypto_rsa.c:69

References GNUNET_free, and GNUNET_CRYPTO_RsaSignature::sexp.

Referenced by checkvec(), clean_rsa_sig(), clean_rsa_signature(), GNUNET_CRYPTO_blinded_sig_decref(), GNUNET_CRYPTO_unblinded_sig_decref(), and output_vectors().

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 1023 of file crypto_rsa.c.

1026{
1027 gcry_mpi_t s;
1028 size_t buf_size;
1029 size_t rsize;
1030 unsigned char *buf;
1031 int ret;
1032
1033 ret = key_from_sexp (&s,
1034 sig->sexp,
1035 "sig-val",
1036 "s");
1037 if (0 != ret)
1038 ret = key_from_sexp (&s,
1039 sig->sexp,
1040 "rsa",
1041 "s");
1042 GNUNET_assert (0 == ret);
1043 gcry_mpi_print (GCRYMPI_FMT_USG,
1044 NULL,
1045 0,
1046 &buf_size,
1047 s);
1048 buf = GNUNET_malloc (buf_size);
1049 GNUNET_assert (0 ==
1050 gcry_mpi_print (GCRYMPI_FMT_USG,
1051 buf,
1052 buf_size,
1053 &rsize,
1054 s));
1055 GNUNET_assert (rsize == buf_size);
1056 *buffer = (void *) buf;
1057 gcry_mpi_release (s);
1058 return buf_size;
1059}

References 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(), output_vectors(), qconv_blinded_sig(), qconv_rsa_signature(), and qconv_unblinded_sig().

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 1063 of file crypto_rsa.c.

1065{
1066 struct GNUNET_CRYPTO_RsaSignature *sig;
1067 gcry_mpi_t s;
1068 gcry_sexp_t data;
1069
1070 if (0 !=
1071 gcry_mpi_scan (&s,
1072 GCRYMPI_FMT_USG,
1073 buf,
1074 buf_size,
1075 NULL))
1076 {
1077 GNUNET_break_op (0);
1078 return NULL;
1079 }
1080
1081 if (0 !=
1082 gcry_sexp_build (&data,
1083 NULL,
1084 "(sig-val(rsa(s %M)))",
1085 s))
1086 {
1087 GNUNET_break (0);
1088 gcry_mpi_release (s);
1089 return NULL;
1090 }
1091 gcry_mpi_release (s);
1093 sig->sexp = data;
1094 return sig;
1095}

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

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

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 1268 of file crypto_rsa.c.

1269{
1270 struct GNUNET_CRYPTO_RsaSignature *dup;
1271 gcry_sexp_t dup_sexp;
1272 size_t erroff;
1273 gcry_mpi_t s;
1274 int ret;
1275
1276 /* verify that this is an RSA signature */
1277 ret = key_from_sexp (&s, sig->sexp, "sig-val", "s");
1278 if (0 != ret)
1279 ret = key_from_sexp (&s, sig->sexp, "rsa", "s");
1280 GNUNET_assert (0 == ret);
1281 gcry_mpi_release (s);
1282 /* copy the sexp */
1283 GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", sig->sexp));
1285 dup->sexp = dup_sexp;
1286 return dup;
1287}

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

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 1118 of file crypto_rsa.c.

1121{
1122 struct RsaBlindingKey *bkey;
1123 gcry_mpi_t n;
1124 gcry_mpi_t s;
1125 gcry_mpi_t r_inv;
1126 gcry_mpi_t ubsig;
1127 int ret;
1128 struct GNUNET_CRYPTO_RsaSignature *sret;
1129
1130 BENCHMARK_START (rsa_unblind);
1131
1132 ret = key_from_sexp (&n, pkey->sexp, "public-key", "n");
1133 if (0 != ret)
1134 ret = key_from_sexp (&n, pkey->sexp, "rsa", "n");
1135 if (0 != ret)
1136 {
1137 GNUNET_break_op (0);
1138 return NULL;
1139 }
1140 ret = key_from_sexp (&s, sig->sexp, "sig-val", "s");
1141 if (0 != ret)
1142 ret = key_from_sexp (&s, sig->sexp, "rsa", "s");
1143 if (0 != ret)
1144 {
1145 gcry_mpi_release (n);
1146 GNUNET_break_op (0);
1147 return NULL;
1148 }
1149
1150 bkey = rsa_blinding_key_derive (pkey, bks);
1151 if (NULL == bkey)
1152 {
1153 /* RSA key is malicious since rsa_gcd_validate failed here.
1154 * It should have failed during GNUNET_CRYPTO_rsa_blind too though,
1155 * so the exchange is being malicious in an unfamilair way, maybe
1156 * just trying to crash us. */
1157 GNUNET_break_op (0);
1158 gcry_mpi_release (n);
1159 gcry_mpi_release (s);
1160 return NULL;
1161 }
1162
1163 r_inv = gcry_mpi_new (0);
1164 if (1 !=
1165 gcry_mpi_invm (r_inv,
1166 bkey->r,
1167 n))
1168 {
1169 /* We cannot find r mod n, so gcd(r,n) != 1, which should get *
1170 * caught above, but we handle it the same here. */
1171 GNUNET_break_op (0);
1172 gcry_mpi_release (r_inv);
1173 rsa_blinding_key_free (bkey);
1174 gcry_mpi_release (n);
1175 gcry_mpi_release (s);
1176 return NULL;
1177 }
1178
1179 ubsig = gcry_mpi_new (0);
1180 gcry_mpi_mulm (ubsig, s, r_inv, n);
1181 gcry_mpi_release (n);
1182 gcry_mpi_release (r_inv);
1183 gcry_mpi_release (s);
1184 rsa_blinding_key_free (bkey);
1185
1186 sret = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature);
1187 GNUNET_assert (0 ==
1188 gcry_sexp_build (&sret->sexp,
1189 NULL,
1190 "(sig-val (rsa (s %M)))",
1191 ubsig));
1192 gcry_mpi_release (ubsig);
1193 BENCHMARK_END (rsa_unblind);
1194 return sret;
1195}

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

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

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 void *  message,
size_t  message_size,
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
messagethe message to sign
message_sizenumber of bytes in message
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 1199 of file crypto_rsa.c.

1203{
1204 gcry_sexp_t data;
1205 gcry_mpi_t r;
1206 int rc;
1207
1208 BENCHMARK_START (rsa_verify);
1209
1211 message,
1212 message_size);
1213 if (NULL == r)
1214 {
1215 GNUNET_break_op (0);
1216 /* RSA key is malicious since rsa_gcd_validate failed here.
1217 * It should have failed during GNUNET_CRYPTO_rsa_blind too though,
1218 * so the exchange is being malicious in an unfamilair way, maybe
1219 * just trying to crash us. Arguably, we've only an internal error
1220 * though because we should've detected this in our previous call
1221 * to GNUNET_CRYPTO_rsa_unblind. *///
1222 return GNUNET_NO;
1223 }
1224
1225 data = mpi_to_sexp (r);
1226 gcry_mpi_release (r);
1227
1228 rc = gcry_pk_verify (sig->sexp,
1229 data,
1230 pkey->sexp);
1231 gcry_sexp_release (data);
1232 if (0 != rc)
1233 {
1235 _ ("RSA signature verification failed at %s:%d: %s\n"),
1236 __FILE__,
1237 __LINE__,
1238 gcry_strerror (rc));
1239 BENCHMARK_END (rsa_verify);
1240 return GNUNET_SYSERR;
1241 }
1242 BENCHMARK_END (rsa_verify);
1243 return GNUNET_OK;
1244}
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:894
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

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

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

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

◆ GNUNET_CRYPTO_cs_private_key_generate()

void GNUNET_CRYPTO_cs_private_key_generate ( struct GNUNET_CRYPTO_CsPrivateKey priv)

Create a new random private key.

Parameters
[out]privwhere to write the fresh private key

Create a new random private key.

This is an implementation of the Clause Blind Schnorr Signature Scheme using Curve25519. Further details about the Clause Blind Schnorr Signature Scheme can be found here: https://eprint.iacr.org/2019/877.pdf

We use libsodium wherever possible.

Definition at line 45 of file crypto_cs.c.

46{
47 crypto_core_ed25519_scalar_random (priv->scalar.d);
48}
unsigned char d[crypto_core_ed25519_SCALARBYTES]
32 byte scalar
struct GNUNET_CRYPTO_Cs25519Scalar scalar

References GNUNET_CRYPTO_Cs25519Scalar::d, and GNUNET_CRYPTO_CsPrivateKey::scalar.

Referenced by GNUNET_CRYPTO_blind_sign_keys_create_va(), and output_vectors().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_cs_private_key_get_public()

void GNUNET_CRYPTO_cs_private_key_get_public ( const struct GNUNET_CRYPTO_CsPrivateKey priv,
struct GNUNET_CRYPTO_CsPublicKey pub 
)

Extract the public key of the given private key.

Parameters
privthe private key
[out]pubwhere to write the public key

Definition at line 52 of file crypto_cs.c.

55{
56 GNUNET_assert (0 ==
57 crypto_scalarmult_ed25519_base_noclamp (pub->point.y,
58 priv->scalar.d));
59}

References GNUNET_CRYPTO_Cs25519Scalar::d, GNUNET_assert, pub, and GNUNET_CRYPTO_CsPrivateKey::scalar.

Referenced by GNUNET_CRYPTO_blind_sign_keys_create_va(), and output_vectors().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_cs_r_derive()

void GNUNET_CRYPTO_cs_r_derive ( const struct GNUNET_CRYPTO_CsSessionNonce nonce,
const char *  seed,
const struct GNUNET_CRYPTO_CsPrivateKey lts,
struct GNUNET_CRYPTO_CsRSecret  r[2] 
)

Derive a new secret r pair r0 and r1.

In original papers r is generated randomly To provide abort-idempotency, r needs to be derived but still needs to be UNPREDICTABLE To ensure unpredictability a new nonce should be used when a new r needs to be derived. Uses HKDF internally. Comment: Can be done in one HKDF shot and split output.

Parameters
nonceis a random nonce
seedseed to use in derivation
ltsis a long-term-secret in form of a private key
[out]rarray containing derived secrets r0 and r1

Definition at line 79 of file crypto_cs.c.

83{
85 GNUNET_YES ==
87 r, sizeof (struct GNUNET_CRYPTO_CsRSecret) * 2,
88 seed, strlen (seed),
89 lts, sizeof (*lts),
90 nonce, sizeof (*nonce),
91 NULL, 0));
92 map_to_scalar_subgroup (&r[0].scalar);
93 map_to_scalar_subgroup (&r[1].scalar);
94}
static void map_to_scalar_subgroup(struct GNUNET_CRYPTO_Cs25519Scalar *scalar)
Maps 32 random bytes to a scalar.
Definition: crypto_cs.c:69
the private r used in the signature

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

Referenced by checkvec(), GNUNET_CRYPTO_blind_sign(), GNUNET_CRYPTO_get_blinding_input_values(), and output_vectors().

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

◆ GNUNET_CRYPTO_cs_r_get_public()

void GNUNET_CRYPTO_cs_r_get_public ( const struct GNUNET_CRYPTO_CsRSecret r_priv,
struct GNUNET_CRYPTO_CsRPublic r_pub 
)

Extract the public R of the given secret r.

Parameters
r_privthe private key
[out]r_pubwhere to write the public key

Definition at line 98 of file crypto_cs.c.

100{
101 GNUNET_assert (0 ==
102 crypto_scalarmult_ed25519_base_noclamp (r_pub->point.y,
103 r_priv->scalar.d));
104}
unsigned char y[crypto_core_ed25519_BYTES]
This is a point on the Curve25519.
struct GNUNET_CRYPTO_Cs25519Point point
struct GNUNET_CRYPTO_Cs25519Scalar scalar

References GNUNET_CRYPTO_Cs25519Scalar::d, GNUNET_assert, GNUNET_CRYPTO_CsRPublic::point, GNUNET_CRYPTO_CsRSecret::scalar, and GNUNET_CRYPTO_Cs25519Point::y.

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_cs_blinding_secrets_derive()

void GNUNET_CRYPTO_cs_blinding_secrets_derive ( const struct GNUNET_CRYPTO_CsBlindingNonce blind_seed,
struct GNUNET_CRYPTO_CsBlindingSecret  bs[2] 
)

Derives new random blinding factors.

In original papers blinding factors are generated randomly To provide abort-idempotency, blinding factors need to be derived but still need to be UNPREDICTABLE. To ensure unpredictability a new nonce has to be used. Uses HKDF internally.

Parameters
blind_seedis the blinding seed to derive blinding factors
[out]bsarray containing the two derived blinding secrets

Definition at line 108 of file crypto_cs.c.

111{
113 GNUNET_YES ==
115 sizeof (struct GNUNET_CRYPTO_CsBlindingSecret)
116 * 2,
117 "alphabeta",
118 strlen ("alphabeta"),
119 blind_seed,
120 sizeof(*blind_seed),
121 NULL,
122 0));
127}
static float beta
Percentage of total peer number in the view to send random PULLs to.
static float alpha
Percentage of total peer number in the view to send random PUSHes to.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_gnunet(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
Definition: crypto_hkdf.c:199
Secret used for blinding (alpha and beta).

References alpha, beta, GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet(), GNUNET_YES, and map_to_scalar_subgroup().

Referenced by checkvec(), GNUNET_CRYPTO_blind_sig_unblind(), GNUNET_CRYPTO_message_blind_to_sign(), and output_vectors().

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

◆ GNUNET_CRYPTO_cs_calc_blinded_c()

void GNUNET_CRYPTO_cs_calc_blinded_c ( const struct GNUNET_CRYPTO_CsBlindingSecret  bs[2],
const struct GNUNET_CRYPTO_CsRPublic  r_pub[2],
const struct GNUNET_CRYPTO_CsPublicKey pub,
const void *  msg,
size_t  msg_len,
struct GNUNET_CRYPTO_CsC  blinded_c[2],
struct GNUNET_CRYPTO_CSPublicRPairP r_pub_blind 
)

Calculate two blinded c's.

Comment: One would be insecure due to Wagner's algorithm solving ROS

Parameters
bsarray of the two blinding factor structs each containing alpha and beta
r_pubarray of the two signer's nonce R
pubthe public key of the signer
msgthe message to blind in preparation for signing
msg_lenlength of message msg
[out]blinded_carray of the two blinded c's
[out]r_pub_blindarray of the two blinded R

Definition at line 240 of file crypto_cs.c.

248{
249 /* for i 0/1: R'i = Ri + alpha i*G + beta i*pub */
250 calc_r_dash (&bs[0],
251 &r_pub[0],
252 pub,
253 &r_pub_blind->r_pub[0]);
254 calc_r_dash (&bs[1],
255 &r_pub[1],
256 pub,
257 &r_pub_blind->r_pub[1]);
258
259 /* for i 0/1: c'i = H(R'i, msg) */
260 struct GNUNET_CRYPTO_CsC c_dash_0;
261 struct GNUNET_CRYPTO_CsC c_dash_1;
262 cs_full_domain_hash (&r_pub_blind->r_pub[0],
263 msg,
264 msg_len,
265 pub,
266 &c_dash_0);
267 cs_full_domain_hash (&r_pub_blind->r_pub[1],
268 msg,
269 msg_len,
270 pub,
271 &c_dash_1);
272
273 /* for i 0/1: ci = c'i + beta i mod p */
274 crypto_core_ed25519_scalar_add (blinded_c[0].scalar.d,
275 c_dash_0.scalar.d,
276 bs[0].beta.d);
277 crypto_core_ed25519_scalar_add (blinded_c[1].scalar.d,
278 c_dash_1.scalar.d,
279 bs[1].beta.d);
280}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static void calc_r_dash(const struct GNUNET_CRYPTO_CsBlindingSecret *bs, const struct GNUNET_CRYPTO_CsRPublic *r_pub, const struct GNUNET_CRYPTO_CsPublicKey *pub, struct GNUNET_CRYPTO_CsRPublic *blinded_r_pub)
calculate R'
Definition: crypto_cs.c:209
static void cs_full_domain_hash(const struct GNUNET_CRYPTO_CsRPublic *r_dash, const void *msg, size_t msg_len, const struct GNUNET_CRYPTO_CsPublicKey *pub, struct GNUNET_CRYPTO_CsC *c)
Computes a Hash of (R', m) mapped to a Curve25519 scalar.
Definition: crypto_cs.c:151
struct GNUNET_CRYPTO_CsRPublic r_pub[2]
Schnorr c to be signed.
struct GNUNET_CRYPTO_Cs25519Scalar scalar

References GNUNET_CRYPTO_CsBlindingSecret::beta, calc_r_dash(), cs_full_domain_hash(), GNUNET_CRYPTO_Cs25519Scalar::d, msg, pub, GNUNET_CRYPTO_CSPublicRPairP::r_pub, and GNUNET_CRYPTO_CsC::scalar.

Referenced by checkvec(), GNUNET_CRYPTO_blind_sig_unblind(), GNUNET_CRYPTO_message_blind_to_sign(), and output_vectors().

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

◆ GNUNET_CRYPTO_cs_sign_derive()

void GNUNET_CRYPTO_cs_sign_derive ( const struct GNUNET_CRYPTO_CsPrivateKey priv,
const struct GNUNET_CRYPTO_CsRSecret  r[2],
const struct GNUNET_CRYPTO_CsBlindedMessage bm,
struct GNUNET_CRYPTO_CsBlindSignature cs_blind_sig 
)

Sign a blinded c.

This function derives b from a nonce and a longterm secret. In the original papers b is generated randomly. To provide abort-idempotency, b needs to be derived but still need to be UNPREDICTABLE. To ensure unpredictability a new nonce has to be used for every signature. HKDF is used internally for derivation. r0 and r1 can be derived prior by using GNUNET_CRYPTO_cs_r_derive.

Parameters
privprivate key to use for the signing and as LTS in HKDF
rarray of the two secret inputs from the signer
bmblinded message, including array of the two blinded c to sign c_b and the random nonce
[out]cs_blind_sigwhere to write the blind signature

Definition at line 284 of file crypto_cs.c.

289{
290 struct GNUNET_CRYPTO_Cs25519Scalar c_b_mul_priv;
291 uint32_t hkdf_out;
292
293 /* derive clause session identifier b (random bit) */
295 GNUNET_CRYPTO_hkdf_gnunet (&hkdf_out,
296 sizeof (hkdf_out),
297 "b",
298 strlen ("b"),
299 priv,
300 sizeof (*priv),
301 &bm->nonce,
302 sizeof (bm->nonce),
303 NULL,
304 0));
305 cs_blind_sig->b = hkdf_out % 2;
306
307 /* s = r_b + c_b * priv */
308 crypto_core_ed25519_scalar_mul (c_b_mul_priv.d,
309 bm->c[cs_blind_sig->b].scalar.d,
310 priv->scalar.d);
311 crypto_core_ed25519_scalar_add (cs_blind_sig->s_scalar.scalar.d,
312 r[cs_blind_sig->b].scalar.d,
313 c_b_mul_priv.d);
314}
struct GNUNET_CRYPTO_Cs25519Scalar scalar
struct GNUNET_CRYPTO_CsBlindS s_scalar
The blinded s scalar calculated from c_b.
unsigned int b
To make ROS problem harder, the signer chooses an unpredictable b and only calculates signature of c_...
struct GNUNET_CRYPTO_CsC c[2]
The Clause Schnorr c_0 and c_1 containing the blinded message.
struct GNUNET_CRYPTO_CsSessionNonce nonce
Nonce used in initial request.

References GNUNET_CRYPTO_CsBlindSignature::b, GNUNET_CRYPTO_CsBlindedMessage::c, GNUNET_CRYPTO_Cs25519Scalar::d, GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet(), GNUNET_YES, GNUNET_CRYPTO_CsBlindedMessage::nonce, GNUNET_CRYPTO_CsBlindSignature::s_scalar, GNUNET_CRYPTO_CsPrivateKey::scalar, GNUNET_CRYPTO_CsRSecret::scalar, GNUNET_CRYPTO_CsC::scalar, and GNUNET_CRYPTO_CsBlindS::scalar.

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

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

◆ GNUNET_CRYPTO_cs_unblind()

void GNUNET_CRYPTO_cs_unblind ( const struct GNUNET_CRYPTO_CsBlindS blinded_signature_scalar,
const struct GNUNET_CRYPTO_CsBlindingSecret bs,
struct GNUNET_CRYPTO_CsS signature_scalar 
)

Unblind a blind-signed signature using a c that was blinded.

Parameters
blinded_signature_scalarthe signature made on the blinded c
bsthe blinding factors used in the blinding
[out]signature_scalarwhere to write the unblinded signature

Definition at line 318 of file crypto_cs.c.

322{
323 crypto_core_ed25519_scalar_add (signature_scalar->scalar.d,
324 blinded_signature_scalar->scalar.d,
325 bs->alpha.d);
326}
struct GNUNET_CRYPTO_Cs25519Scalar alpha
struct GNUNET_CRYPTO_Cs25519Scalar scalar

References GNUNET_CRYPTO_CsBlindingSecret::alpha, GNUNET_CRYPTO_Cs25519Scalar::d, GNUNET_CRYPTO_CsS::scalar, and GNUNET_CRYPTO_CsBlindS::scalar.

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_cs_verify()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_cs_verify ( const struct GNUNET_CRYPTO_CsSignature sig,
const struct GNUNET_CRYPTO_CsPublicKey pub,
const void *  msg,
size_t  msg_len 
)

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

Parameters
sigsignature that is being validated
pubpublic key of the signer
msgis the message that should be signed by sig (message is used to calculate c)
msg_lenis the message length
Returns
GNUNET_YES on success, GNUNET_SYSERR if signature invalid

Definition at line 330 of file crypto_cs.c.

334{
335 // calculate c' = H(R, m)
336 struct GNUNET_CRYPTO_CsC c_dash;
337
339 msg,
340 msg_len,
341 pub,
342 &c_dash);
343
344 // s'G ?= R' + c' pub
345 struct GNUNET_CRYPTO_Cs25519Point sig_scal_mul_base;
346 GNUNET_assert (0 ==
347 crypto_scalarmult_ed25519_base_noclamp (
348 sig_scal_mul_base.y,
349 sig->s_scalar.scalar.d));
350 struct GNUNET_CRYPTO_Cs25519Point c_dash_mul_pub;
351 GNUNET_assert (0 == crypto_scalarmult_ed25519_noclamp (c_dash_mul_pub.y,
352 c_dash.scalar.d,
353 pub->point.y));
354 struct GNUNET_CRYPTO_Cs25519Point R_add_c_dash_mul_pub;
355 GNUNET_assert (0 == crypto_core_ed25519_add (R_add_c_dash_mul_pub.y,
356 sig->r_point.point.y,
357 c_dash_mul_pub.y));
358
359 return 0 == GNUNET_memcmp (&sig_scal_mul_base,
360 &R_add_c_dash_mul_pub)
361 ? GNUNET_OK
363}
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_CRYPTO_CsS s_scalar
Schnorr signatures are composed of a scalar s and a curve point.
struct GNUNET_CRYPTO_CsRPublic r_point
Curve point of the Schnorr signature.

References cs_full_domain_hash(), GNUNET_CRYPTO_Cs25519Scalar::d, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, msg, GNUNET_CRYPTO_CsRPublic::point, pub, GNUNET_CRYPTO_CsSignature::r_point, GNUNET_CRYPTO_CsSignature::s_scalar, GNUNET_CRYPTO_CsC::scalar, GNUNET_CRYPTO_CsS::scalar, and GNUNET_CRYPTO_Cs25519Point::y.

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

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

◆ GNUNET_CRYPTO_get_blinding_input_values()

struct GNUNET_CRYPTO_BlindingInputValues * GNUNET_CRYPTO_get_blinding_input_values ( const struct GNUNET_CRYPTO_BlindSignPrivateKey bsign_priv,
const union GNUNET_CRYPTO_BlindSessionNonce nonce,
const char *  salt 
)

Compute blinding input values for a given nonce and salt.

Parameters
bsign_privprivate key to compute input values for
noncesession nonce to derive input values from
saltsalt to include in derivation logic
Returns
blinding input values

Definition at line 430 of file crypto_blind_sign.c.

434{
436
438 biv->cipher = bsign_priv->cipher;
439 biv->rc = 1;
440 switch (bsign_priv->cipher)
441 {
443 GNUNET_break (0);
444 GNUNET_free (biv);
445 return NULL;
447 return biv;
449 {
450 struct GNUNET_CRYPTO_CsRSecret cspriv[2];
451
453 salt,
454 &bsign_priv->details.cs_private_key,
455 cspriv);
457 &biv->details.cs_values.r_pub[0]);
459 &biv->details.cs_values.r_pub[1]);
460 return biv;
461 }
462 }
463 GNUNET_break (0);
464 GNUNET_free (biv);
465 return NULL;
466}
void GNUNET_CRYPTO_cs_r_get_public(const struct GNUNET_CRYPTO_CsRSecret *r_priv, struct GNUNET_CRYPTO_CsRPublic *r_pub)
Extract the public R of the given secret r.
Definition: crypto_cs.c:98
void GNUNET_CRYPTO_cs_r_derive(const struct GNUNET_CRYPTO_CsSessionNonce *nonce, const char *seed, const struct GNUNET_CRYPTO_CsPrivateKey *lts, struct GNUNET_CRYPTO_CsRSecret r[2])
Derive a new secret r pair r0 and r1.
Definition: crypto_cs.c:79
struct GNUNET_CRYPTO_CsPrivateKey cs_private_key
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the public key.
union GNUNET_CRYPTO_BlindSignPrivateKey::@17 details
Details, depending on cipher.
Input needed for blinding a message.
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_CSPublicRPairP cs_values
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindingInputValues::@19 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_CsSessionNonce cs_nonce
Nonce used when signing with CS.

References GNUNET_CRYPTO_BlindSignPrivateKey::cipher, GNUNET_CRYPTO_BlindingInputValues::cipher, GNUNET_CRYPTO_BlindSessionNonce::cs_nonce, GNUNET_CRYPTO_BlindSignPrivateKey::cs_private_key, GNUNET_CRYPTO_BlindingInputValues::cs_values, GNUNET_CRYPTO_BlindSignPrivateKey::details, GNUNET_CRYPTO_BlindingInputValues::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_cs_r_derive(), GNUNET_CRYPTO_cs_r_get_public(), GNUNET_free, GNUNET_new, GNUNET_CRYPTO_CSPublicRPairP::r_pub, GNUNET_CRYPTO_BlindingInputValues::rc, and salt.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_blind_sign_pub_decref()

void GNUNET_CRYPTO_blind_sign_pub_decref ( struct GNUNET_CRYPTO_BlindSignPublicKey bsign_pub)

Decrement reference counter of a bsign_pub, and free it if it reaches zero.

Parameters
[in]bsign_pubkey to free

Definition at line 79 of file crypto_blind_sign.c.

81{
82 GNUNET_assert (bsign_pub->rc > 0);
83 bsign_pub->rc--;
84 if (0 != bsign_pub->rc)
85 return;
86 switch (bsign_pub->cipher)
87 {
89 GNUNET_break (0);
90 break;
92 if (NULL != bsign_pub->details.rsa_public_key)
93 {
95 bsign_pub->details.rsa_public_key = NULL;
96 }
98 break;
100 break;
101 }
102 GNUNET_free (bsign_pub);
103}
union GNUNET_CRYPTO_BlindSignPublicKey::@16 details
Details, depending on cipher.
unsigned int rc
Reference counter.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the public key.
struct GNUNET_CRYPTO_RsaPublicKey * rsa_public_key
If we use GNUNET_CRYPTO_BSA_RSA in cipher.

References GNUNET_CRYPTO_BlindSignPublicKey::cipher, GNUNET_CRYPTO_BlindSignPublicKey::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_public_key_free(), GNUNET_free, GNUNET_CRYPTO_BlindSignPublicKey::rc, and GNUNET_CRYPTO_BlindSignPublicKey::rsa_public_key.

Referenced by clean_blind_sign_pub().

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

◆ GNUNET_CRYPTO_blind_sign_priv_decref()

void GNUNET_CRYPTO_blind_sign_priv_decref ( struct GNUNET_CRYPTO_BlindSignPrivateKey bsign_priv)

Decrement reference counter of a bsign_priv, and free it if it reaches zero.

Parameters
[in]bsign_privkey to free

Definition at line 50 of file crypto_blind_sign.c.

52{
53 GNUNET_assert (bsign_priv->rc > 0);
54 bsign_priv->rc--;
55 if (0 != bsign_priv->rc)
56 return;
57 switch (bsign_priv->cipher)
58 {
60 GNUNET_break (0);
61 break;
63 if (NULL != bsign_priv->details.rsa_private_key)
64 {
66 bsign_priv->details.rsa_private_key = NULL;
67 }
69 break;
72 break;
73 }
74 GNUNET_free (bsign_priv);
75}
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_RsaPrivateKey * rsa_private_key
If we use GNUNET_CRYPTO_BSA_RSA in cipher.

References GNUNET_CRYPTO_BlindSignPrivateKey::cipher, GNUNET_CRYPTO_BlindSignPrivateKey::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_private_key_free(), GNUNET_free, GNUNET_CRYPTO_BlindSignPrivateKey::rc, and GNUNET_CRYPTO_BlindSignPrivateKey::rsa_private_key.

Referenced by clean_blind_sign_priv().

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

◆ GNUNET_CRYPTO_unblinded_sig_decref()

void GNUNET_CRYPTO_unblinded_sig_decref ( struct GNUNET_CRYPTO_UnblindedSignature ub_sig)

Decrement reference counter of a ub_sig, and free it if it reaches zero.

Parameters
[in]ub_sigsignature to free

Definition at line 107 of file crypto_blind_sign.c.

109{
110 GNUNET_assert (ub_sig->rc > 0);
111 ub_sig->rc--;
112 if (0 != ub_sig->rc)
113 return;
114 switch (ub_sig->cipher)
115 {
117 GNUNET_break (0);
118 break;
120 if (NULL != ub_sig->details.rsa_signature)
121 {
123 ub_sig->details.rsa_signature = NULL;
124 }
126 break;
129 break;
130 }
131 GNUNET_free (ub_sig);
132}
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1015
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
union GNUNET_CRYPTO_UnblindedSignature::@14 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.

References GNUNET_CRYPTO_UnblindedSignature::cipher, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_free(), GNUNET_free, GNUNET_CRYPTO_UnblindedSignature::rc, and GNUNET_CRYPTO_UnblindedSignature::rsa_signature.

Referenced by clean_unblinded_sig().

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

◆ GNUNET_CRYPTO_blinded_sig_decref()

void GNUNET_CRYPTO_blinded_sig_decref ( struct GNUNET_CRYPTO_BlindedSignature blind_sig)

Decrement reference counter of a blind_sig, and free it if it reaches zero.

Parameters
[in]blind_sigsignature to free

Definition at line 136 of file crypto_blind_sign.c.

138{
139 GNUNET_assert (blind_sig->rc > 0);
140 blind_sig->rc--;
141 if (0 != blind_sig->rc)
142 return;
143 switch (blind_sig->cipher)
144 {
146 GNUNET_break (0);
147 break;
149 if (NULL != blind_sig->details.blinded_rsa_signature)
150 {
152 blind_sig->details.blinded_rsa_signature);
153 blind_sig->details.blinded_rsa_signature = NULL;
154 }
156 break;
159 break;
160 }
161 GNUNET_free (blind_sig);
162}
unsigned int rc
Reference counter.
union GNUNET_CRYPTO_BlindedSignature::@15 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.

References GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_free(), GNUNET_free, and GNUNET_CRYPTO_BlindedSignature::rc.

Referenced by clean_blinded_sig().

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

◆ GNUNET_CRYPTO_blinded_message_decref()

void GNUNET_CRYPTO_blinded_message_decref ( struct GNUNET_CRYPTO_BlindedMessage bm)

Decrement reference counter of a bm, and free it if it reaches zero.

Parameters
[in]bmblinded message to free

Definition at line 166 of file crypto_blind_sign.c.

168{
169 GNUNET_assert (bm->rc > 0);
170 bm->rc--;
171 if (0 != bm->rc)
172 return;
173 switch (bm->cipher)
174 {
176 GNUNET_break (0);
177 break;
180 break;
182 break;
183 }
184 GNUNET_free (bm);
185}
unsigned int rc
Reference counter.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the sign blinded message.
union GNUNET_CRYPTO_BlindedMessage::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaBlindedMessage rsa_blinded_message
If we use GNUNET_CRYPTO_BSA_RSA in cipher.

References GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg, GNUNET_CRYPTO_BlindedMessage::cipher, GNUNET_CRYPTO_BlindedMessage::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, GNUNET_CRYPTO_BlindedMessage::rc, and GNUNET_CRYPTO_BlindedMessage::rsa_blinded_message.

Referenced by clean_blinded_message().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_blinded_message_incref()

struct GNUNET_CRYPTO_BlindedMessage * GNUNET_CRYPTO_blinded_message_incref ( struct GNUNET_CRYPTO_BlindedMessage bm)

Increment reference counter of the given bm.

Parameters
[in,out]bmblinded message to increment reference counter for
Returns
alias of bm with RC incremented

Definition at line 189 of file crypto_blind_sign.c.

191{
192 bm->rc++;
193 return bm;
194}

References GNUNET_CRYPTO_BlindedMessage::rc.

◆ GNUNET_CRYPTO_blinding_input_values_incref()

struct GNUNET_CRYPTO_BlindingInputValues * GNUNET_CRYPTO_blinding_input_values_incref ( struct GNUNET_CRYPTO_BlindingInputValues bm)

Increment reference counter of the given bi.

Parameters
[in,out]biblinding input values to increment reference counter for
Returns
alias of bi with RC incremented

Definition at line 198 of file crypto_blind_sign.c.

200{
201 bm->rc++;
202 return bm;
203}

References GNUNET_CRYPTO_BlindingInputValues::rc.

◆ GNUNET_CRYPTO_blinding_input_values_decref()

void GNUNET_CRYPTO_blinding_input_values_decref ( struct GNUNET_CRYPTO_BlindingInputValues bm)

Decrement reference counter of the given bi, and free it if it reaches zero.

Parameters
[in,out]biblinding input values to decrement reference counter for

Definition at line 26 of file crypto_blind_sign.c.

28{
29 GNUNET_assert (bm->rc > 0);
30 bm->rc--;
31 if (0 != bm->rc)
32 return;
33 switch (bm->cipher)
34 {
36 GNUNET_break (0);
37 break;
40 break;
43 break;
44 }
45 GNUNET_free (bm);
46}

References GNUNET_CRYPTO_BlindingInputValues::cipher, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, and GNUNET_CRYPTO_BlindingInputValues::rc.

◆ GNUNET_CRYPTO_bsign_pub_incref()

struct GNUNET_CRYPTO_BlindSignPublicKey * GNUNET_CRYPTO_bsign_pub_incref ( struct GNUNET_CRYPTO_BlindSignPublicKey bsign_pub)

Increment reference counter of the given bsign_pub.

Parameters
[in,out]bsign_pubpublic key to increment reference counter for
Returns
alias of bsign_pub with RC incremented

Definition at line 207 of file crypto_blind_sign.c.

209{
210 bsign_pub->rc++;
211 return bsign_pub;
212}

References GNUNET_CRYPTO_BlindSignPublicKey::rc.

◆ GNUNET_CRYPTO_bsign_priv_incref()

struct GNUNET_CRYPTO_BlindSignPrivateKey * GNUNET_CRYPTO_bsign_priv_incref ( struct GNUNET_CRYPTO_BlindSignPrivateKey bsign_priv)

Increment reference counter of the given bsign_priv.

Parameters
[in,out]bsign_privprivate key to increment reference counter for
Returns
alias of bsign_priv with RC incremented

Definition at line 216 of file crypto_blind_sign.c.

218{
219 bsign_priv->rc++;
220 return bsign_priv;
221}

References GNUNET_CRYPTO_BlindSignPrivateKey::rc.

◆ GNUNET_CRYPTO_ub_sig_incref()

struct GNUNET_CRYPTO_UnblindedSignature * GNUNET_CRYPTO_ub_sig_incref ( struct GNUNET_CRYPTO_UnblindedSignature ub_sig)

Increment reference counter of the given ub_sig.

Parameters
[in,out]ub_sigsignature to increment reference counter for
Returns
alias of ub_sig with RC incremented

Definition at line 225 of file crypto_blind_sign.c.

226{
227 ub_sig->rc++;
228 return ub_sig;
229}

References GNUNET_CRYPTO_UnblindedSignature::rc.

◆ GNUNET_CRYPTO_blind_sig_incref()

struct GNUNET_CRYPTO_BlindedSignature * GNUNET_CRYPTO_blind_sig_incref ( struct GNUNET_CRYPTO_BlindedSignature blind_sig)

Increment reference counter of the given blind_sig.

Parameters
[in,out]blind_sigsignature to increment reference counter for
Returns
alias of blind_sig with RC incremented

Definition at line 233 of file crypto_blind_sign.c.

235{
236 blind_sig->rc++;
237 return blind_sig;
238}

References GNUNET_CRYPTO_BlindedSignature::rc.

◆ GNUNET_CRYPTO_bsign_pub_cmp()

int GNUNET_CRYPTO_bsign_pub_cmp ( const struct GNUNET_CRYPTO_BlindSignPublicKey bp1,
const struct GNUNET_CRYPTO_BlindSignPublicKey bp2 
)

Compare two denomination public keys.

Parameters
bp1first key
bp2second key
Returns
0 if the keys are equal, otherwise -1 or 1

Definition at line 242 of file crypto_blind_sign.c.

245{
246 if (bp1->cipher != bp2->cipher)
247 return (bp1->cipher > bp2->cipher) ? 1 : -1;
248 switch (bp1->cipher)
249 {
251 GNUNET_break (0);
252 return 0;
254 return GNUNET_memcmp (&bp1->pub_key_hash,
255 &bp2->pub_key_hash);
257 return GNUNET_memcmp (&bp1->pub_key_hash,
258 &bp2->pub_key_hash);
259 }
260 GNUNET_assert (0);
261 return -2;
262}
struct GNUNET_HashCode pub_key_hash
Hash of the public key.

References GNUNET_CRYPTO_BlindSignPublicKey::cipher, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_memcmp, and GNUNET_CRYPTO_BlindSignPublicKey::pub_key_hash.

◆ GNUNET_CRYPTO_ub_sig_cmp()

int GNUNET_CRYPTO_ub_sig_cmp ( const struct GNUNET_CRYPTO_UnblindedSignature sig1,
const struct GNUNET_CRYPTO_UnblindedSignature sig2 
)

Compare two denomination signatures.

Parameters
sig1first signature
sig2second signature
Returns
0 if the keys are equal, otherwise -1 or 1

Definition at line 266 of file crypto_blind_sign.c.

269{
270 if (sig1->cipher != sig2->cipher)
271 return (sig1->cipher > sig2->cipher) ? 1 : -1;
272 switch (sig1->cipher)
273 {
275 GNUNET_break (0);
276 return 0;
279 sig2->details.rsa_signature);
281 return GNUNET_memcmp (&sig1->details.cs_signature,
282 &sig2->details.cs_signature);
283 }
284 GNUNET_assert (0);
285 return -2;
286}
int GNUNET_CRYPTO_rsa_signature_cmp(const struct GNUNET_CRYPTO_RsaSignature *s1, const struct GNUNET_CRYPTO_RsaSignature *s2)
Compare the values of two signatures.
Definition: crypto_rsa.c:602
struct GNUNET_CRYPTO_CsSignature cs_signature
If we use GNUNET_CRYPTO_BSA_CS in cipher.

References GNUNET_CRYPTO_UnblindedSignature::cipher, GNUNET_CRYPTO_UnblindedSignature::cs_signature, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_cmp(), GNUNET_memcmp, and GNUNET_CRYPTO_UnblindedSignature::rsa_signature.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_blind_sig_cmp()

int GNUNET_CRYPTO_blind_sig_cmp ( const struct GNUNET_CRYPTO_BlindedSignature sig1,
const struct GNUNET_CRYPTO_BlindedSignature sig2 
)

Compare two blinded denomination signatures.

Parameters
sig1first signature
sig2second signature
Returns
0 if the keys are equal, otherwise -1 or 1

Definition at line 290 of file crypto_blind_sign.c.

293{
294 if (sig1->cipher != sig2->cipher)
295 return (sig1->cipher > sig2->cipher) ? 1 : -1;
296 switch (sig1->cipher)
297 {
299 GNUNET_break (0);
300 return 0;
307 }
308 GNUNET_assert (0);
309 return -2;
310}
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.

References GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_cmp(), and GNUNET_memcmp.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_blinded_message_cmp()

int GNUNET_CRYPTO_blinded_message_cmp ( const struct GNUNET_CRYPTO_BlindedMessage bp1,
const struct GNUNET_CRYPTO_BlindedMessage bp2 
)

Compare two blinded messages.

Parameters
bp1first blinded message
bp2second blinded message
Returns
0 if the keys are equal, otherwise -1 or 1

Definition at line 314 of file crypto_blind_sign.c.

317{
318 if (bp1->cipher != bp2->cipher)
319 return (bp1->cipher > bp2->cipher) ? 1 : -1;
320 switch (bp1->cipher)
321 {
323 GNUNET_break (0);
324 return 0;
330 return memcmp (bp1->details.rsa_blinded_message.blinded_msg,
336 }
337 GNUNET_assert (0);
338 return -2;
339}
struct GNUNET_CRYPTO_CsBlindedMessage cs_blinded_message
If we use GNUNET_CRYPTO_BSA_CS in cipher.

References GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg, GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg_size, GNUNET_CRYPTO_BlindedMessage::cipher, GNUNET_CRYPTO_BlindedMessage::cs_blinded_message, GNUNET_CRYPTO_BlindedMessage::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_memcmp, and GNUNET_CRYPTO_BlindedMessage::rsa_blinded_message.

◆ GNUNET_CRYPTO_blind_sign_keys_create()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blind_sign_keys_create ( struct GNUNET_CRYPTO_BlindSignPrivateKey **  bsign_priv,
struct GNUNET_CRYPTO_BlindSignPublicKey **  bsign_pub,
enum GNUNET_CRYPTO_BlindSignatureAlgorithm  cipher,
  ... 
)

Initialize public-private key pair for blind signatures.

For GNUNET_CRYPTO_BSA_RSA, an additional "unsigned int" argument with the number of bits for 'n' (e.g. 2048) must be passed.

Parameters
[out]bsign_privwhere to write the private key with RC 1
[out]bsign_pubwhere to write the public key with RC 1
cipherwhich type of cipher to use
...RSA key size (eg. 2048/3072/4096)
Returns
GNUNET_OK on success, GNUNET_NO if parameterst were invalid

Definition at line 343 of file crypto_blind_sign.c.

348{
350 va_list ap;
351
352 va_start (ap,
353 cipher);
355 bsign_pub,
356 cipher,
357 ap);
358 va_end (ap);
359 return ret;
360}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blind_sign_keys_create_va(struct GNUNET_CRYPTO_BlindSignPrivateKey **bsign_priv, struct GNUNET_CRYPTO_BlindSignPublicKey **bsign_pub, enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher, va_list ap)
Initialize public-private key pair for blind signatures.

References GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_CRYPTO_blind_sign_keys_create_va(), and ret.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_blind_sign_keys_create_va()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blind_sign_keys_create_va ( struct GNUNET_CRYPTO_BlindSignPrivateKey **  bsign_priv,
struct GNUNET_CRYPTO_BlindSignPublicKey **  bsign_pub,
enum GNUNET_CRYPTO_BlindSignatureAlgorithm  cipher,
va_list  ap 
)

Initialize public-private key pair for blind signatures.

For GNUNET_CRYPTO_BSA_RSA, an additional "unsigned int" argument with the number of bits for 'n' (e.g. 2048) must be passed.

Parameters
[out]bsign_privwhere to write the private key with RC 1
[out]bsign_pubwhere to write the public key with RC 1
cipherwhich type of cipher to use
apRSA key size (eg. 2048/3072/4096)
Returns
GNUNET_OK on success, GNUNET_NO if parameterst were invalid

Definition at line 364 of file crypto_blind_sign.c.

369{
372
374 priv->rc = 1;
375 priv->cipher = cipher;
376 *bsign_priv = priv;
378 pub->rc = 1;
379 pub->cipher = cipher;
380 *bsign_pub = pub;
381 switch (cipher)
382 {
384 GNUNET_break (0);
385 break;
387 {
388 unsigned int bits;
389
390 bits = va_arg (ap,
391 unsigned int);
392 if (bits < 512)
393 {
394 GNUNET_break (0);
395 break;
396 }
399 }
400 if (NULL == priv->details.rsa_private_key)
401 {
402 GNUNET_break (0);
403 break;
404 }
405 pub->details.rsa_public_key
408 GNUNET_CRYPTO_rsa_public_key_hash (pub->details.rsa_public_key,
409 &pub->pub_key_hash);
410 return GNUNET_OK;
414 &priv->details.cs_private_key,
415 &pub->details.cs_public_key);
416 GNUNET_CRYPTO_hash (&pub->details.cs_public_key,
417 sizeof(pub->details.cs_public_key),
418 &pub->pub_key_hash);
419 return GNUNET_OK;
420 }
421 GNUNET_free (priv);
423 *bsign_priv = NULL;
424 *bsign_pub = NULL;
425 return GNUNET_SYSERR;
426}
struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_create(unsigned int len)
Create a new private key.
Definition: crypto_rsa.c:144
void GNUNET_CRYPTO_cs_private_key_get_public(const struct GNUNET_CRYPTO_CsPrivateKey *priv, struct GNUNET_CRYPTO_CsPublicKey *pub)
Extract the public key of the given private key.
Definition: crypto_cs.c:52
void GNUNET_CRYPTO_rsa_public_key_hash(const struct GNUNET_CRYPTO_RsaPublicKey *key, struct GNUNET_HashCode *hc)
Compute hash over the public key.
Definition: crypto_rsa.c:407
void GNUNET_CRYPTO_cs_private_key_generate(struct GNUNET_CRYPTO_CsPrivateKey *priv)
Create a new random private key.
Definition: crypto_cs.c:45
Type of private signing keys for blind signing.
Type of public signing keys for blind signatures.

References GNUNET_CRYPTO_BlindSignPublicKey::cipher, GNUNET_CRYPTO_BlindSignPrivateKey::cipher, GNUNET_CRYPTO_BlindSignPrivateKey::cs_private_key, GNUNET_CRYPTO_BlindSignPrivateKey::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_cs_private_key_generate(), GNUNET_CRYPTO_cs_private_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_rsa_private_key_create(), GNUNET_CRYPTO_rsa_private_key_get_public(), GNUNET_CRYPTO_rsa_public_key_hash(), GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_SYSERR, pub, GNUNET_CRYPTO_BlindSignPrivateKey::rc, and GNUNET_CRYPTO_BlindSignPrivateKey::rsa_private_key.

Referenced by GNUNET_CRYPTO_blind_sign_keys_create().

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

◆ GNUNET_CRYPTO_message_blind_to_sign()

struct GNUNET_CRYPTO_BlindedMessage * GNUNET_CRYPTO_message_blind_to_sign ( const struct GNUNET_CRYPTO_BlindSignPublicKey bsign_pub,
const union GNUNET_CRYPTO_BlindingSecretP bks,
const union GNUNET_CRYPTO_BlindSessionNonce nonce,
const void *  message,
size_t  message_size,
const struct GNUNET_CRYPTO_BlindingInputValues alg_values 
)

Blind message for blind signing with dk using blinding secret coin_bks.

Parameters
bsign_pubpublic key to blind for
bksblinding secret to use
noncenonce used to obtain alg_values can be NULL if input values are not used for the cipher
messagemessage to sign
message_sizenumber of bytes in message
alg_valuesalgorithm specific values to blind the message
Returns
blinded message to give to signer, NULL on error

Definition at line 470 of file crypto_blind_sign.c.

477{
479
481 bm->cipher = bsign_pub->cipher;
482 bm->rc = 1;
483 switch (bsign_pub->cipher)
484 {
486 GNUNET_break (0);
487 GNUNET_free (bm);
488 return NULL;
490 if (GNUNET_YES !=
492 message,
493 message_size,
494 &bks->rsa_bks,
495 bsign_pub->details.rsa_public_key,
497 {
498 GNUNET_break (0);
499 GNUNET_free (bm);
500 return NULL;
501 }
502 return bm;
504 {
505 struct GNUNET_CRYPTO_CSPublicRPairP blinded_r_pub;
507
508 if (NULL == nonce)
509 {
510 GNUNET_break_op (0);
511 GNUNET_free (bm);
512 return NULL;
513 }
515 bs);
517 bs,
518 alg_values->details.cs_values.r_pub,
519 &bsign_pub->details.cs_public_key,
520 message,
521 message_size,
523 &blinded_r_pub);
525 (void) blinded_r_pub;
526 return bm;
527 }
528 }
529 GNUNET_break (0);
530 return NULL;
531}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_blind(const void *message, size_t message_size, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, struct GNUNET_CRYPTO_RsaBlindedMessage *bm)
Blinds the given message with the given blinding key.
Definition: crypto_rsa.c:807
void GNUNET_CRYPTO_cs_calc_blinded_c(const struct GNUNET_CRYPTO_CsBlindingSecret bs[2], const struct GNUNET_CRYPTO_CsRPublic r_pub[2], const struct GNUNET_CRYPTO_CsPublicKey *pub, const void *msg, size_t msg_len, struct GNUNET_CRYPTO_CsC blinded_c[2], struct GNUNET_CRYPTO_CSPublicRPairP *r_pub_blind)
Calculate two blinded c's.
Definition: crypto_cs.c:240
void GNUNET_CRYPTO_cs_blinding_secrets_derive(const struct GNUNET_CRYPTO_CsBlindingNonce *blind_seed, struct GNUNET_CRYPTO_CsBlindingSecret bs[2])
Derives new random blinding factors.
Definition: crypto_cs.c:108
struct GNUNET_CRYPTO_CsPublicKey cs_public_key
If we use GNUNET_CRYPTO_BSA_CS in cipher.
Blinded message ready for blind signing.
Pair of Public R values for Cs denominations.
struct GNUNET_CRYPTO_CsBlindingNonce nonce
Clause Schnorr nonce.
struct GNUNET_CRYPTO_RsaBlindingKeySecret rsa_bks
Variant for RSA for blind signatures.

References GNUNET_CRYPTO_CsBlindedMessage::c, GNUNET_CRYPTO_BlindSignPublicKey::cipher, GNUNET_CRYPTO_BlindedMessage::cipher, GNUNET_CRYPTO_BlindedMessage::cs_blinded_message, GNUNET_CRYPTO_BlindSessionNonce::cs_nonce, GNUNET_CRYPTO_BlindSignPublicKey::cs_public_key, GNUNET_CRYPTO_BlindingInputValues::cs_values, GNUNET_CRYPTO_BlindSignPublicKey::details, GNUNET_CRYPTO_BlindedMessage::details, GNUNET_CRYPTO_BlindingInputValues::details, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_cs_blinding_secrets_derive(), GNUNET_CRYPTO_cs_calc_blinded_c(), GNUNET_CRYPTO_rsa_blind(), GNUNET_free, GNUNET_new, GNUNET_YES, GNUNET_CRYPTO_CsBlindedMessage::nonce, GNUNET_CRYPTO_BlindingSecretP::nonce, GNUNET_CRYPTO_CSPublicRPairP::r_pub, GNUNET_CRYPTO_BlindedMessage::rc, GNUNET_CRYPTO_BlindingSecretP::rsa_bks, GNUNET_CRYPTO_BlindedMessage::rsa_blinded_message, and GNUNET_CRYPTO_BlindSignPublicKey::rsa_public_key.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_blind_sign()

struct GNUNET_CRYPTO_BlindedSignature * GNUNET_CRYPTO_blind_sign ( const struct GNUNET_CRYPTO_BlindSignPrivateKey bsign_priv,
const char *  salt,
const struct GNUNET_CRYPTO_BlindedMessage blinded_message 
)

Create blind signature.

Parameters
bsign_privprivate key to use for signing
saltsalt value to use for the HKDF, can be NULL if input values are not used for the cipher
blinded_messagethe already blinded message to sign
Returns
blind signature with RC=1, NULL on failure

Definition at line 535 of file crypto_blind_sign.c.

539{
540 struct GNUNET_CRYPTO_BlindedSignature *blind_sig;
541
542 if (blinded_message->cipher != bsign_priv->cipher)
543 {
544 GNUNET_break (0);
545 return NULL;
546 }
547
548 blind_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
549 blind_sig->cipher = bsign_priv->cipher;
550 blind_sig->rc = 1;
551 switch (bsign_priv->cipher)
552 {
554 GNUNET_break (0);
555 GNUNET_free (blind_sig);
556 return NULL;
560 bsign_priv->details.rsa_private_key,
561 &blinded_message->details.rsa_blinded_message);
562 if (NULL == blind_sig->details.blinded_rsa_signature)
563 {
564 GNUNET_break (0);
565 GNUNET_free (blind_sig);
566 return NULL;
567 }
568 return blind_sig;
570 {
571 struct GNUNET_CRYPTO_CsRSecret r[2];
572
574 &blinded_message->details.cs_blinded_message.nonce,
575 salt,
576 &bsign_priv->details.cs_private_key,
577 r);
579 &bsign_priv->details.cs_private_key,
580 r,
581 &blinded_message->details.cs_blinded_message,
582 &blind_sig->details.blinded_cs_answer);
583 }
584 return blind_sig;
585 }
586 GNUNET_break (0);
587 return NULL;
588}
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_sign_blinded(const struct GNUNET_CRYPTO_RsaPrivateKey *key, const struct GNUNET_CRYPTO_RsaBlindedMessage *bm)
Sign a blinded value, which must be a full domain hash of a message.
Definition: crypto_rsa.c:970
void GNUNET_CRYPTO_cs_sign_derive(const struct GNUNET_CRYPTO_CsPrivateKey *priv, const struct GNUNET_CRYPTO_CsRSecret r[2], const struct GNUNET_CRYPTO_CsBlindedMessage *bm, struct GNUNET_CRYPTO_CsBlindSignature *cs_blind_sig)
Sign a blinded c.
Definition: crypto_cs.c:284
Type for blinded signatures.

References GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_CRYPTO_BlindSignPrivateKey::cipher, GNUNET_CRYPTO_BlindedMessage::cipher, GNUNET_CRYPTO_BlindedMessage::cs_blinded_message, GNUNET_CRYPTO_BlindSignPrivateKey::cs_private_key, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_CRYPTO_BlindSignPrivateKey::details, GNUNET_CRYPTO_BlindedMessage::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_cs_r_derive(), GNUNET_CRYPTO_cs_sign_derive(), GNUNET_CRYPTO_rsa_sign_blinded(), GNUNET_free, GNUNET_new, GNUNET_CRYPTO_CsBlindedMessage::nonce, GNUNET_CRYPTO_BlindedSignature::rc, GNUNET_CRYPTO_BlindedMessage::rsa_blinded_message, GNUNET_CRYPTO_BlindSignPrivateKey::rsa_private_key, and salt.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_blind_sig_unblind()

struct GNUNET_CRYPTO_UnblindedSignature * GNUNET_CRYPTO_blind_sig_unblind ( const struct GNUNET_CRYPTO_BlindedSignature blinded_sig,
const union GNUNET_CRYPTO_BlindingSecretP bks,
const void *  message,
size_t  message_size,
const struct GNUNET_CRYPTO_BlindingInputValues alg_values,
const struct GNUNET_CRYPTO_BlindSignPublicKey bsign_pub 
)

Unblind blind signature.

Parameters
blinded_sigthe blind signature
bksblinding secret to use
messagemessage that was supposedly signed
message_sizenumber of bytes in message
alg_valuesalgorithm specific values
bsign_pubpublic key used for signing
Returns
unblinded signature with RC=1, NULL on error

Definition at line 592 of file crypto_blind_sign.c.

599{
601
602 if (blinded_sig->cipher != bsign_pub->cipher)
603 {
604 GNUNET_break (0);
605 return NULL;
606 }
607 if (blinded_sig->cipher != alg_values->cipher)
608 {
609 GNUNET_break (0);
610 return NULL;
611 }
613 ub_sig->cipher = blinded_sig->cipher;
614 ub_sig->rc = 1;
615 switch (bsign_pub->cipher)
616 {
618 GNUNET_break (0);
619 GNUNET_free (ub_sig);
620 return NULL;
622 ub_sig->details.rsa_signature
624 blinded_sig->details.blinded_rsa_signature,
625 &bks->rsa_bks,
626 bsign_pub->details.rsa_public_key);
627 if (NULL == ub_sig->details.rsa_signature)
628 {
629 GNUNET_break (0);
630 GNUNET_free (ub_sig);
631 return NULL;
632 }
633 return ub_sig;
635 {
637 struct GNUNET_CRYPTO_CsC c[2];
638 struct GNUNET_CRYPTO_CSPublicRPairP r_pub_blind;
639 unsigned int b;
640
642 bs);
644 bs,
645 alg_values->details.cs_values.r_pub,
646 &bsign_pub->details.cs_public_key,
647 message,
648 message_size,
649 c,
650 &r_pub_blind);
651 b = blinded_sig->details.blinded_cs_answer.b;
653 = r_pub_blind.r_pub[b];
655 &blinded_sig->details.blinded_cs_answer.s_scalar,
656 &bs[b],
657 &ub_sig->details.cs_signature.s_scalar);
658 return ub_sig;
659 }
660 }
661 GNUNET_break (0);
662 GNUNET_free (ub_sig);
663 return NULL;
664}
void GNUNET_CRYPTO_cs_unblind(const struct GNUNET_CRYPTO_CsBlindS *blinded_signature_scalar, const struct GNUNET_CRYPTO_CsBlindingSecret *bs, struct GNUNET_CRYPTO_CsS *signature_scalar)
Unblind a blind-signed signature using a c that was blinded.
Definition: crypto_cs.c:318
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.
Definition: crypto_rsa.c:1118
Type of (unblinded) signatures.

References GNUNET_CRYPTO_CsBlindSignature::b, GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_UnblindedSignature::cipher, GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_CRYPTO_BlindSignPublicKey::cipher, GNUNET_CRYPTO_BlindingInputValues::cipher, GNUNET_CRYPTO_BlindSignPublicKey::cs_public_key, GNUNET_CRYPTO_UnblindedSignature::cs_signature, GNUNET_CRYPTO_BlindingInputValues::cs_values, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_CRYPTO_BlindSignPublicKey::details, GNUNET_CRYPTO_BlindingInputValues::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_cs_blinding_secrets_derive(), GNUNET_CRYPTO_cs_calc_blinded_c(), GNUNET_CRYPTO_cs_unblind(), GNUNET_CRYPTO_rsa_unblind(), GNUNET_free, GNUNET_new, GNUNET_CRYPTO_BlindingSecretP::nonce, GNUNET_CRYPTO_CsSignature::r_point, GNUNET_CRYPTO_CSPublicRPairP::r_pub, GNUNET_CRYPTO_UnblindedSignature::rc, GNUNET_CRYPTO_BlindingSecretP::rsa_bks, GNUNET_CRYPTO_BlindSignPublicKey::rsa_public_key, GNUNET_CRYPTO_UnblindedSignature::rsa_signature, GNUNET_CRYPTO_CsSignature::s_scalar, and GNUNET_CRYPTO_CsBlindSignature::s_scalar.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_blind_sig_verify()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blind_sig_verify ( const struct GNUNET_CRYPTO_BlindSignPublicKey bsign_pub,
const struct GNUNET_CRYPTO_UnblindedSignature ub_sig,
const void *  message,
size_t  message_size 
)

Verify signature made blindly.

Parameters
bsign_pubpublic key
ub_sigsignature made blindly with the private key
messagemessage that was supposedly signed
message_sizenumber of bytes in message
Returns
GNUNET_OK if the signature is valid

Definition at line 668 of file crypto_blind_sign.c.

673{
674 if (bsign_pub->cipher != ub_sig->cipher)
675 {
676 GNUNET_break (0);
677 return GNUNET_SYSERR;
678 }
679 switch (bsign_pub->cipher)
680 {
682 GNUNET_break (0);
683 return GNUNET_NO;
685 if (GNUNET_OK !=
687 message_size,
688 ub_sig->details.rsa_signature,
689 bsign_pub->details.rsa_public_key))
690 {
691 GNUNET_break_op (0);
692 return GNUNET_NO;
693 }
694 return GNUNET_YES;
696 if (GNUNET_OK !=
698 &bsign_pub->details.cs_public_key,
699 message,
700 message_size))
701 {
702 GNUNET_break_op (0);
703 return GNUNET_NO;
704 }
705 return GNUNET_YES;
706 }
707 GNUNET_break (0);
708 return GNUNET_NO;
709}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_cs_verify(const struct GNUNET_CRYPTO_CsSignature *sig, const struct GNUNET_CRYPTO_CsPublicKey *pub, const void *msg, size_t msg_len)
Verify whether the given message corresponds to the given signature and the signature is valid with r...
Definition: crypto_cs.c:330
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_verify(const void *message, size_t message_size, 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 resp...
Definition: crypto_rsa.c:1199

References GNUNET_CRYPTO_UnblindedSignature::cipher, GNUNET_CRYPTO_BlindSignPublicKey::cipher, GNUNET_CRYPTO_BlindSignPublicKey::cs_public_key, GNUNET_CRYPTO_UnblindedSignature::cs_signature, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_CRYPTO_BlindSignPublicKey::details, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_cs_verify(), GNUNET_CRYPTO_rsa_verify(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_CRYPTO_BlindSignPublicKey::rsa_public_key, and GNUNET_CRYPTO_UnblindedSignature::rsa_signature.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_public_key_get_length()

ssize_t GNUNET_CRYPTO_public_key_get_length ( const struct GNUNET_CRYPTO_PublicKey key)

Get the compacted length of a GNUNET_CRYPTO_PublicKey.

Compacted means that it returns the minimum number of bytes this key is long, as opposed to the union structure inside GNUNET_CRYPTO_PublicKey. Useful for compact serializations.

Parameters
keythe key.
Returns
-1 on error, else the compacted length of the key.

Definition at line 85 of file crypto_pkey.c.

87{
88 switch (ntohl (key->type))
89 {
91 return sizeof (key->type) + sizeof (key->ecdsa_key);
93 return sizeof (key->type) + sizeof (key->eddsa_key);
94 default:
95 GNUNET_break (0);
96 }
97 return -1;
98}

References GNUNET_break, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, and key.

Referenced by attr_iter_cb(), check_signature_identity(), consume_result_cb(), cred_iter_cb(), ego_callback(), get_message_body_size(), GNR_create_signature_message(), gns_string_to_value(), GNUNET_CRYPTO_public_key_to_string(), GNUNET_CRYPTO_read_public_key_from_buffer(), GNUNET_CRYPTO_write_public_key_to_buffer(), GNUNET_GNS_lookup_limited(), GNUNET_GNSRECORD_check_pow(), GNUNET_GNSRECORD_data_from_identity(), GNUNET_GNSRECORD_pow_round(), GNUNET_GNSRECORD_proof_get_size(), GNUNET_NAMESTORE_zone_to_name(), GNUNET_REVOCATION_query(), handle_client_call_message(), publicize_rm(), run(), run_edkey(), run_pkey(), run_with_key(), run_with_zone_pkey(), send_enter_room(), send_open_room(), and sign_pow_identity().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_read_public_key_from_buffer()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_public_key_from_buffer ( const void *  buffer,
size_t  len,
struct GNUNET_CRYPTO_PublicKey key,
size_t *  read 
)

Reads a GNUNET_CRYPTO_PublicKey from a compact buffer.

The buffer has to contain at least the compacted length of a GNUNET_CRYPTO_PublicKey in bytes. If the buffer is too small, the function returns -1 as error. If the buffer does not contain a valid key, it returns -2 as error.

Parameters
bufferthe buffer
lenthe length of buffer
keythe key
theamount of bytes read from the buffer
Returns
GNUNET_SYSERR on error

Definition at line 120 of file crypto_pkey.c.

125{
126 if (len < sizeof (key->type))
127 return GNUNET_SYSERR;
128 GNUNET_memcpy (&key->type,
129 buffer,
130 sizeof (key->type));
131 ssize_t length = GNUNET_CRYPTO_public_key_get_length (key);
132 if (len < length)
133 return GNUNET_SYSERR;
134 if (length < 0)
135 return GNUNET_SYSERR;
136 GNUNET_memcpy (&key->ecdsa_key,
137 buffer + sizeof (key->type),
138 length - sizeof (key->type));
139 *kb_read = length;
140 return GNUNET_OK;
141}
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:85

References GNUNET_CRYPTO_public_key_get_length(), GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, and key.

Referenced by block_plugin_revocation_check_block(), block_plugin_revocation_get_key(), check_room_initial_key(), handle_attribute_result(), handle_cadet_ring_message(), handle_consume_ticket_result(), handle_credential_result(), handle_lookup(), handle_phone_ring(), handle_query_message(), handle_zone_to_name(), and initialize_handle_via_key().

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

◆ GNUNET_CRYPTO_private_key_get_length()

ssize_t GNUNET_CRYPTO_private_key_get_length ( const struct GNUNET_CRYPTO_PrivateKey key)

Get the compacted length of a GNUNET_CRYPTO_PrivateKey.

Compacted means that it returns the minimum number of bytes this key is long, as opposed to the union structure inside GNUNET_CRYPTO_PrivateKey. Useful for compact serializations.

Parameters
keythe key.
Returns
-1 on error, else the compacted length of the key.

Definition at line 64 of file crypto_pkey.c.

66{
67 switch (ntohl (key->type))
68 {
70 return sizeof (key->type) + sizeof (key->ecdsa_key);
71 break;
73 return sizeof (key->type) + sizeof (key->eddsa_key);
74 break;
75 default:
77 "Got key type %u\n", ntohl (key->type));
78 GNUNET_break (0);
79 }
80 return -1;
81}

References GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, and key.

Referenced by create_update_message(), GNUNET_CRYPTO_private_key_to_string(), GNUNET_CRYPTO_read_private_key_from_buffer(), GNUNET_CRYPTO_write_private_key_to_buffer(), GNUNET_IDENTITY_create(), GNUNET_IDENTITY_ego_get_anonymous(), GNUNET_MESSENGER_connect(), GNUNET_MESSENGER_set_key(), GNUNET_NAMESTORE_record_set_edit_begin(), GNUNET_NAMESTORE_record_set_edit_cancel(), GNUNET_NAMESTORE_records_store(), GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_NAMESTORE_zone_iteration_start2(), GNUNET_NAMESTORE_zone_monitor_start(), GNUNET_NAMESTORE_zone_monitor_start2(), GNUNET_NAMESTORE_zone_to_name(), GNUNET_RECLAIM_attribute_delete(), GNUNET_RECLAIM_attribute_store(), GNUNET_RECLAIM_credential_delete(), GNUNET_RECLAIM_credential_store(), GNUNET_RECLAIM_get_attributes_start(), GNUNET_RECLAIM_get_credentials_start(), GNUNET_RECLAIM_ticket_issue(), GNUNET_RECLAIM_ticket_iteration_start(), GNUNET_RECLAIM_ticket_revoke(), handle_gns_response(), handle_identity_update(), handle_zone_to_name_it(), notify_listeners(), records_lookup(), and send_lookup_response_with_filter().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_write_public_key_to_buffer()

ssize_t GNUNET_CRYPTO_write_public_key_to_buffer ( const struct GNUNET_CRYPTO_PublicKey key,
void *  buffer,
size_t  len 
)

Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.

The buffer requires space for at least the compacted length of a GNUNET_CRYPTO_PublicKey in bytes. If the buffer is too small, the function returns -1 as error. If the key is not valid, it returns -2 as error.

Parameters
keythe key
bufferthe buffer
lenthe length of buffer
Returns
-1 or -2 on error, else the amount of bytes written to the buffer

Definition at line 145 of file crypto_pkey.c.

149{
150 const ssize_t length = GNUNET_CRYPTO_public_key_get_length (key);
151 if (len < length)
152 return -1;
153 if (length < 0)
154 return -2;
155 GNUNET_memcpy (buffer, &(key->type), sizeof (key->type));
156 GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length
157 - sizeof (key->type));
158 return length;
159}

References GNUNET_CRYPTO_public_key_get_length(), GNUNET_memcpy, and key.

Referenced by attr_iter_cb(), consume_result_cb(), cred_iter_cb(), GNR_create_signature_message(), GNUNET_GNS_lookup_limited(), GNUNET_NAMESTORE_zone_to_name(), GNUNET_REVOCATION_query(), handle_client_call_message(), send_enter_room(), and send_open_room().

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

◆ GNUNET_CRYPTO_read_private_key_from_buffer()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer ( const void *  buffer,
size_t  len,
struct GNUNET_CRYPTO_PrivateKey key,
size_t *  read 
)

Reads a GNUNET_CRYPTO_PrivateKey from a compact buffer.

The buffer has to contain at least the compacted length of a GNUNET_CRYPTO_PrivateKey in bytes. If the buffer is too small, the function returns GNUNET_SYSERR as error.

Parameters
bufferthe buffer
lenthe length of buffer
keythe key
theamount of bytes read from the buffer
Returns
GNUNET_SYSERR on error

Definition at line 163 of file crypto_pkey.c.

168{
169 if (len < sizeof (key->type))
170 return GNUNET_SYSERR;
171 GNUNET_memcpy (&key->type,
172 buffer,
173 sizeof (key->type));
174 ssize_t length = GNUNET_CRYPTO_private_key_get_length (key);
175 if (len < length)
176 return GNUNET_SYSERR;
177 if (length < 0)
178 return GNUNET_SYSERR;
179 GNUNET_memcpy (&key->ecdsa_key,
180 buffer + sizeof (key->type),
181 length - sizeof (key->type));
182 *kb_read = length;
183 return GNUNET_OK;
184}
ssize_t GNUNET_CRYPTO_private_key_get_length(const struct GNUNET_CRYPTO_PrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_PrivateKey.
Definition: crypto_pkey.c:64

References GNUNET_CRYPTO_private_key_get_length(), GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, and key.

Referenced by handle_attribute_delete_message(), handle_attribute_store_message(), handle_client_call_message(), handle_create_message(), handle_credential_delete_message(), handle_credential_iteration_start(), handle_credential_store_message(), handle_edit_record_set(), handle_edit_record_set_cancel(), handle_identity_update(), handle_issue_ticket_message(), handle_iteration_start(), handle_lookup_result(), handle_monitor_start(), handle_record_lookup(), handle_record_result(), handle_record_store(), handle_result(), handle_revoke_ticket_message(), handle_ticket_iteration_start(), handle_zone_to_name(), and handle_zone_to_name_response().

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

◆ GNUNET_CRYPTO_write_private_key_to_buffer()

ssize_t GNUNET_CRYPTO_write_private_key_to_buffer ( const struct GNUNET_CRYPTO_PrivateKey key,
void *  buffer,
size_t  len 
)

Writes a GNUNET_CRYPTO_PrivateKey to a compact buffer.

The buffer requires space for at least the compacted length of a GNUNET_CRYPTO_PrivateKey in bytes. If the buffer is too small, the function returns -1 as error. If the key is not valid, it returns -2 as error.

Parameters
keythe key
bufferthe buffer
lenthe length of buffer
Returns
-1 or -2 on error, else the amount of bytes written to the buffer

Definition at line 188 of file crypto_pkey.c.

192{
193 const ssize_t length = GNUNET_CRYPTO_private_key_get_length (key);
194 if (len < length)
195 return -1;
196 if (length < 0)
197 return -2;
198 GNUNET_memcpy (buffer, &(key->type), sizeof (key->type));
199 GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length
200 - sizeof (key->type));
201 return length;
202}

References GNUNET_CRYPTO_private_key_get_length(), GNUNET_memcpy, and key.

Referenced by create_update_message(), GNUNET_IDENTITY_create(), GNUNET_NAMESTORE_record_set_edit_begin(), GNUNET_NAMESTORE_record_set_edit_cancel(), GNUNET_NAMESTORE_records_store(), GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_NAMESTORE_zone_iteration_start2(), GNUNET_NAMESTORE_zone_to_name(), GNUNET_RECLAIM_attribute_delete(), GNUNET_RECLAIM_attribute_store(), GNUNET_RECLAIM_credential_delete(), GNUNET_RECLAIM_credential_store(), GNUNET_RECLAIM_get_attributes_start(), GNUNET_RECLAIM_get_credentials_start(), GNUNET_RECLAIM_ticket_issue(), GNUNET_RECLAIM_ticket_iteration_start(), GNUNET_RECLAIM_ticket_revoke(), handle_gns_response(), handle_zone_to_name_it(), notify_listeners(), reconnect(), records_lookup(), and send_lookup_response_with_filter().

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

◆ GNUNET_CRYPTO_signature_get_length()

ssize_t GNUNET_CRYPTO_signature_get_length ( const struct GNUNET_CRYPTO_Signature sig)

Get the compacted length of a GNUNET_CRYPTO_Signature.

Compacted means that it returns the minimum number of bytes this signature is long, as opposed to the union structure inside GNUNET_CRYPTO_Signature. Useful for compact serializations.

Parameters
sigthe signature.
Returns
-1 on error, else the compacted length of the signature.

Definition at line 206 of file crypto_pkey.c.

208{
209 switch (ntohl (sig->type))
210 {
212 return sizeof (sig->type) + sizeof (sig->ecdsa_signature);
213 break;
215 return sizeof (sig->type) + sizeof (sig->eddsa_signature);
216 break;
217 default:
218 GNUNET_break (0);
219 }
220 return -1;
221}
struct GNUNET_CRYPTO_EddsaSignature eddsa_signature
AN EdDSA signature.
struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature
An ECDSA signature.
uint32_t type
Type of signature.

References GNUNET_CRYPTO_Signature::ecdsa_signature, GNUNET_CRYPTO_Signature::eddsa_signature, GNUNET_break, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, and GNUNET_CRYPTO_Signature::type.

Referenced by get_message_size(), GNUNET_CRYPTO_read_signature_from_buffer(), GNUNET_CRYPTO_write_signature_to_buffer(), handle_client_call_message(), and hash_message().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_signature_get_raw_length_by_type()

ssize_t GNUNET_CRYPTO_signature_get_raw_length_by_type ( uint32_t  type)

Get the compacted length of a signature by type.

Compacted means that it returns the minimum number of bytes this signature is long, as opposed to the union structure inside GNUNET_CRYPTO_Signature. Useful for compact serializations.

Parameters
sigthe signature.
Returns
-1 on error, else the compacted length of the signature.

Definition at line 225 of file crypto_pkey.c.

226{
227 switch (ntohl (type))
228 {
230 return sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
231 break;
233 return sizeof (struct GNUNET_CRYPTO_EddsaSignature);
234 break;
235 default:
236 GNUNET_break (0);
237 }
238 return -1;
239}
static uint32_t type
Type string converted to DNS type value.
an ECC signature using ECDSA
an ECC signature using EdDSA.

References GNUNET_break, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, and type.

Referenced by GNUNET_GNSRECORD_proof_get_size().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_read_signature_from_buffer()

ssize_t GNUNET_CRYPTO_read_signature_from_buffer ( struct GNUNET_CRYPTO_Signature sig,
const void *  buffer,
size_t  len 
)

Reads a GNUNET_CRYPTO_Signature from a compact buffer.

The buffer has to contain at least the compacted length of a GNUNET_CRYPTO_Signature in bytes. If the buffer is too small, the function returns -1 as error. If the buffer does not contain a valid key, it returns -2 as error.

Parameters
sigthe signature
bufferthe buffer
lenthe length of buffer
Returns
-1 or -2 on error, else the amount of bytes read from the buffer

Definition at line 243 of file crypto_pkey.c.

247{
248 if (len < sizeof (sig->type))
249 return -1;
250 GNUNET_memcpy (&(sig->type), buffer, sizeof (sig->type));
251 const ssize_t length = GNUNET_CRYPTO_signature_get_length (sig);
252 if (len < length)
253 return -1;
254 if (length < 0)
255 return -2;
256 GNUNET_memcpy (&(sig->ecdsa_signature), buffer + sizeof (sig->type), length
257 - sizeof (sig->type));
258 return length;
259}
ssize_t GNUNET_CRYPTO_signature_get_length(const struct GNUNET_CRYPTO_Signature *sig)
Get the compacted length of a GNUNET_CRYPTO_Signature.
Definition: crypto_pkey.c:206

References GNUNET_CRYPTO_Signature::ecdsa_signature, GNUNET_CRYPTO_signature_get_length(), GNUNET_memcpy, and GNUNET_CRYPTO_Signature::type.

Referenced by decode_message(), and handle_cadet_ring_message().

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

◆ GNUNET_CRYPTO_write_signature_to_buffer()

ssize_t GNUNET_CRYPTO_write_signature_to_buffer ( const struct GNUNET_CRYPTO_Signature sig,
void *  buffer,
size_t  len 
)

Writes a GNUNET_CRYPTO_Signature to a compact buffer.

The buffer requires space for at least the compacted length of a GNUNET_CRYPTO_Signature in bytes. If the buffer is too small, the function returns -1 as error. If the key is not valid, it returns -2 as error.

Parameters
sigthe signature
bufferthe buffer
lenthe length of buffer
Returns
-1 or -2 on error, else the amount of bytes written to the buffer

Definition at line 263 of file crypto_pkey.c.

267{
268 const ssize_t length = GNUNET_CRYPTO_signature_get_length (sig);
269 if (len < length)
270 return -1;
271 if (length < 0)
272 return -2;
273 GNUNET_memcpy (buffer, &(sig->type), sizeof (sig->type));
274 GNUNET_memcpy (buffer + sizeof (sig->type), &(sig->ecdsa_signature), length
275 - sizeof (sig->type));
276 return length;
277}

References GNUNET_CRYPTO_Signature::ecdsa_signature, GNUNET_CRYPTO_signature_get_length(), GNUNET_memcpy, and GNUNET_CRYPTO_Signature::type.

Referenced by handle_client_call_message().

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

◆ GNUNET_CRYPTO_sign_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_ ( const struct GNUNET_CRYPTO_PrivateKey priv,
const struct GNUNET_CRYPTO_EccSignaturePurpose purpose,
struct GNUNET_CRYPTO_Signature sig 
)

Sign a given block.

The purpose data is the beginning of the data of which the signature is to be created. The size field in purpose must correctly indicate the number of bytes of the data structure, including its header. If possible, use GNUNET_CRYPTO_sign() instead of this function.

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

Definition at line 308 of file crypto_pkey.c.

313{
314 sig->type = priv->type;
315 switch (ntohl (priv->type))
316 {
318 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose,
319 &(sig->ecdsa_signature));
320 break;
322 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose,
323 &(sig->eddsa_signature));
324 break;
325 default:
326 GNUNET_break (0);
327 }
328
329 return GNUNET_SYSERR;
330}
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.
Definition: crypto_ecc.c:625

References GNUNET_CRYPTO_PrivateKey::ecdsa_key, GNUNET_CRYPTO_Signature::ecdsa_signature, GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_CRYPTO_Signature::eddsa_signature, GNUNET_break, GNUNET_CRYPTO_ecdsa_sign_(), GNUNET_CRYPTO_eddsa_sign_(), GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, GNUNET_CRYPTO_PrivateKey::type, and GNUNET_CRYPTO_Signature::type.

Referenced by GNUNET_ABD_delegate_issue(), and OIDC_build_authz_code().

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

◆ GNUNET_CRYPTO_sign_raw_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_raw_ ( const struct GNUNET_CRYPTO_PrivateKey priv,
const struct GNUNET_CRYPTO_EccSignaturePurpose purpose,
unsigned char *  sig 
)

Sign a given block.

The purpose data is the beginning of the data of which the signature is to be created. The size field in purpose must correctly indicate the number of bytes of the data structure, including its header. The signature payload and length depends on the key type.

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

Definition at line 281 of file crypto_pkey.c.

286{
287 switch (ntohl (priv->type))
288 {
290 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose,
291 (struct
293 break;
295 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose,
296 (struct
298 break;
299 default:
300 GNUNET_break (0);
301 }
302
303 return GNUNET_SYSERR;
304}

References GNUNET_CRYPTO_PrivateKey::ecdsa_key, GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_break, GNUNET_CRYPTO_ecdsa_sign_(), GNUNET_CRYPTO_eddsa_sign_(), GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, and GNUNET_CRYPTO_PrivateKey::type.

Referenced by sign_pow_identity().

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

◆ GNUNET_CRYPTO_signature_verify_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_signature_verify_ ( uint32_t  purpose,
const struct GNUNET_CRYPTO_EccSignaturePurpose validate,
const struct GNUNET_CRYPTO_Signature sig,
const struct GNUNET_CRYPTO_PublicKey pub 
)

Verify a given signature.

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

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

Definition at line 334 of file crypto_pkey.c.

339{
340 /* check type matching of 'sig' and 'pub' */
341 GNUNET_assert (ntohl (pub->type) == ntohl (sig->type));
342 switch (ntohl (pub->type))
343 {
345 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate,
346 &(sig->ecdsa_signature),
347 &(pub->ecdsa_key));
348 break;
350 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate,
351 &(sig->eddsa_signature),
352 &(pub->eddsa_key));
353 break;
354 default:
355 GNUNET_break (0);
356 }
357
358 return GNUNET_SYSERR;
359}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:649
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:708

References GNUNET_CRYPTO_Signature::ecdsa_signature, GNUNET_CRYPTO_Signature::eddsa_signature, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_ecdsa_verify_(), GNUNET_CRYPTO_eddsa_verify_(), GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, pub, and GNUNET_CRYPTO_Signature::type.

Referenced by GNUNET_ABD_delegate_deserialize(), GNUNET_ABD_delegate_serialize(), and OIDC_parse_authz_code().

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

◆ GNUNET_CRYPTO_signature_verify_raw_()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_signature_verify_raw_ ( uint32_t  purpose,
const struct GNUNET_CRYPTO_EccSignaturePurpose validate,
const unsigned char *  sig,
const struct GNUNET_CRYPTO_PublicKey pub 
)

Verify a given signature.

The validate data is the beginning of the data of which the signature is to be verified. The size field in validate must correctly indicate the number of bytes of the data structure, including its header. If purpose does not match the purpose given in validate (the latter must be in big endian), signature verification fails.

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

Definition at line 363 of file crypto_pkey.c.

370{
371 switch (ntohl (pub->type))
372 {
374 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate,
375 (struct
377 &(pub->ecdsa_key));
378 break;
380 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate,
381 (struct
383 &(pub->eddsa_key));
384 break;
385 default:
386 GNUNET_break (0);
387 }
388
389 return GNUNET_SYSERR;
390}

References GNUNET_break, GNUNET_CRYPTO_ecdsa_verify_(), GNUNET_CRYPTO_eddsa_verify_(), GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, and pub.

Referenced by check_signature_identity().

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

◆ GNUNET_CRYPTO_public_key_to_string()

char * GNUNET_CRYPTO_public_key_to_string ( const struct GNUNET_CRYPTO_PublicKey key)

Creates a (Base32) string representation of the public key.

The resulting string encodes a compacted representation of the key. See also #GNUNET_CRYPTO_key_get_length.

Parameters
keythe key.
Returns
the string representation of the key, or NULL on error.

Definition at line 394 of file crypto_pkey.c.

References GNUNET_CRYPTO_public_key_get_length(), GNUNET_STRINGS_data_to_string_alloc(), key, and size.

Referenced by abd_value_to_string(), create_finished(), delegation_chain_fw_resolution_start(), DID_ego_to_did(), DID_pkey_to_did(), forward_resolution(), get_store_contact(), gns_value_to_string(), GNUNET_ABD_delegate_to_string(), GNUNET_GNSRECORD_pkey_to_zkey(), handle_intermediate_result(), handle_verify_result(), issue_ticket(), list_ego(), print_deleset(), print_ego(), save_member_session(), send_enter_room(), send_open_room(), store_cb(), and verify_member_session_as_sender().

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

◆ GNUNET_CRYPTO_private_key_to_string()

char * GNUNET_CRYPTO_private_key_to_string ( const struct GNUNET_CRYPTO_PrivateKey key)

Creates a (Base32) string representation of the private key.

The resulting string encodes a compacted representation of the key. See also #GNUNET_CRYPTO_key_get_length.

Parameters
keythe key.
Returns
the string representation of the key, or NULL on error.

Definition at line 404 of file crypto_pkey.c.

References GNUNET_CRYPTO_private_key_get_length(), GNUNET_STRINGS_data_to_string_alloc(), key, and size.

Referenced by create_finished(), display_record(), ego_get_all(), ego_get_response(), and print_ego().

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

◆ GNUNET_CRYPTO_public_key_from_string()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string ( const char *  str,
struct GNUNET_CRYPTO_PublicKey key 
)

Parses a (Base32) string representation of the public key.

See also GNUNET_CRYPTO_public_key_to_string.

Parameters
strthe encoded key.
keywhere to write the key.
Returns
GNUNET_SYSERR on error.

Definition at line 414 of file crypto_pkey.c.

416{
419 strlen (str),
420 key,
421 sizeof (*key));
422 if (GNUNET_OK != ret)
423 return GNUNET_SYSERR;
424 return check_key_type (ntohl (key->type));
425
426}
static enum GNUNET_GenericReturnValue check_key_type(uint32_t type)
Definition: crypto_pkey.c:32

References check_key_type(), GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, key, and ret.

Referenced by abd_string_to_value(), authorize_endpoint(), code_redirect(), consume_fail(), consume_ticket(), create_response(), DID_did_to_pkey(), DID_public_key_from_did(), get_identity_for_string(), gns_string_to_value(), GNUNET_ABD_delegate_from_string(), GNUNET_GNS_lookup_with_tld(), GNUNET_GNS_parse_ztld(), GNUNET_GNSRECORD_zkey_to_pkey(), identity_cb(), load_member_session(), load_member_session_next(), run(), run_with_zone_pkey(), sign_cb(), tld_iter(), and write_encrypted_message().

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

◆ GNUNET_CRYPTO_private_key_from_string()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_private_key_from_string ( const char *  str,
struct GNUNET_CRYPTO_PrivateKey key 
)

Parses a (Base32) string representation of the private key.

See also GNUNET_CRYPTO_private_key_to_string.

Parameters
strthe encoded key.
keywhere to write the key.
Returns
GNUNET_SYSERR on error.

Definition at line 430 of file crypto_pkey.c.

432{
435 strlen (str),
436 key,
437 sizeof (*key));
438 if (GNUNET_OK != ret)
439 return GNUNET_SYSERR;
440 return check_key_type (ntohl (key->type));
441}

References check_key_type(), GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, key, and ret.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_key_get_public()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public ( const struct GNUNET_CRYPTO_PrivateKey privkey,
struct GNUNET_CRYPTO_PublicKey key 
)

Retrieves the public key representation of a private key.

Parameters
privkeythe private key.
keythe public key result.
Returns
GNUNET_SYSERR on error.

Definition at line 445 of file crypto_pkey.c.

448{
449 key->type = privkey->type;
450 switch (ntohl (privkey->type))
451 {
454 &key->ecdsa_key);
455 break;
458 &key->eddsa_key);
459 break;
460 default:
461 GNUNET_break (0);
462 return GNUNET_SYSERR;
463 }
464 return GNUNET_OK;
465}
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:201
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.
Definition: crypto_ecc.c:190

References GNUNET_CRYPTO_PrivateKey::ecdsa_key, GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_break, GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_OK, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, key, and GNUNET_CRYPTO_PrivateKey::type.

Referenced by attr_iter_cb(), authorize_endpoint(), create_finished(), create_message_join(), create_message_key(), cred_iter_cb(), dequeue_message_from_room(), DID_create_namestore_lookup_cb(), get_nick_record(), GNUNET_ABD_delegate_issue(), GNUNET_GNSRECORD_block_calculate_size(), GNUNET_GNSRECORD_block_create(), GNUNET_GNSRECORD_block_sign(), GNUNET_GNSRECORD_query_from_private_key(), GNUNET_IDENTITY_ego_get_public_key(), handle_attribute_store_message(), handle_client_call_message(), handle_collect(), handle_credential_store_message(), identity_zone_cb(), issue_ticket(), run_edkey(), run_pkey(), run_with_key(), set_handle_key(), and sign_pow().

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

◆ GNUNET_OP_create()

struct GNUNET_OP_Handle * GNUNET_OP_create ( )

Create new operations handle.

◆ GNUNET_OP_destroy()

void GNUNET_OP_destroy ( struct GNUNET_OP_Handle *  h)

Destroy operations handle.

◆ GNUNET_OP_get_next_id()

uint64_t GNUNET_OP_get_next_id ( struct GNUNET_OP_Handle *  h)

Get a unique operation ID to distinguish between asynchronous requests.

Parameters
hOperations handle.
Returns
Operation ID to use.

◆ GNUNET_OP_get()

int GNUNET_OP_get ( struct GNUNET_OP_Handle *  h,
uint64_t  op_id,
GNUNET_ResultCallback result_cb,
void **  cls,
void **  ctx 
)

Find operation by ID.

Parameters
hOperations handle.
op_idOperation ID to look up.
[out]result_cbIf an operation was found, its result callback is returned here.
[out]clsIf an operation was found, its closure is returned here.
[out]ctxUser context.
Returns
GNUNET_YES if an operation was found, GNUNET_NO if not found.

◆ GNUNET_OP_add()

uint64_t GNUNET_OP_add ( struct GNUNET_OP_Handle *  h,
GNUNET_ResultCallback  result_cb,
void *  cls,
void *  ctx 
)

Add a new operation.

Parameters
hOperations handle.
result_cbFunction to call with the result of the operation.
clsClosure for result_cb.
ctxUser context.
Returns
ID of the new operation.

◆ GNUNET_OP_result()

int GNUNET_OP_result ( struct GNUNET_OP_Handle *  h,
uint64_t  op_id,
int64_t  result_code,
const void *  data,
uint16_t  data_size,
void **  ctx 
)

Call the result callback of an operation and remove it.

Parameters
hOperations handle.
op_idOperation ID.
result_codeResult of the operation.
dataData result of the operation.
data_sizeSize of data.
[out]ctxUser context.
Returns
GNUNET_YES if the operation was found and removed, GNUNET_NO if the operation was not found.

◆ GNUNET_OP_remove()

int GNUNET_OP_remove ( struct GNUNET_OP_Handle *  h,
uint64_t  op_id 
)

Remove / cancel an operation.

Parameters
hOperations handle.
op_idOperation ID.
Returns
GNUNET_YES if the operation was found and removed, GNUNET_NO if the operation was not found.

Variable Documentation

◆ bits [1/3]

uint32_t GNUNET_HashCode::bits[512/8/sizeof(uint32_t)]

◆ bits [2/3]

uint32_t GNUNET_ShortHashCode::bits[256/8/sizeof(uint32_t)]

Definition at line 293 of file gnunet_common.h.

◆ value

uint32_t GNUNET_Uuid::value[4]

128 random bits.

Definition at line 310 of file gnunet_common.h.

◆ size

uint16_t GNUNET_MessageHeader::size

The length of the struct (in bytes, including the length field itself), in big-endian format.

Definition at line 323 of file gnunet_common.h.

Referenced by announce_id(), barrier_reached_run(), cadet_mq_send_impl(), callback_download(), check_add_global_address(), check_address_change_notification(), check_advertisement(), check_alice_client_message(), check_alice_client_message_multipart(), check_alices_cryptodata_message(), check_arm_list_result(), check_attribute_delete_message(), check_attribute_result(), check_attribute_store_message(), check_backchannel_encapsulation(), check_bob_client_message(), check_bob_client_message_multipart(), check_bobs_cryptodata_message(), check_bobs_cryptodata_multipart(), check_client_hello(), check_client_keygen(), check_client_redirect_to_ip(), check_client_result(), check_client_seed(), check_client_send(), check_client_start_search(), check_collect(), check_communicator_available(), check_communicator_backchannel(), check_connection_create(), check_connection_reversal_request(), check_consume_ticket_message(), check_consume_ticket_result(), check_create_message(), check_credential_delete_message(), check_credential_iteration_start(), check_credential_result(), check_credential_store_message(), check_data(), check_delete_message(), check_dht_local_get_result_seen(), check_dht_local_hello_offer(), check_dht_p2p_put(), check_dht_p2p_result(), check_dv_box(), check_dv_learn(), check_edit_record_set(), check_edit_record_set_cancel(), check_edit_record_set_response(), check_flow_control(), check_fragment_box(), check_get(), check_get_path(), check_helper_init(), check_identity_result_code(), check_identity_update(), check_incoming_msg(), check_index_info(), check_index_start_failed(), check_issue_ticket_message(), check_iterate_start(), check_iteration_start(), check_local_data(), check_lookup(), check_lookup_result(), check_monitor_get_resp(), check_monitor_notify(), check_monitor_put(), check_monitor_start(), check_notify_inbound(), check_p2p_get(), check_p2p_revoke(), check_peer_pull_reply(), check_query_message(), check_record_lookup(), check_record_result(), check_record_store(), check_recv(), check_recv_message(), check_register(), check_reliability_ack(), check_reliability_box(), check_rename_message(), check_request(), check_request_connection_reversal(), check_response(), check_result(), check_revoke_message(), check_revoke_ticket_message(), check_room_initial_key(), check_search(), check_send_message(), check_set(), check_statistics_value(), check_status(), check_stream_input(), check_stun(), check_ticket_iteration_start(), check_ticket_result(), check_tunnel_message(), check_union_p2p_ibf(), check_union_p2p_inquiry(), check_union_p2p_strata_estimator(), check_use_ip(), check_verify(), check_view_update(), check_watch(), check_zone_to_name_response(), consider_for_advertising(), consider_sending_fc(), consider_ss_ack(), core_mq_send_impl(), create_rekey(), demultiplex_with_cmc(), do_pad(), do_restart_typemap_message(), do_send(), enc_notify_cb(), encapsulate_for_dv(), execute_add(), execute_remove(), extract_box_cb(), find_advertisable_hello(), forward_dv_box(), forward_dv_learn(), fragment_message(), GCCH_handle_channel_plaintext_data(), GCCH_handle_local_data(), GCP_set_hello(), GCT_handle_encrypted(), GCT_send(), GCT_send_channel_destroy(), GDS_helper_make_put_message(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_reply(), GNUNET_copy_message(), GNUNET_HELLO_builder_from_msg(), GNUNET_HELLO_builder_to_dht_hello_msg(), GNUNET_HELLO_dht_msg_to_block(), GNUNET_HELPER_send(), GNUNET_MQ_extract_nested_mh_(), GNUNET_MQ_msg_(), GNUNET_MQ_msg_copy(), GNUNET_MQ_msg_nested_mh_(), GNUNET_MQ_send(), GNUNET_MQ_send_copy(), GNUNET_MST_from_buffer(), GNUNET_NAT_register(), GNUNET_PEERSTORE_hello_add(), GNUNET_TRANSPORT_communicator_notify(), GNUNET_TRANSPORT_communicator_receive(), got_hello(), GSC_CLIENTS_deliver_message(), GSC_SESSIONS_confirm_typemap(), GSC_SESSIONS_set_typemap(), GSC_SESSIONS_transmit(), GSC_TYPEMAP_compute_type_map_message(), GSC_TYPEMAP_get_from_message(), handle_add_address(), handle_add_queue_message(), handle_address_change_notification(), handle_arm_list_result(), handle_autoconfig_request(), handle_backchannel_encapsulation(), handle_block_cache(), handle_cadet_audio_message(), handle_call_audio(), handle_client_audio_message(), handle_client_decrypt(), handle_client_init(), handle_client_insert(), handle_client_redirect_to_ip(), handle_client_response(), handle_client_send(), handle_client_set_add(), handle_client_start_search(), handle_communicator_available(), handle_communicator_backchannel(), handle_connection_create(), handle_core_message(), handle_data(), handle_dht_local_get_result_seen(), handle_dht_local_put(), handle_dht_p2p_put(), handle_dht_p2p_result(), handle_dns_request(), handle_dns_response(), handle_dummy(), handle_dv_box(), handle_fragment_box(), handle_get(), handle_get_path(), handle_helper_barrier_reached(), handle_helper_init(), handle_icmp_back(), handle_icmp_remote(), handle_icmp_service(), handle_identity_update(), handle_incoming_msg(), handle_intersection_p2p_bf(), handle_iter_element(), handle_local_data(), handle_lookup_block_response(), handle_monitor_get_resp(), handle_monitor_put(), handle_new_element(), handle_p2p_get(), handle_p2p_put(), handle_phone_audio(), handle_plaintext_data(), handle_put(), handle_record_store(), handle_recv(), handle_recv_message(), handle_register(), handle_reliability_ack(), handle_reply(), handle_request(), handle_response(), handle_result(), handle_send_message(), handle_set(), handle_statistics_value(), handle_status(), handle_tcp_back(), handle_tunnel_message(), handle_udp_back(), handle_udp_remote(), handle_udp_service(), handle_union_p2p_elements(), handle_union_p2p_full_element(), handle_union_p2p_ibf(), handle_union_p2p_inquiry(), handle_union_p2p_strata_estimator(), handle_validation_challenge(), handle_verify(), handle_watch(), handle_zone_to_name_it(), hello_add_iter(), host_processor(), impl_send_continue(), initialize_handle_via_key(), inject_message(), inject_rekey(), main(), make_peer(), message_token(), monitor_notify_all(), mq_send(), mq_send_d(), mq_send_impl(), notify_listeners(), on_appsink_new_sample(), pass_plaintext_to_core(), PEERSTORE_parse_record_message(), play(), process_client_result(), process_helper_messages(), process_helper_msgs(), process_notify(), process_record_messages(), publicize_rm(), queue_finish(), queue_send_msg(), recv_from_streams(), recv_message(), reliability_box_message(), route_message(), route_via_neighbour(), run(), save(), schedule_next_hello(), select_read_cb(), select_write_cb(), send_challenge(), send_channel_data_ack(), send_channel_open(), send_icmp_packet_via_tun(), send_keepalive(), send_msg_with_kx(), send_open_ack(), send_start_messages(), send_tcp_packet_via_tun(), send_udp_packet_via_tun(), service_client_mst_cb(), service_mq_send(), set_listen_cb(), setup_estimate_message(), setup_flood_message(), sign_ephemeral_key(), start_dv_learn(), stdin_receiver(), task_start_reconcile(), tokenized_cb(), transmit_cummulative_ack_cb(), transmit_ready(), transmit_typemap_task(), try_handle_plaintext(), try_transmission(), validation_transmit_on_queue(), write_message(), and write_page().

◆ type [1/2]

uint16_t GNUNET_MessageHeader::type

The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.

Definition at line 328 of file gnunet_common.h.

Referenced by check_local_data(), check_reliability_box(), check_union_p2p_strata_estimator(), connection_client_send_impl(), consider_sending_fc(), consider_ss_ack(), create_rekey(), demultiplex_with_cmc(), do_send(), enc_notify_cb(), encapsulate_for_dv(), execute_add(), execute_mutation(), execute_remove(), finished_cb(), forward_dv_learn(), fragment_message(), GCCH_handle_local_data(), GCCH_is_type_to_drop(), GCT_send_channel_destroy(), GDS_helper_make_put_message(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_reply(), get_app(), GNUNET_HELLO_builder_from_msg(), GNUNET_HELLO_builder_get_expiration_time(), GNUNET_HELLO_builder_to_dht_hello_msg(), GNUNET_HELLO_dht_msg_to_block(), GNUNET_MQ_destroy(), GNUNET_MQ_msg_(), GNUNET_MQ_send(), GNUNET_MQ_send_cancel(), GNUNET_MST_from_buffer(), GNUNET_NAT_register(), GNUNET_TESTING_loop_notify_children_(), GSC_CLIENTS_deliver_message(), GSC_SESSIONS_set_typemap(), GSC_TYPEMAP_compute_type_map_message(), GSC_TYPEMAP_get_from_message(), handle_backchannel_encapsulation(), handle_client_send(), handle_communicator_backchannel(), handle_dht_local_monitor(), handle_dht_local_monitor_stop(), handle_get(), handle_get_key(), handle_get_zero_anonymity(), handle_icmp_back(), handle_icmp_remote(), handle_icmp_service(), handle_monitor_get(), handle_monitor_get_resp(), handle_monitor_put(), handle_raw_message(), handle_recv(), handle_reliability_box(), handle_tcp_back(), handle_udp_back(), handle_union_p2p_strata_estimator(), handle_validation_challenge(), impl_send_continue(), inject_rekey(), main(), message_token(), monitor_notify_all(), mq_send(), mq_send_impl(), notify_listeners(), play(), process_helper_msgs(), process_record_messages(), queue_finish(), recv_message(), reliability_box_message(), request_done(), route_control_message_without_fc(), route_message(), route_via_neighbour(), run(), save(), send_challenge(), send_channel_data_ack(), send_channel_open(), send_icmp_packet_via_tun(), send_keepalive(), send_open_ack(), send_start_messages(), send_tcp_packet_via_tun(), send_udp_packet_via_tun(), service_client_mst_cb(), service_mq_send(), set_listen_cb(), setup_estimate_message(), setup_flood_message(), sign_ephemeral_key(), start_dv_learn(), stdin_receiver(), task_start_reconcile(), tokenized_cb(), transmit_content(), transmit_cummulative_ack_cb(), transmit_ready(), try_handle_plaintext(), validation_transmit_on_queue(), and write_message().

◆ header

struct GNUNET_MessageHeader GNUNET_OperationResultMessage::header

Definition at line 337 of file gnunet_common.h.

◆ reserved

uint32_t GNUNET_OperationResultMessage::reserved

Definition at line 339 of file gnunet_common.h.

◆ op_id

uint64_t GNUNET_OperationResultMessage::op_id

Operation ID.

Definition at line 344 of file gnunet_common.h.

◆ result_code

uint64_t GNUNET_OperationResultMessage::result_code

Status code for the operation.

Definition at line 349 of file gnunet_common.h.

◆ bits [3/3]

uint32_t GNUNET_AsyncScopeId::bits[16/sizeof(uint32_t)]

Definition at line 360 of file gnunet_common.h.

◆ scope_id

struct GNUNET_AsyncScopeId GNUNET_AsyncScopeSave::scope_id

Saved scope.

Unused if 'have_scope==GNUNET_NO'.

Definition at line 374 of file gnunet_common.h.

Referenced by GNUNET_async_scope_enter(), GNUNET_SCHEDULER_do_work(), output_message(), and setup_job_headers().

◆ have_scope

int GNUNET_AsyncScopeSave::have_scope

GNUNET_YES unless this saved scope is the unnamed root scope.

Definition at line 379 of file gnunet_common.h.

Referenced by GNUNET_async_scope_enter(), GNUNET_SCHEDULER_do_work(), output_message(), and setup_job_headers().

◆ mv

GNUNET_MQ_MessageValidationCallback GNUNET_MQ_MessageHandler::mv

Callback to validate a message of the specified type.

The closure given to mv will be this struct (not ctx). Using NULL means only size-validation using expected_size. In this case, expected_size must be non-zero.

Definition at line 501 of file gnunet_mq_lib.h.

Referenced by GNUNET_MQ_copy_handlers2().

◆ cb

GNUNET_MQ_MessageCallback GNUNET_MQ_MessageHandler::cb

Callback, called every time a new message of the specified type has been received.

The closure given to mv will be this struct (not ctx).

Definition at line 508 of file gnunet_mq_lib.h.

Referenced by GNUNET_MQ_copy_handlers2(), and GNUNET_MQ_set_handlers_closure().

◆ cls

void* GNUNET_MQ_MessageHandler::cls

◆ type [2/2]

uint16_t GNUNET_MQ_MessageHandler::type

Type of the message this handler covers, in host byte order.

Definition at line 518 of file gnunet_mq_lib.h.

Referenced by GNUNET_MQ_copy_handlers2().

◆ expected_size

uint16_t GNUNET_MQ_MessageHandler::expected_size

Expected size of messages of this type.

Minimum size of the message if mv is non-NULL. Messages of the given type will be discarded (and the connection closed with an error reported to the application) if they do not have the right size.

Definition at line 526 of file gnunet_mq_lib.h.

Referenced by GNUNET_MQ_copy_handlers2().