GNUnet 0.21.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_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_FoKemC
 This is the encapsulated key of our FO-KEM. 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_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...
 
#define GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES
 

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_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...
 
enum GNUNET_GenericReturnValue 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_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_ecdhe_elligator_initialize (void)
 Initializes the elligator library THis function is thread safe. 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...
 
ssize_t GNUNET_CRYPTO_encrypt_old (const void *block, size_t size, const struct GNUNET_CRYPTO_PublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
 Encrypt a block with GNUNET_CRYPTO_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is required for decryption using ecdh to derive a symmetric key. More...
 
ssize_t GNUNET_CRYPTO_decrypt_old (const void *block, size_t size, const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
 Decrypt a given block with GNUNET_CRYPTO_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_encrypt (const void *block, size_t size, const struct GNUNET_CRYPTO_PublicKey *pub, void *result, size_t result_size)
 Encrypt a block with GNUNET_CRYPTO_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is required for decryption using ecdh to derive a symmetric key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_decrypt (const void *block, size_t size, const struct GNUNET_CRYPTO_PrivateKey *priv, void *result, size_t result_size)
 Decrypt a given block with GNUNET_CRYPTO_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key. 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_HandleGNUNET_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

GNUNET_MQ_MessageValidationCallback GNUNET_MQ_MessageHandler::mv
 Callback to validate a message of the specified type. More...
 
GNUNET_MQ_MessageCallback GNUNET_MQ_MessageHandler::cb
 Callback, called every time a new message of the specified type has been received. More...
 
void * GNUNET_MQ_MessageHandler::cls
 Closure for mv and cb. More...
 
uint16_t GNUNET_MQ_MessageHandler::type
 Type of the message this handler covers, in host byte order. More...
 
uint16_t GNUNET_MQ_MessageHandler::expected_size
 Expected size of messages of this type. More...
 

Detailed Description

Multi-function utilities library for GNUnet programs.

Author
Christian Grothoff

Common buffer management functions.

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

Macro Definition Documentation

◆ GNUNET_UTIL_VERSION

#define GNUNET_UTIL_VERSION   0x000A0104

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

Definition at line 96 of file gnunet_common.h.

◆ GNUNET_MIN

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

Definition at line 115 of file gnunet_common.h.

◆ GNUNET_MAX

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

Definition at line 117 of file gnunet_common.h.

◆ BYTE_SWAP_16

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

Endian operations.

Definition at line 166 of file gnunet_common.h.

◆ BYTE_SWAP_32

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

Definition at line 168 of file gnunet_common.h.

◆ BYTE_SWAP_64

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

Definition at line 172 of file gnunet_common.h.

◆ GNUNET_htobe16 [1/2]

#define GNUNET_htobe16 (   x)    BYTE_SWAP_16 (x)

Definition at line 197 of file gnunet_common.h.

◆ GNUNET_htobe16 [2/2]

#define GNUNET_htobe16 (   x)    (x)

Definition at line 197 of file gnunet_common.h.

◆ GNUNET_htole16 [1/2]

#define GNUNET_htole16 (   x)    (x)

Definition at line 198 of file gnunet_common.h.

◆ GNUNET_htole16 [2/2]

#define GNUNET_htole16 (   x)    BYTE_SWAP_16 (x)

Definition at line 198 of file gnunet_common.h.

◆ GNUNET_be16toh [1/2]

#define GNUNET_be16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 199 of file gnunet_common.h.

◆ GNUNET_be16toh [2/2]

#define GNUNET_be16toh (   x)    (x)

Definition at line 199 of file gnunet_common.h.

◆ GNUNET_le16toh [1/2]

#define GNUNET_le16toh (   x)    (x)

Definition at line 200 of file gnunet_common.h.

◆ GNUNET_le16toh [2/2]

#define GNUNET_le16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 200 of file gnunet_common.h.

◆ GNUNET_htobe32 [1/2]

#define GNUNET_htobe32 (   x)    BYTE_SWAP_32 (x)

Definition at line 202 of file gnunet_common.h.

◆ GNUNET_htobe32 [2/2]

#define GNUNET_htobe32 (   x)    (x)

Definition at line 202 of file gnunet_common.h.

◆ GNUNET_htole32 [1/2]

#define GNUNET_htole32 (   x)    (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_htole32 [2/2]

#define GNUNET_htole32 (   x)    BYTE_SWAP_32 (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_be32toh [1/2]

#define GNUNET_be32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_be32toh [2/2]

#define GNUNET_be32toh (   x)    (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_le32toh [1/2]

#define GNUNET_le32toh (   x)    (x)

Definition at line 205 of file gnunet_common.h.

◆ GNUNET_le32toh [2/2]

#define GNUNET_le32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 205 of file gnunet_common.h.

◆ GNUNET_htobe64 [1/2]

#define GNUNET_htobe64 (   x)    BYTE_SWAP_64 (x)

Definition at line 207 of file gnunet_common.h.

◆ GNUNET_htobe64 [2/2]

#define GNUNET_htobe64 (   x)    (x)

Definition at line 207 of file gnunet_common.h.

◆ GNUNET_htole64 [1/2]

#define GNUNET_htole64 (   x)    (x)

Definition at line 208 of file gnunet_common.h.

◆ GNUNET_htole64 [2/2]

#define GNUNET_htole64 (   x)    BYTE_SWAP_64 (x)

Definition at line 208 of file gnunet_common.h.

◆ GNUNET_be64toh [1/2]

#define GNUNET_be64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 209 of file gnunet_common.h.

◆ GNUNET_be64toh [2/2]

#define GNUNET_be64toh (   x)    (x)

Definition at line 209 of file gnunet_common.h.

◆ GNUNET_le64toh [1/2]

#define GNUNET_le64toh (   x)    (x)

Definition at line 210 of file gnunet_common.h.

◆ GNUNET_le64toh [2/2]

#define GNUNET_le64toh (   x)    BYTE_SWAP_64 (x)

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

◆ GNUNET_PACKED

#define GNUNET_PACKED   __attribute__ ((packed))

gcc-ism to get packed structs.

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

◆ GNUNET_UNUSED

#define GNUNET_UNUSED   __attribute__ ((unused))

gcc-ism to document unused arguments

Definition at line 253 of file gnunet_common.h.

◆ GNUNET_NORETURN

#define GNUNET_NORETURN   __attribute__ ((noreturn))

gcc-ism to document functions that don't return

Definition at line 258 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 263 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 268 of file gnunet_common.h.

◆ GN_LIKELY

#define GN_LIKELY (   expr)    (expr)

Definition at line 509 of file gnunet_common.h.

◆ GN_UNLIKELY

#define GN_UNLIKELY (   expr)    (expr)

Definition at line 510 of file gnunet_common.h.

◆ GNUNET_LOG_CALL_STATUS

#define GNUNET_LOG_CALL_STATUS   -1

Definition at line 514 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 536 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 562 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 655 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 1009 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 1218 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 1247 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 1275 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 1288 of file gnunet_common.h.

◆ __func__

#define __func__   "<unknown>"

Definition at line 1788 of file gnunet_common.h.

◆ GNUNET_CONTAINER_LIB_H

#define GNUNET_CONTAINER_LIB_H

Definition at line 61 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_DLL_insert_sorted

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

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

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

Definition at line 2097 of file gnunet_container_lib.h.

◆ GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH

#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH   126

Maximum length of an ECC signature.

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

Definition at line 77 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_AES_KEY_LENGTH

#define GNUNET_CRYPTO_AES_KEY_LENGTH   (256 / 8)

length of the sessionkey in bytes (256 BIT sessionkey)

Definition at line 110 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_HASH_LENGTH

#define GNUNET_CRYPTO_HASH_LENGTH   (512 / 8)

Length of a hash value.

Definition at line 115 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_PKEY_ASCII_LENGTH

#define GNUNET_CRYPTO_PKEY_ASCII_LENGTH   52

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

Definition at line 121 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_PAILLIER_BITS

#define GNUNET_CRYPTO_PAILLIER_BITS   2048

Size of paillier plain texts and public keys.

Private keys and ciphertexts are twice this size.

Definition at line 519 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_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:291
@ 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 4234 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 4307 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES

#define GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES
Value:
(crypto_secretbox_MACBYTES \
+ sizeof (struct \
GNUNET_CRYPTO_FoKemC))

Definition at line 4365 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 398 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 414 of file gnunet_common.h.

◆ GNUNET_CRYPTO_HashCompletedCallback

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

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

Parameters
clsclosure
resresulting hash, NULL on error

Definition at line 1134 of file gnunet_crypto_lib.h.

Enumeration Type Documentation

◆ GNUNET_GenericReturnValue

Named constants for return values.

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

Enumerator
GNUNET_SYSERR 
GNUNET_NO 
GNUNET_OK 
GNUNET_YES 

Definition at line 105 of file gnunet_common.h.

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

◆ GNUNET_SCHEDULER_Priority

Valid task priorities.

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

Enumerator
GNUNET_SCHEDULER_PRIORITY_KEEP 

Run with the same priority as the current job.

GNUNET_SCHEDULER_PRIORITY_IDLE 

Run when otherwise idle.

GNUNET_SCHEDULER_PRIORITY_BACKGROUND 

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

GNUNET_SCHEDULER_PRIORITY_DEFAULT 

Run with the default priority (normal P2P operations).

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

GNUNET_SCHEDULER_PRIORITY_HIGH 

Run with high priority (important requests).

Higher than DEFAULT.

GNUNET_SCHEDULER_PRIORITY_UI 

Run with priority for interactive tasks.

Higher than "HIGH".

GNUNET_SCHEDULER_PRIORITY_URGENT 

Run with priority for urgent tasks.

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

GNUNET_SCHEDULER_PRIORITY_SHUTDOWN 

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

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

GNUNET_SCHEDULER_PRIORITY_COUNT 

Number of priorities (must be the last priority).

This priority must not be used by clients.

Definition at line 1800 of file gnunet_common.h.

1801{
1806
1811
1817
1825
1831
1837
1845
1855
1861};
@ GNUNET_SCHEDULER_PRIORITY_UI
Run with priority for interactive tasks.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
@ GNUNET_SCHEDULER_PRIORITY_URGENT
Run with priority for urgent tasks.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
@ GNUNET_SCHEDULER_PRIORITY_COUNT
Number of priorities (must be the last priority).
@ GNUNET_SCHEDULER_PRIORITY_KEEP
Run with the same priority as the current job.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
@ GNUNET_SCHEDULER_PRIORITY_SHUTDOWN
This is an internal priority level that is only used for tasks that are being triggered due to shutdo...

◆ GNUNET_CRYPTO_KeyType

Key type for the generic public key union.

Enumerator
GNUNET_PUBLIC_KEY_TYPE_ECDSA 

The identity type.

The value is the same as the PKEY record type.

GNUNET_PUBLIC_KEY_TYPE_EDDSA 

EDDSA identity.

The value is the same as the EDKEY record type.

Definition at line 366 of file gnunet_crypto_lib.h.

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

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

3426{
3427
3432
3437
3442};
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.

Function Documentation

◆ GNUNET_buffer_prealloc()

void GNUNET_buffer_prealloc ( struct GNUNET_Buffer buf,
size_t  capacity 
)

Initialize a buffer with the given capacity.

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

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

Definition at line 35 of file buffer.c.

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

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

◆ GNUNET_buffer_ensure_remaining()

void GNUNET_buffer_ensure_remaining ( struct GNUNET_Buffer buf,
size_t  n 
)

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

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

Definition at line 55 of file buffer.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_buffer_write()

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

Write bytes to the buffer.

Grows the buffer if necessary.

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

Definition at line 86 of file buffer.c.

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

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

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

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

◆ GNUNET_buffer_write_str()

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

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

Grows the buffer if necessary.

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

Definition at line 103 of file buffer.c.

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

References GNUNET_buffer_write().

Referenced by GNUNET_CONFIGURATION_serialize_diagnostics(), and login_redirect().

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

◆ GNUNET_buffer_write_data_encoded()

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

Write data encoded via GNUNET_STRINGS_data_to_string to the buffer.

Grows the buffer if necessary.

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

Definition at line 264 of file buffer.c.

267{
268 size_t outlen = data_len * 8;
269
270 if (outlen % 5 > 0)
271 outlen += 5 - outlen % 5;
272 outlen /= 5;
274 outlen);
275 GNUNET_assert (NULL !=
277 data_len,
278 (buf->mem
279 + buf->position),
280 outlen));
281 buf->position += outlen;
282 GNUNET_assert (buf->position <= buf->capacity);
283}
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:709

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

Here is the call graph for this function:

◆ GNUNET_buffer_write_path()

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

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

Parameters
bufbuffer to write to
strstring containing the new path component

Definition at line 180 of file buffer.c.

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

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

Here is the call graph for this function:

◆ GNUNET_buffer_write_fstr()

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

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

Grows the buffer if necessary.

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

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

Here is the caller graph for this function:

◆ GNUNET_buffer_write_vfstr()

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

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

Grows the buffer if necessary.

Parameters
bufthe buffer to write to
fmtformat string
argsformat argument list

Definition at line 230 of file buffer.c.

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

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

Referenced by GNUNET_buffer_write_fstr().

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

◆ GNUNET_buffer_reap_str()

char * GNUNET_buffer_reap_str ( struct GNUNET_Buffer buf)

Clear the buffer and return the string it contained.

The caller is responsible to eventually GNUNET_free the returned string.

The returned string is always 0-terminated.

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

Definition at line 123 of file buffer.c.

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

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

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

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

◆ GNUNET_buffer_reap()

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

Clear the buffer and return its contents.

The caller is responsible to eventually GNUNET_free the returned data.

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

Definition at line 149 of file buffer.c.

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

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

Referenced by GNUNET_BIO_get_buffer_contents().

Here is the caller graph for this function:

◆ GNUNET_buffer_clear()

void GNUNET_buffer_clear ( struct GNUNET_Buffer buf)

Free the backing memory of the given buffer.

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

Definition at line 164 of file buffer.c.

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

References GNUNET_free, and GNUNET_Buffer::mem.

Referenced by GNUNET_BIO_write_close(), and GNUNET_STRINGS_urlencode().

Here is the caller graph for this function:

◆ GNUNET_wait_child()

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

Starts the handling of the child processes.

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

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

Definition at line 198 of file child_management.c.

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

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

◆ GNUNET_get_log_call_status()

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

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

Used internally by GNUNET_log*()

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

Definition at line 500 of file common_logging.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_b2s()

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

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

This is used for logging binary data when debugging.

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

Definition at line 324 of file common_logging.c.

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

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

Here is the call graph for this function:

◆ GNUNET_htonll()

uint64_t GNUNET_htonll ( uint64_t  n)

Convert unsigned 64-bit integer to network byte order.

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

Definition at line 37 of file common_endian.c.

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

Referenced by abd_string_to_value(), block_proc(), change_service(), commit_set(), consider_sending_fc(), create_loc_uri(), determine_id(), GCCH_handle_channel_plaintext_data_ack(), GNUNET_ABD_delegate_issue(), GNUNET_ABD_delegate_serialize(), GNUNET_ABD_delegates_serialize(), GNUNET_ARM_request_service_list(), GNUNET_BIO_write_int64(), GNUNET_CRYPTO_ecc_scalar_from_int(), GNUNET_CRYPTO_random_timeflake(), GNUNET_DATASTORE_get_key(), GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_DATASTORE_reserve(), GNUNET_FS_tree_encoder_next(), GNUNET_GNSRECORD_pow_round(), GNUNET_GNSRECORD_records_serialize(), GNUNET_hton_double(), GNUNET_NAMESTORE_zone_iterator_next(), GNUNET_NAMESTORE_zone_monitor_next(), GNUNET_PEERSTORE_iteration_next(), GNUNET_PEERSTORE_monitor_next(), GNUNET_RECLAIM_attribute_store(), GNUNET_RECLAIM_credential_store(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_hton(), handle_client_accept(), hash_for_index_cb(), notify_change(), print_record(), qconv_abs_time(), qconv_array(), 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_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(), print_record(), process_result_with_request(), queue_send_msg(), reconstruct_cb(), set_result_cb(), try_match_block(), uri_chk_to_string(), uri_loc_to_string(), and verify_message_crypto().

◆ GNUNET_hton_double()

double GNUNET_hton_double ( double  d)

Convert double to network byte order.

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

Definition at line 70 of file common_endian.c.

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

References d, GNUNET_htonll(), and res.

Referenced by setup_estimate_message().

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

◆ GNUNET_ntoh_double()

double GNUNET_ntoh_double ( double  d)

Convert double to host byte order.

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

Definition at line 83 of file common_endian.c.

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

References d, GNUNET_ntohll(), and res.

Referenced by handle_estimate().

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

◆ GNUNET_memcmp_ct_()

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

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

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

Definition at line 131 of file consttime_memcmp.c.

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

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

◆ GNUNET_is_zero_()

enum GNUNET_GenericReturnValue 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
GNUNET_YES if a is zero, GNUNET_NO otherwise

Definition at line 492 of file common_allocation.c.

494{
495 const char *b = a;
496
497 for (size_t i = 0; i < n; i++)
498 if (b[i])
499 return GNUNET_NO;
500 return GNUNET_YES;
501}

References GNUNET_NO, and GNUNET_YES.

◆ 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

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

Parameters
sizehow many bytes of memory to allocate, do NOT use this function (or GNUNET_malloc()) to allocate more than several MB of memory, if you are possibly needing a very large chunk use GNUNET_xmalloc_unchecked_() instead.
filenamewhere in the code was the call to GNUNET_malloc()
linenumberwhere in the code was the call to GNUNET_malloc()
Returns
pointer to size bytes of memory

Definition at line 60 of file common_allocation.c.

61{
62 void *ret;
63
64 /* As a security precaution, we generally do not allow very large
65 * allocations using the default 'GNUNET_malloc()' macro */
68 if (NULL == ret)
69 {
71 GNUNET_assert (0);
72 }
73 return ret;
74}
#define LOG_STRERROR(kind, syscall)
static char * filename
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Wrapper around malloc().
#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 92 of file common_allocation.c.

97{
98 /* use char pointer internally to avoid void pointer arithmetic warnings */
99 char **ret = GNUNET_xmalloc_ (n * sizeof(void *) /* 1. dim header */
100 + n * m * elementSize, /* element data */
101 filename,
102 linenumber);
103
104 for (size_t i = 0; i < n; i++)
105 ret[i] = (char *) ret /* base address */
106 + n * sizeof(void *) /* skip 1. dim header */
107 + i * m * elementSize; /* skip to 2. dim row header */
108 return (void **) ret;
109}
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 128 of file common_allocation.c.

134{
135 /* use char pointer internally to avoid void pointer arithmetic warnings */
136 char ***ret = GNUNET_xmalloc_ (n * sizeof(void **) /* 1. dim header */
137 + n * m * sizeof(void *) /* 2. dim header */
138 + n * m * o * elementSize, /* element data */
139 filename,
140 linenumber);
141
142 for (size_t i = 0; i < n; i++)
143 {
144 /* need to cast to (char *) temporarily for byte level accuracy */
145 ret[i] = (char **) ((char *) ret /* base address */
146 + n * sizeof(void **) /* skip 1. dim header */
147 + i * m * sizeof(void *)); /* skip to 2. dim header */
148 for (size_t j = 0; j < m; j++)
149 ret[i][j] = (char *) ret /* base address */
150 + n * sizeof(void **) /* skip 1. dim header */
151 + n * m * sizeof(void *) /* skip 2. dim header */
152 + i * m * o * elementSize /* skip to 2. dim part */
153 + j * o * elementSize; /* skip to 3. dim row data */
154 }
155 return (void ***) ret;
156}

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 160 of file common_allocation.c.

164{
165 void *ret;
166
167 /* As a security precaution, we generally do not allow very large
168 * allocations here */
170 GNUNET_assert_at (size < INT_MAX, filename, linenumber);
171 ret = malloc (size);
172 if (ret == NULL)
173 {
175 GNUNET_assert (0);
176 }
177 GNUNET_memcpy (ret, buf, size);
178 return ret;
179}
#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

Allocate memory.

Allocates size bytes of memory. The memory will be zero'ed out.

Parameters
sizethe number of bytes to allocate
filenamewhere in the code was the call to GNUNET_malloc_unchecked()
linenumberwhere in the code was the call to GNUNET_malloc_unchecked()
Returns
pointer to size bytes of memory, NULL if we do not have enough memory

Definition at line 192 of file common_allocation.c.

193{
194 void *result;
195
196 (void) filename;
197 (void) linenumber;
198
199 result = malloc (size);
200 if (NULL == result)
201 return NULL;
202 memset (result, 0, size);
203
204 return result;
205}
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.

Checks the return value, aborts if no more memory is available. The content of the intersection of the new and old size will be unchanged.

Parameters
ptrthe pointer to reallocate
nhow many bytes of memory to allocate
filenamewhere in the code was the call to GNUNET_realloc()
linenumberwhere in the code was the call to GNUNET_realloc()
Returns
pointer to size bytes of memory

Definition at line 220 of file common_allocation.c.

221{
222 (void) filename;
223 (void) linenumber;
224
225#if defined(M_SIZE)
226#if ENABLE_POISONING
227 {
228 uint64_t *base = ptr;
229 size_t s = M_SIZE (ptr);
230
231 if (s > n)
232 {
233 const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
234 char *cbase = ptr;
235
236 GNUNET_memcpy (&cbase[n],
237 &baadfood,
238 GNUNET_MIN (8 - (n % 8),
239 s - n));
240 for (size_t i = 1 + (n + 7) / 8; i < s / 8; i++)
241 base[i] = baadfood;
242 GNUNET_memcpy (&base[s / 8],
243 &baadfood,
244 s % 8);
245 }
246 }
247#endif
248#endif
249 ptr = realloc (ptr, n);
250 if ((NULL == ptr) && (n > 0))
251 {
253 GNUNET_assert (0);
254 }
255 return ptr;
256}
#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)

Merely a wrapper for the case that we want to keep track of allocations.

Parameters
ptrthe pointer to free
filenamewhere in the code was the call to GNUNET_free()
linenumberwhere in the code was the call to GNUNET_free()

Definition at line 284 of file common_allocation.c.

287{
288 if (NULL == ptr)
289 return;
290#if defined(M_SIZE)
291#if ENABLE_POISONING
292 {
293 const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
294 uint64_t *base = ptr;
295 size_t s = M_SIZE (ptr);
296
297 for (size_t i = 0; i < s / 8; i++)
298 base[i] = baadfood;
299 GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
300 }
301#endif
302#endif
303 free (ptr);
304}

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

Dup a string.

Parameters
strthe string to dup
filenamewhere in the code was the call to GNUNET_strdup()
linenumberwhere in the code was the call to GNUNET_strdup()
Returns
strdup(@a str)

Definition at line 316 of file common_allocation.c.

317{
318 char *res;
319 size_t slen;
320
321 GNUNET_assert_at (str != NULL, filename, linenumber);
322 slen = strlen (str) + 1;
323 res = GNUNET_xmalloc_ (slen, filename, linenumber);
324 GNUNET_memcpy (res, str, slen);
325 return res;
326}

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

Dup partially a string.

Parameters
strthe string to dup
lenthe length of the string to dup
filenamewhere in the code was the call to GNUNET_strndup()
linenumberwhere in the code was the call to GNUNET_strndup()
Returns
strndup(@a str,@a len)

Definition at line 355 of file common_allocation.c.

359{
360 char *res;
361
362 if (0 == len)
363 return GNUNET_strdup ("");
364 GNUNET_assert_at (NULL != str, filename, linenumber);
365 len = strnlen (str, len);
366 res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
367 GNUNET_memcpy (res, str, len);
368 /* res[len] = '\0'; 'malloc' zeros out anyway */
369 return res;
370}
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)

Grow an array, the new elements are zeroed out.

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

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
filenamewhere in the code was the call to GNUNET_array_grow()
linenumberwhere in the code was the call to GNUNET_array_grow()

Definition at line 386 of file common_allocation.c.

392{
393 void *tmp;
394 size_t size;
395
396 GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber);
397 size = newCount * elementSize;
398 if (0 == size)
399 {
400 tmp = NULL;
401 }
402 else
403 {
404 tmp = GNUNET_xmalloc_ (size, filename, linenumber);
405 if (NULL != *old)
406 {
407 GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN (*oldCount, newCount));
408 }
409 }
410
411 if (NULL != *old)
412 {
413 GNUNET_xfree_ (*old, filename, linenumber);
414 }
415 *old = tmp;
416 *oldCount = newCount;
417}
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 1477 of file common_logging.c.

1479{
1480 *old_scope = current_async_scope;
1483}
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 1492 of file common_logging.c.

1493{
1494 current_async_scope = *old_scope;
1495}

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 1518 of file common_logging.c.

1519{
1520 *scope_ret = current_async_scope;
1521}

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 1504 of file common_logging.c.

1505{
1507 aid_ret,
1508 sizeof(struct GNUNET_AsyncScopeId));
1509}
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 calcualations.
Definition: gnunet-scrypt.c:34
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf_v(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
Derive key.
Definition: crypto_kdf.c:38
unsigned char twofish_key[(256/8)]
Actual key for TwoFish.
unsigned char aes_key[(256/8)]
Actual key for AES.

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

Referenced by GNUNET_CRYPTO_symmetric_derive_iv().

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

◆ GNUNET_CRYPTO_pow_hash()

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

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

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

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

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

Definition at line 42 of file crypto_pow.c.

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

References GNUNET_break, result, and salt.

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_context_start()

struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start ( void  )

Start incremental hashing operation.

Returns
context for incremental hash computation

Definition at line 350 of file crypto_hash.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_context_copy()

struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_copy ( const struct GNUNET_HashContext hc)

Make a copy of the hash computation.

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

Definition at line 377 of file crypto_hash.c.

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

References GNUNET_assert, GNUNET_new, and GNUNET_HashContext::hd.

◆ GNUNET_CRYPTO_hash_context_read()

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

Add data to be hashed.

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

Definition at line 366 of file crypto_hash.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_context_finish()

void GNUNET_CRYPTO_hash_context_finish ( struct GNUNET_HashContext hc,
struct GNUNET_HashCode r_hash 
)

Finish the hash computation.

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

Definition at line 390 of file crypto_hash.c.

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

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

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

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

◆ GNUNET_CRYPTO_hash_context_abort()

void GNUNET_CRYPTO_hash_context_abort ( struct GNUNET_HashContext hc)

Abort hashing, do not bother calculating final result.

Parameters
hchash context to destroy

Definition at line 408 of file crypto_hash.c.

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

References GNUNET_free, and GNUNET_HashContext::hd.

Referenced by GNUNET_CRYPTO_hash_context_finish().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hmac_raw()

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

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

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

Definition at line 300 of file crypto_hash.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_file_cancel()

void GNUNET_CRYPTO_hash_file_cancel ( struct GNUNET_CRYPTO_FileHashContext fhc)

Cancel a file hashing operation.

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

Definition at line 225 of file crypto_hash_file.c.

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

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

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

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

◆ GNUNET_CRYPTO_hash_count_leading_zeros()

unsigned int GNUNET_CRYPTO_hash_count_leading_zeros ( const struct GNUNET_HashCode h)

Count the number of leading 0 bits in h.

Parameters
ha hash
Returns
number of leading 0 bits in h

Definition at line 177 of file crypto_hash.c.

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

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

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

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

◆ GNUNET_CRYPTO_hash_count_tailing_zeros()

unsigned int GNUNET_CRYPTO_hash_count_tailing_zeros ( const struct GNUNET_HashCode h)

Count the number of tailing 0 bits in h.

Parameters
ha hash
Returns
number of tailing 0 bits in h

Definition at line 199 of file crypto_hash.c.

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

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

Here is the call graph for this function:

◆ GNUNET_CRYPTO_kdf_v()

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

Derive key.

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

Definition at line 38 of file crypto_kdf.c.

45{
46 /*
47 * "Finally, we point out to a particularly advantageous instantiation using
48 * HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from SHA-512 is
49 * truncated to 256 bits). This makes sense in two ways: First, the extraction part is where we need a
50 * stronger hash function due to the unconventional demand from the hash function in the extraction
51 * setting. Second, as shown in Section 6, using HMAC with a truncated output as an extractor
52 * allows to prove the security of HKDF under considerably weaker assumptions on the underlying
53 * hash function."
54 *
55 * http://eprint.iacr.org/2010/264
56 */
58 out_len,
59 GCRY_MD_SHA512,
60 GCRY_MD_SHA256,
61 xts,
62 xts_len,
63 skm,
64 skm_len,
65 argp);
66}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_v(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
Derive key.
Definition: crypto_hkdf.c:166

References GNUNET_CRYPTO_hkdf_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 95 of file crypto_kdf.c.

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

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

227{
228 char *pubkeybuf;
229 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
230 char *end;
231
232 if (keylen % 5 > 0)
233 keylen += 5 - keylen % 5;
234 keylen /= 5;
235 pubkeybuf = GNUNET_malloc (keylen + 1);
236 end =
237 GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
238 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
239 pubkeybuf,
240 keylen);
241 if (NULL == end)
242 {
243 GNUNET_free (pubkeybuf);
244 return NULL;
245 }
246 *end = '\0';
247 return pubkeybuf;
248}
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...

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

Referenced by get_ego().

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

◆ GNUNET_CRYPTO_ecdsa_private_key_to_string()

char * GNUNET_CRYPTO_ecdsa_private_key_to_string ( const struct GNUNET_CRYPTO_EcdsaPrivateKey priv)

Convert a private key to a string.

Parameters
privkey to convert
Returns
string representing priv

Definition at line 306 of file crypto_ecc.c.

308{
309 char *privkeybuf;
310 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)) * 8;
311 char *end;
312
313 if (keylen % 5 > 0)
314 keylen += 5 - keylen % 5;
315 keylen /= 5;
316 privkeybuf = GNUNET_malloc (keylen + 1);
317 end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
318 sizeof(
320 privkeybuf,
321 keylen);
322 if (NULL == end)
323 {
324 GNUNET_free (privkeybuf);
325 return NULL;
326 }
327 *end = '\0';
328 return privkeybuf;
329}
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 279 of file crypto_ecc.c.

281{
282 char *privkeybuf;
283 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
284 char *end;
285
286 if (keylen % 5 > 0)
287 keylen += 5 - keylen % 5;
288 keylen /= 5;
289 privkeybuf = GNUNET_malloc (keylen + 1);
290 end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
291 sizeof(
293 privkeybuf,
294 keylen);
295 if (NULL == end)
296 {
297 GNUNET_free (privkeybuf);
298 return NULL;
299 }
300 *end = '\0';
301 return privkeybuf;
302}
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 252 of file crypto_ecc.c.

254{
255 char *pubkeybuf;
256 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
257 char *end;
258
259 if (keylen % 5 > 0)
260 keylen += 5 - keylen % 5;
261 keylen /= 5;
262 pubkeybuf = GNUNET_malloc (keylen + 1);
263 end =
264 GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
265 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
266 pubkeybuf,
267 keylen);
268 if (NULL == end)
269 {
270 GNUNET_free (pubkeybuf);
271 return NULL;
272 }
273 *end = '\0';
274 return pubkeybuf;
275}
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 333 of file crypto_ecc.c.

337{
338 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
339
340 if (keylen % 5 > 0)
341 keylen += 5 - keylen % 5;
342 keylen /= 5;
343 if (enclen != keylen)
344 return GNUNET_SYSERR;
345
346 if (GNUNET_OK !=
348 enclen,
349 pub,
350 sizeof(
352 return GNUNET_SYSERR;
353 return GNUNET_OK;
354}
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 383 of file crypto_ecc.c.

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

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

362{
363 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
364
365 if (keylen % 5 > 0)
366 keylen += 5 - keylen % 5;
367 keylen /= 5;
368 if (enclen != keylen)
369 return GNUNET_SYSERR;
370
371 if (GNUNET_OK !=
373 enclen,
374 pub,
375 sizeof(
377 return GNUNET_SYSERR;
378 return GNUNET_OK;
379}

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

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

Definition at line 586 of file crypto_ecc.c.

591{
592 unsigned char sk[crypto_sign_SECRETKEYBYTES];
593 unsigned char pk[crypto_sign_PUBLICKEYBYTES];
594 int res;
595
596 GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
597 res = crypto_sign_detached ((uint8_t *) sig,
598 NULL,
599 (uint8_t *) data,
600 size,
601 sk);
602 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
603}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.

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

Referenced by ego_sign_data_cb().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_ecdsa_sign_derived()

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

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

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

Definition at line 175 of file crypto_ecc_gnsrecord.c.

181{
185 label,
186 context);
188 purpose,
189 sig);
191 return res;
192}
static pa_context * context
Pulseaudio context.
struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_private_key_derive(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const char *label, const char *context)
Derive a private key from a given private key and a label.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
ECDSA Sign a given block.
Definition: crypto_ecc.c:536
GNUNET_GenericReturnValue
Named constants for return values.

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

Referenced by block_sign_ecdsa().

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

◆ GNUNET_CRYPTO_eddsa_sign_derived()

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

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

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

Derive the private key

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

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

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

Temporarily put zk into S

Reduce the scalar value r

Calculate R := r * G of the signature

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

Reduce the resulting scalar value

Calculate S := r + hram * s mod L

Definition at line 72 of file crypto_ecc_gnsrecord.c.

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

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

Referenced by block_sign_eddsa().

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

◆ GNUNET_CRYPTO_eddsa_key_get_public_from_scalar()

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

Extract the public key of the given private scalar.

Parameters
sthe private scalar
pkeythe resulting public key

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

Definition at line 437 of file crypto_ecc_gnsrecord.c.

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

References pkey, and GNUNET_CRYPTO_EddsaPrivateScalar::s.

◆ GNUNET_CRYPTO_ecdhe_elligator_initialize()

void GNUNET_CRYPTO_ecdhe_elligator_initialize ( void  )

Initializes the elligator library THis function is thread safe.

Definition at line 222 of file crypto_elligator.c.

223{
224 static bool initialized = false;
225
226 if (initialized)
227 {
228 return;
229 }
230
243
244 mp_size_t scratch_space_lengths[] = {
245 // For least_square_root
246
247 mpn_sec_powm_itch (P_LIMBS, P_BITS - 1, P_LIMBS),
248 mpn_sec_sqr_itch (P_LIMBS),
249 mpn_sec_div_r_itch (P_LIMBS + P_LIMBS, P_LIMBS),
250 mpn_sec_sub_1_itch (P_LIMBS),
251 mpn_sec_mul_itch (P_LIMBS, P_LIMBS),
252
253 // For Elligator_2_Curve25519_encode
254
255 mpn_sec_powm_itch (P_LIMBS, P_BITS - 1, P_LIMBS),
256 mpn_sec_mul_itch (P_LIMBS, P_LIMBS),
257 mpn_sec_div_r_itch (P_LIMBS + P_LIMBS, P_LIMBS),
258 mpn_sec_sqr_itch (P_LIMBS),
259 mpn_sec_sub_1_itch (P_LIMBS),
260
261 // For Elligator_2_Curve25519_decode
262
263 mpn_sec_sqr_itch (P_LIMBS),
264 mpn_sec_div_r_itch (P_LIMBS + P_LIMBS, P_LIMBS),
265 mpn_sec_div_r_itch (P_LIMBS, P_LIMBS),
266 mpn_sec_mul_itch (P_LIMBS, P_LIMBS),
267 mpn_sec_add_1_itch (P_LIMBS),
268 mpn_sec_powm_itch (P_LIMBS, P_BITS - 1, P_LIMBS),
269
270 // For Elligator_2_Curve25519_convert_from_Ed25519
271 /*
272 mpn_sec_sqr_itch (P_LIMBS),
273 mpn_sec_div_r_itch (P_LIMBS + P_LIMBS, P_LIMBS),
274 mpn_sec_mul_itch (P_LIMBS, P_LIMBS),
275 mpn_sec_add_1_itch (P_LIMBS),
276 mpn_sec_powm_itch (P_LIMBS, P_BITS - 1, P_LIMBS),
277 mpn_sec_sub_1_itch (P_LIMBS)
278 */
279 };
280
281 for (size_t i = 0; i < sizeof scratch_space_lengths
282 / sizeof *scratch_space_lengths; ++i)
283 {
284 if (scratch_space_lengths[i] > scratch_space_length)
285 {
286 scratch_space_length = scratch_space_lengths[i];
287 }
288 }
289
290 initialized = true;
291}
static void decode_bytes(mp_limb_t *number, const uint8_t *bytes)
static mp_limb_t divide_minus_p_1_2[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static mp_limb_t negative_A[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static mp_limb_t negative_2[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
#define P_BITS
static mp_limb_t square_root_negative_1[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static mp_limb_t p[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static const unsigned char divide_minus_p_1_2_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static const unsigned char negative_A_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static const unsigned char u_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
#define P_LIMBS
static const unsigned char p_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static const unsigned char negative_1_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static const unsigned char negative_2_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static mp_size_t scratch_space_length
static const unsigned char A_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static const unsigned char square_root_negative_1_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static const unsigned char d_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static mp_limb_t negative_1[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static const unsigned char divide_plus_p_3_8_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static const unsigned char divide_negative_1_2_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static mp_limb_t A[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static mp_limb_t inverted_u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static mp_limb_t divide_plus_p_3_8[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static mp_limb_t u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static const unsigned char inverted_u_bytes[(((256)+CHAR_BIT - 1)/CHAR_BIT)]
static mp_limb_t divide_negative_1_2[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static int initialized
Have we been initialized?
Definition: plugin.c:59

References A, A_bytes, d, d_bytes, decode_bytes(), divide_minus_p_1_2, divide_minus_p_1_2_bytes, divide_negative_1_2, divide_negative_1_2_bytes, divide_plus_p_3_8, divide_plus_p_3_8_bytes, initialized, inverted_u, inverted_u_bytes, negative_1, negative_1_bytes, negative_2, negative_2_bytes, negative_A, negative_A_bytes, p, P_BITS, p_bytes, P_LIMBS, scratch_space_length, square_root_negative_1, square_root_negative_1_bytes, u, and u_bytes.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_mpi_print_unsigned()

void GNUNET_CRYPTO_mpi_print_unsigned ( void *  buf,
size_t  size,
gcry_mpi_t  val 
)

Output the given MPI value to the given buffer in network byte order.

The MPI val may not be negative.

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

Definition at line 79 of file crypto_mpi.c.

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

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

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

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

◆ GNUNET_CRYPTO_mpi_scan_unsigned()

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

Convert data buffer into MPI value.

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

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

Definition at line 132 of file crypto_mpi.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_paillier_create()

void GNUNET_CRYPTO_paillier_create ( struct GNUNET_CRYPTO_PaillierPublicKey public_key,
struct GNUNET_CRYPTO_PaillierPrivateKey private_key 
)

Create a freshly generated paillier public key.

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

Definition at line 40 of file crypto_paillier.c.

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

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

Referenced by handle_client_keygen(), and run().

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

◆ GNUNET_CRYPTO_paillier_encrypt()

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

Encrypt a plaintext with a paillier public key.

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

Definition at line 221 of file crypto_paillier.c.

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