GNUnet 0.22.0
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_ElligatorEcdhePrivateKey
 Special private ECC key generated by GNUNET_CRYPTO_ecdhe_elligator_key_create. 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 98 of file gnunet_common.h.

◆ GNUNET_MIN

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

Definition at line 117 of file gnunet_common.h.

◆ GNUNET_MAX

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

Definition at line 119 of file gnunet_common.h.

◆ BYTE_SWAP_16

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

Endian operations.

Definition at line 168 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 170 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 174 of file gnunet_common.h.

◆ GNUNET_htobe16 [1/2]

#define GNUNET_htobe16 (   x)    BYTE_SWAP_16 (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_htobe16 [2/2]

#define GNUNET_htobe16 (   x)    (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_htole16 [1/2]

#define GNUNET_htole16 (   x)    (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_htole16 [2/2]

#define GNUNET_htole16 (   x)    BYTE_SWAP_16 (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_be16toh [1/2]

#define GNUNET_be16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 205 of file gnunet_common.h.

◆ GNUNET_be16toh [2/2]

#define GNUNET_be16toh (   x)    (x)

Definition at line 205 of file gnunet_common.h.

◆ GNUNET_le16toh [1/2]

#define GNUNET_le16toh (   x)    (x)

Definition at line 206 of file gnunet_common.h.

◆ GNUNET_le16toh [2/2]

#define GNUNET_le16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 206 of file gnunet_common.h.

◆ GNUNET_htobe32 [1/2]

#define GNUNET_htobe32 (   x)    BYTE_SWAP_32 (x)

Definition at line 208 of file gnunet_common.h.

◆ GNUNET_htobe32 [2/2]

#define GNUNET_htobe32 (   x)    (x)

Definition at line 208 of file gnunet_common.h.

◆ GNUNET_htole32 [1/2]

#define GNUNET_htole32 (   x)    (x)

Definition at line 209 of file gnunet_common.h.

◆ GNUNET_htole32 [2/2]

#define GNUNET_htole32 (   x)    BYTE_SWAP_32 (x)

Definition at line 209 of file gnunet_common.h.

◆ GNUNET_be32toh [1/2]

#define GNUNET_be32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 210 of file gnunet_common.h.

◆ GNUNET_be32toh [2/2]

#define GNUNET_be32toh (   x)    (x)

Definition at line 210 of file gnunet_common.h.

◆ GNUNET_le32toh [1/2]

#define GNUNET_le32toh (   x)    (x)

Definition at line 211 of file gnunet_common.h.

◆ GNUNET_le32toh [2/2]

#define GNUNET_le32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 211 of file gnunet_common.h.

◆ GNUNET_htobe64 [1/2]

#define GNUNET_htobe64 (   x)    BYTE_SWAP_64 (x)

Definition at line 213 of file gnunet_common.h.

◆ GNUNET_htobe64 [2/2]

#define GNUNET_htobe64 (   x)    (x)

Definition at line 213 of file gnunet_common.h.

◆ GNUNET_htole64 [1/2]

#define GNUNET_htole64 (   x)    (x)

Definition at line 214 of file gnunet_common.h.

◆ GNUNET_htole64 [2/2]

#define GNUNET_htole64 (   x)    BYTE_SWAP_64 (x)

Definition at line 214 of file gnunet_common.h.

◆ GNUNET_be64toh [1/2]

#define GNUNET_be64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 215 of file gnunet_common.h.

◆ GNUNET_be64toh [2/2]

#define GNUNET_be64toh (   x)    (x)

Definition at line 215 of file gnunet_common.h.

◆ GNUNET_le64toh [1/2]

#define GNUNET_le64toh (   x)    (x)

Definition at line 216 of file gnunet_common.h.

◆ GNUNET_le64toh [2/2]

#define GNUNET_le64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 216 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 232 of file gnunet_common.h.

◆ GNUNET_PACKED

#define GNUNET_PACKED   __attribute__ ((packed))

gcc-ism to get packed structs.

Definition at line 238 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 253 of file gnunet_common.h.

◆ GNUNET_UNUSED

#define GNUNET_UNUSED   __attribute__ ((unused))

gcc-ism to document unused arguments

Definition at line 259 of file gnunet_common.h.

◆ GNUNET_NORETURN

#define GNUNET_NORETURN   __attribute__ ((noreturn))

gcc-ism to document functions that don't return

Definition at line 264 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 269 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 274 of file gnunet_common.h.

◆ GN_LIKELY

#define GN_LIKELY (   expr)    (expr)

Definition at line 517 of file gnunet_common.h.

◆ GN_UNLIKELY

#define GN_UNLIKELY (   expr)    (expr)

Definition at line 518 of file gnunet_common.h.

◆ GNUNET_LOG_CALL_STATUS

#define GNUNET_LOG_CALL_STATUS   -1

Definition at line 522 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 545 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 571 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 664 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 1055 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 1269 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 1298 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 1326 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 1339 of file gnunet_common.h.

◆ __func__

#define __func__   "<unknown>"

Definition at line 1854 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 532 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_AEAD_ID

#define GNUNET_CRYPTO_HPKE_AEAD_ID   0x0003

Definition at line 2121 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_NONCE_LEN

#define GNUNET_CRYPTO_HPKE_NONCE_LEN   12

Definition at line 2124 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_KEY_LEN

#define GNUNET_CRYPTO_HPKE_KEY_LEN   32

Definition at line 2127 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HPKE_TAG_LEN

#define GNUNET_CRYPTO_HPKE_TAG_LEN   16

Definition at line 2130 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 2133 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 2136 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:293
@ 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 4821 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 4894 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 404 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 420 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 1147 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 107 of file gnunet_common.h.

108{
109 GNUNET_SYSERR = -1,
110 GNUNET_NO = 0,
111 GNUNET_OK = 1,
112 /* intentionally identical to #GNUNET_OK! */
113 GNUNET_YES = 1,
114};
@ 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 1866 of file gnunet_common.h.

1867{
1872
1877
1883
1891
1897
1903
1911
1921
1927};
@ 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 379 of file gnunet_crypto_lib.h.

380{
386
392};
@ 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 2112 of file gnunet_crypto_lib.h.

2113{
2118};
@ 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 2140 of file gnunet_crypto_lib.h.

2141{
2144};
@ 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 2155 of file gnunet_crypto_lib.h.

2156{
2159};
@ 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 4012 of file gnunet_crypto_lib.h.

4013{
4014
4019
4024
4029};
@ 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 265 of file buffer.c.

268{
269 size_t outlen = data_len * 8;
270
271 if (outlen % 5 > 0)
272 outlen += 5 - outlen % 5;
273 outlen /= 5;
275 outlen);
276 GNUNET_assert (NULL !=
278 data_len,
279 (buf->mem
280 + buf->position),
281 outlen));
282 buf->position += outlen;
283 GNUNET_assert (buf->position <= buf->capacity);
284}
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 181 of file buffer.c.

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

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 231 of file buffer.c.

234{
235 int res;
236 va_list args2;
237
238 va_copy (args2, args);
239 res = vsnprintf (NULL, 0, fmt, args2);
240 va_end (args2);
241
242 GNUNET_assert (res >= 0);
244
245 va_copy (args2, args);
246 res = vsnprintf (buf->mem + buf->position, res + 1, fmt, args2);
247 va_end (args2);
248
249 GNUNET_assert (res >= 0);
250 buf->position += res;
251 GNUNET_assert (buf->position <= buf->capacity);
252}
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 void *res;
152 *size = buf->position;
153 res = buf->mem;
154 memset (buf, 0, sizeof (struct GNUNET_Buffer));
155 return res;
156}
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 165 of file buffer.c.

166{
167 GNUNET_free (buf->mem);
168 memset (buf, 0, sizeof (struct GNUNET_Buffer));
169}
#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:1618
@ 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:1660
#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:93
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 134 of file consttime_memcmp.c.

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

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(), create_receiver(), 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(), create_receiver(), 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(), create_receiver(), 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:65
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:1309
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
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:98
#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:33
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 1013 of file crypto_hpke.c.

1015{
1016 switch (ntohl (sk->type))
1017 {
1019 memcpy (x25519->d, sk->ecdsa_key.d,
1020 sizeof sk->ecdsa_key.d);
1021 return GNUNET_OK;
1023 if (0 != crypto_sign_ed25519_sk_to_curve25519 (x25519->d,
1024 sk->eddsa_key.d))
1025 return GNUNET_SYSERR;
1026 return GNUNET_OK;
1027 default:
1028 return GNUNET_SYSERR;
1029 }
1030 return GNUNET_SYSERR;
1031
1032}
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 989 of file crypto_hpke.c.

991{
992 switch (ntohl (pk->type))
993 {
995 if (0 != crypto_sign_ed25519_pk_to_curve25519 (x25519->q_y,
996 pk->ecdsa_key.q_y))
997 return GNUNET_SYSERR;
998 return GNUNET_OK;
1000 if (0 != crypto_sign_ed25519_pk_to_curve25519 (x25519->q_y,
1001 pk->eddsa_key.q_y))
1002 return GNUNET_SYSERR;
1003 return GNUNET_OK;
1004 default:
1005 return GNUNET_SYSERR;
1006 }
1007 return GNUNET_SYSERR;
1008
1009}
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 738 of file crypto_hpke.c.

742{
744 // skE, pkE = GenerateKeyPair()
746
750 &sk, NULL,
751 pkR, info, info_len,
752 NULL, 0,
753 NULL, 0,
754 enc,
755 ctx);
756}
#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:670
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 670 of file crypto_hpke.c.

681{
682 struct GNUNET_ShortHashCode shared_secret;
683
684 switch (mode)
685 {
689 {
691 &shared_secret))
692 return GNUNET_SYSERR;
693 break;
694 }
695 else if (kem ==
697 {
698 uint8_t random_tweak;
700 &random_tweak,
701 sizeof(uint8_t));
702 if (GNUNET_OK !=
704 pkR,
705 enc,
706 (struct
708 *) skE,
709 &shared_secret))
710 return GNUNET_SYSERR;
711 }
712 break;
715 if (NULL == skS)
716 return GNUNET_SYSERR;
718 enc, skE,
719 &shared_secret))
720 return GNUNET_SYSERR;
721 break;
722 default:
723 return GNUNET_SYSERR;
724 }
726 mode,
727 &shared_secret,
728 info, info_len,
729 psk, psk_len,
730 psk_id, psk_id_len,
731 ctx))
732 return GNUNET_SYSERR;
733 return GNUNET_OK;
734}
static 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:585
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(uint8_t random_tweak, const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret)
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephem...
Definition: crypto_hpke.c:423
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
Special private ECC key generated by GNUNET_CRYPTO_ecdhe_elligator_key_create.
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_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block(), 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 760 of file crypto_hpke.c.

770{
771 struct GNUNET_ShortHashCode shared_secret;
772
773 switch (mode)
774 {
778 {
780 &shared_secret))
781 return GNUNET_SYSERR;
782 }
783 else if (kem ==
785 {
787 enc,
788 &shared_secret))
789 return GNUNET_SYSERR;
790 }
791 break;
794 if (NULL == pkS)
795 return GNUNET_SYSERR;
797 enc,
798 &shared_secret))
799 return GNUNET_SYSERR;
800 break;
801 default:
802 return GNUNET_SYSERR;
803 }
805 mode,
806 &shared_secret,
807 info, info_len,
808 psk, psk_len,
809 psk_id, psk_id_len,
810 ctx))
811 return GNUNET_SYSERR;
812 return GNUNET_OK;
813}
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:470
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 817 of file crypto_hpke.c.

822{
826 enc, skR, NULL,
827 info, info_len,
828 NULL, 0, NULL, 0, ctx);
829}
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:760

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,