GNUnet  0.18.1
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_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_CsNonce
 Nonce. 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_RsaBlindingKeySecret
 Constant-size pre-secret for blinding key generation. 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 GNUNET_VA_ARG_ENUM(va, X)   ((enum X) va_arg (va, int))
 wrap va_arg for enums More...
 
#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_GCC_STRUCT_LAYOUT
 gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields 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 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME   180
 
#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...
 

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 int(* EXTRACTOR_MetaDataProcessor) (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_len)
 Type of a function that libextractor calls for each meta data item found. 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  EXTRACTOR_MetaType {
  EXTRACTOR_METATYPE_RESERVED = 0 , EXTRACTOR_METATYPE_MIMETYPE = 1 , EXTRACTOR_METATYPE_FILENAME = 2 , EXTRACTOR_METATYPE_COMMENT = 3 ,
  EXTRACTOR_METATYPE_TITLE = 4 , EXTRACTOR_METATYPE_BOOK_TITLE = 5 , EXTRACTOR_METATYPE_JOURNAL_NAME = 8 , EXTRACTOR_METATYPE_AUTHOR_NAME = 13 ,
  EXTRACTOR_METATYPE_PUBLICATION_DATE = 24 , EXTRACTOR_METATYPE_URL = 29 , EXTRACTOR_METATYPE_URI = 30 , EXTRACTOR_METATYPE_ISRC = 31 ,
  EXTRACTOR_METATYPE_UNKNOWN = 45 , EXTRACTOR_METATYPE_DESCRIPTION = 46 , EXTRACTOR_METATYPE_KEYWORDS = 49 , EXTRACTOR_METATYPE_SUBJECT = 52 ,
  EXTRACTOR_METATYPE_PACKAGE_NAME = 69 , EXTRACTOR_METATYPE_THUMBNAIL = 114 , EXTRACTOR_METATYPE_ALBUM = 129 , EXTRACTOR_METATYPE_ARTIST = 130 ,
  EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162 , EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174 , EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180
}
 Enumeration defining various sources of keywords. More...
 
enum  EXTRACTOR_MetaFormat { EXTRACTOR_METAFORMAT_UNKNOWN = 0 , EXTRACTOR_METAFORMAT_UTF8 = 1 , EXTRACTOR_METAFORMAT_BINARY = 2 , EXTRACTOR_METAFORMAT_C_STRING = 3 }
 Format in which the extracted meta data is presented. 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_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...
 
int GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, void **buf, size_t *buf_size)
 Blinds the given message with the given blinding key. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, const void *msg, size_t msg_len)
 Sign a blinded value, which must be a full domain hash of a message. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, const struct GNUNET_HashCode *hash)
 Create and sign a full domain hash of a message. More...
 
void GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig)
 Free memory occupied by signature. More...
 
size_t GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
 Encode the given signature in a format suitable for storing it into a file. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_signature_decode (const void *buf, size_t buf_size)
 Decode the signature from the data-format back to the "normal", internal format. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig)
 Duplicate the given rsa signature. More...
 
struct GNUNET_CRYPTO_RsaSignatureGNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey)
 Unblind a blind-signed signature. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaPublicKey *public_key)
 Verify whether the given hash corresponds to the given signature and the signature is valid with respect to the given public key. More...
 
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_CsNonce *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_CsNonce *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_CsRPublic blinded_r_pub[2])
 Calculate two blinded c's Comment: One would be insecure due to Wagner's algorithm solving ROS. More...
 
unsigned int GNUNET_CRYPTO_cs_sign_derive (const struct GNUNET_CRYPTO_CsPrivateKey *priv, const struct GNUNET_CRYPTO_CsRSecret r[2], const struct GNUNET_CRYPTO_CsC c[2], const struct GNUNET_CRYPTO_CsNonce *nonce, struct GNUNET_CRYPTO_CsBlindS *blinded_signature_scalar)
 Sign a blinded c This function derives b from a nonce and a longterm secret In original papers b is generated randomly To provide abort-idempotency, b needs to be derived but still need to be UNPREDICTABLE. 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_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 86 of file gnunet_common.h.

◆ GNUNET_MIN

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

Definition at line 105 of file gnunet_common.h.

◆ GNUNET_MAX

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

Definition at line 107 of file gnunet_common.h.

◆ GNUNET_VA_ARG_ENUM

#define GNUNET_VA_ARG_ENUM (   va,
 
)    ((enum X) va_arg (va, int))

wrap va_arg for enums

Definition at line 141 of file gnunet_common.h.

◆ BYTE_SWAP_16

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

Endian operations.

Definition at line 163 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 165 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 169 of file gnunet_common.h.

◆ GNUNET_htobe16 [1/2]

#define GNUNET_htobe16 (   x)    BYTE_SWAP_16 (x)

Definition at line 193 of file gnunet_common.h.

◆ GNUNET_htobe16 [2/2]

#define GNUNET_htobe16 (   x)    (x)

Definition at line 193 of file gnunet_common.h.

◆ GNUNET_htole16 [1/2]

#define GNUNET_htole16 (   x)    (x)

Definition at line 194 of file gnunet_common.h.

◆ GNUNET_htole16 [2/2]

#define GNUNET_htole16 (   x)    BYTE_SWAP_16 (x)

Definition at line 194 of file gnunet_common.h.

◆ GNUNET_be16toh [1/2]

#define GNUNET_be16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 195 of file gnunet_common.h.

◆ GNUNET_be16toh [2/2]

#define GNUNET_be16toh (   x)    (x)

Definition at line 195 of file gnunet_common.h.

◆ GNUNET_le16toh [1/2]

#define GNUNET_le16toh (   x)    (x)

Definition at line 196 of file gnunet_common.h.

◆ GNUNET_le16toh [2/2]

#define GNUNET_le16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 196 of file gnunet_common.h.

◆ GNUNET_htobe32 [1/2]

#define GNUNET_htobe32 (   x)    BYTE_SWAP_32 (x)

Definition at line 198 of file gnunet_common.h.

◆ GNUNET_htobe32 [2/2]

#define GNUNET_htobe32 (   x)    (x)

Definition at line 198 of file gnunet_common.h.

◆ GNUNET_htole32 [1/2]

#define GNUNET_htole32 (   x)    (x)

Definition at line 199 of file gnunet_common.h.

◆ GNUNET_htole32 [2/2]

#define GNUNET_htole32 (   x)    BYTE_SWAP_32 (x)

Definition at line 199 of file gnunet_common.h.

◆ GNUNET_be32toh [1/2]

#define GNUNET_be32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 200 of file gnunet_common.h.

◆ GNUNET_be32toh [2/2]

#define GNUNET_be32toh (   x)    (x)

Definition at line 200 of file gnunet_common.h.

◆ GNUNET_le32toh [1/2]

#define GNUNET_le32toh (   x)    (x)

Definition at line 201 of file gnunet_common.h.

◆ GNUNET_le32toh [2/2]

#define GNUNET_le32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 201 of file gnunet_common.h.

◆ GNUNET_htobe64 [1/2]

#define GNUNET_htobe64 (   x)    BYTE_SWAP_64 (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_htobe64 [2/2]

#define GNUNET_htobe64 (   x)    (x)

Definition at line 203 of file gnunet_common.h.

◆ GNUNET_htole64 [1/2]

#define GNUNET_htole64 (   x)    (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_htole64 [2/2]

#define GNUNET_htole64 (   x)    BYTE_SWAP_64 (x)

Definition at line 204 of file gnunet_common.h.

◆ GNUNET_be64toh [1/2]

#define GNUNET_be64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 205 of file gnunet_common.h.

◆ GNUNET_be64toh [2/2]

#define GNUNET_be64toh (   x)    (x)

Definition at line 205 of file gnunet_common.h.

◆ GNUNET_le64toh [1/2]

#define GNUNET_le64toh (   x)    (x)

Definition at line 206 of file gnunet_common.h.

◆ GNUNET_le64toh [2/2]

#define GNUNET_le64toh (   x)    BYTE_SWAP_64 (x)

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

◆ GNUNET_PACKED

#define GNUNET_PACKED   __attribute__ ((packed))

gcc-ism to get packed structs.

Definition at line 228 of file gnunet_common.h.

◆ GNUNET_GCC_STRUCT_LAYOUT

#define GNUNET_GCC_STRUCT_LAYOUT

gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields

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

◆ GNUNET_UNUSED

#define GNUNET_UNUSED   __attribute__ ((unused))

gcc-ism to document unused arguments

Definition at line 249 of file gnunet_common.h.

◆ GNUNET_NORETURN

#define GNUNET_NORETURN   __attribute__ ((noreturn))

gcc-ism to document functions that don't return

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

◆ GN_LIKELY

#define GN_LIKELY (   expr)    (expr)

Definition at line 505 of file gnunet_common.h.

◆ GN_UNLIKELY

#define GN_UNLIKELY (   expr)    (expr)

Definition at line 506 of file gnunet_common.h.

◆ GNUNET_LOG_CALL_STATUS

#define GNUNET_LOG_CALL_STATUS   -1

Definition at line 510 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
Definition: gnunet_common.h:98
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 532 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 558 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 651 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 1005 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 1214 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 1243 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 1271 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 1284 of file gnunet_common.h.

◆ __func__

#define __func__   "<unknown>"

Definition at line 1784 of file gnunet_common.h.

◆ EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME

#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME   180

Definition at line 197 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)
static struct PendingResolutions * tail
Tail of list of pending resolution requests.
Definition: gnunet-ats.c:235
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:230
struct PendingResolutions * prev
Kept in a DLL.
Definition: gnunet-ats.c:164
struct PendingResolutions * next
Kept in a DLL.
Definition: gnunet-ats.c:159

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 2472 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 73 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 106 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 111 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 117 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 404 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 50 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 394 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 410 of file gnunet_common.h.

◆ EXTRACTOR_MetaDataProcessor

typedef int(* EXTRACTOR_MetaDataProcessor) (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_len)

Type of a function that libextractor calls for each meta data item found.

Parameters
clsclosure (user-defined)
plugin_namename of the plugin that produced this value; special values can be used (e.g. '<zlib>' for zlib being used in the main libextractor library and yielding meta data).
typelibextractor-type describing the meta data
formatbasic format information about data
data_mime_typemime-type of data (not of the original file); can be NULL (if mime-type is not known)
dataactual meta-data found
data_lennumber of bytes in data
Returns
0 to continue extracting, 1 to abort

Definition at line 185 of file gnunet_container_lib.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 1003 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 95 of file gnunet_common.h.

96 {
97  GNUNET_SYSERR = -1,
98  GNUNET_NO = 0,
99  GNUNET_OK = 1,
100  /* intentionally identical to #GNUNET_OK! */
101  GNUNET_YES = 1,
102 };
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_SYSERR
Definition: gnunet_common.h:97

◆ 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 1796 of file gnunet_common.h.

1797 {
1802 
1807 
1813 
1821 
1827 
1833 
1841 
1851 
1857 };
@ 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...

◆ EXTRACTOR_MetaType

Enumeration defining various sources of keywords.

See also http://dublincore.org/documents/1998/09/dces/

Enumerator
EXTRACTOR_METATYPE_RESERVED 
EXTRACTOR_METATYPE_MIMETYPE 
EXTRACTOR_METATYPE_FILENAME 
EXTRACTOR_METATYPE_COMMENT 
EXTRACTOR_METATYPE_TITLE 
EXTRACTOR_METATYPE_BOOK_TITLE 
EXTRACTOR_METATYPE_JOURNAL_NAME 
EXTRACTOR_METATYPE_AUTHOR_NAME 
EXTRACTOR_METATYPE_PUBLICATION_DATE 
EXTRACTOR_METATYPE_URL 
EXTRACTOR_METATYPE_URI 
EXTRACTOR_METATYPE_ISRC 
EXTRACTOR_METATYPE_UNKNOWN 
EXTRACTOR_METATYPE_DESCRIPTION 
EXTRACTOR_METATYPE_KEYWORDS 
EXTRACTOR_METATYPE_SUBJECT 
EXTRACTOR_METATYPE_PACKAGE_NAME 
EXTRACTOR_METATYPE_THUMBNAIL 
EXTRACTOR_METATYPE_ALBUM 
EXTRACTOR_METATYPE_ARTIST 
EXTRACTOR_METATYPE_ORIGINAL_TITLE 
EXTRACTOR_METATYPE_GNUNET_FULL_DATA 
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 

Definition at line 112 of file gnunet_container_lib.h.

113 {
137 };
#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
@ EXTRACTOR_METATYPE_PUBLICATION_DATE
@ EXTRACTOR_METATYPE_URI
@ EXTRACTOR_METATYPE_JOURNAL_NAME
@ EXTRACTOR_METATYPE_BOOK_TITLE
@ EXTRACTOR_METATYPE_THUMBNAIL
@ EXTRACTOR_METATYPE_UNKNOWN
@ EXTRACTOR_METATYPE_AUTHOR_NAME
@ EXTRACTOR_METATYPE_COMMENT
@ EXTRACTOR_METATYPE_TITLE
@ EXTRACTOR_METATYPE_ARTIST
@ EXTRACTOR_METATYPE_ISRC
@ EXTRACTOR_METATYPE_KEYWORDS
@ EXTRACTOR_METATYPE_FILENAME
@ EXTRACTOR_METATYPE_MIMETYPE
@ EXTRACTOR_METATYPE_ALBUM
@ EXTRACTOR_METATYPE_ORIGINAL_TITLE
@ EXTRACTOR_METATYPE_PACKAGE_NAME
@ EXTRACTOR_METATYPE_SUBJECT
@ EXTRACTOR_METATYPE_RESERVED
@ EXTRACTOR_METATYPE_URL
@ EXTRACTOR_METATYPE_GNUNET_FULL_DATA
@ EXTRACTOR_METATYPE_DESCRIPTION

◆ EXTRACTOR_MetaFormat

Format in which the extracted meta data is presented.

Enumerator
EXTRACTOR_METAFORMAT_UNKNOWN 

Format is unknown.

EXTRACTOR_METAFORMAT_UTF8 

0-terminated, UTF-8 encoded string.

"data_len" is strlen(data)+1.

EXTRACTOR_METAFORMAT_BINARY 

Some kind of binary format, see given Mime type.

EXTRACTOR_METAFORMAT_C_STRING 

0-terminated string.

The specific encoding is unknown. "data_len" is strlen (data)+1.

Definition at line 142 of file gnunet_container_lib.h.

143 {
148 
154 
159 
165 };
@ EXTRACTOR_METAFORMAT_BINARY
Some kind of binary format, see given Mime type.
@ EXTRACTOR_METAFORMAT_C_STRING
0-terminated string.
@ EXTRACTOR_METAFORMAT_UTF8
0-terminated, UTF-8 encoded string.
@ EXTRACTOR_METAFORMAT_UNKNOWN
Format is unknown.

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 }
static char buf[2048]
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.

References buf, GNUNET_assert, GNUNET_malloc, and GNUNET_YES.

◆ 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 */
65  GNUNET_break (GNUNET_YES != buf->warn_grow);
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 buf, GNUNET_assert, GNUNET_break, GNUNET_malloc, GNUNET_realloc, and GNUNET_YES.

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 }
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 buf, data, GNUNET_buffer_ensure_remaining(), and len.

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 buf, GNUNET_buffer_write(), and len.

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 buf, data, GNUNET_assert, GNUNET_buffer_ensure_remaining(), and GNUNET_STRINGS_data_to_string().

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 buf, GNUNET_buffer_ensure_remaining(), GNUNET_buffer_write(), and len.

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 int res

References consensus-simulation::args, buf, GNUNET_assert, GNUNET_buffer_ensure_remaining(), 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 buf, GNUNET_buffer_ensure_remaining(), 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:67

References buf, 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 buf, and GNUNET_free.

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

Starts the handling of the child processes.

Parameters
procThe child process to be monitored.
cbThe callback to be called, when the child process completed.
cb_clsThe closure for the callback.
Returns
An handle for the the child being monitored.

Definition at line 205 of file child_management.c.

208 {
209  struct GNUNET_ChildWaitHandle *cwh;
210 
212  cwh = GNUNET_new (struct GNUNET_ChildWaitHandle);
213  cwh->proc = proc;
214  cwh->cb = cb;
215  cwh->cb_cls = cb_cls;
217  cwh_tail,
218  cwh);
219  if (NULL == sig_task)
220  {
226  NULL);
227  }
228  return cwh;
229 }
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:1616
@ 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:1624
#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, and sigpipe.

Referenced by handle_uri(), 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.

Stop waiting on this child.

Parameters
cwhThe handle to be removed.

Definition at line 238 of file child_management.c.

239 {
241  cwh_tail,
242  cwh);
243  GNUNET_free (cwh);
244  if (NULL != cwh_head)
245  return;
247 }
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 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 501 of file common_logging.c.

506 {
507  struct LogDef *ld;
508  int i;
509  int force_only;
510 
511  if (NULL == comp)
512  /* Use default component */
513  comp = component_nopid;
514 
515  /* We have no definitions to override globally configured log level,
516  * so just use it right away.
517  */
518  if ((min_level >= 0) && (GNUNET_NO == gnunet_force_log_present))
519  return caller_level <= min_level;
520 
521  /* Only look for forced definitions? */
522  force_only = min_level >= 0;
523  for (i = 0; i < logdefs_len; i++)
524  {
525  ld = &logdefs[i];
526  if (((! force_only) || ld->force) &&
527  ((line >= ld->from_line) && (line <= ld->to_line) ) &&
528  (0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) &&
529  (0 == regexec (&ld->file_regex, file, 0, NULL, 0)) &&
530  (0 == regexec (&ld->function_regex, function, 0, NULL, 0)))
531  {
532  /* We're finished */
533  return caller_level <= ld->level;
534  }
535  }
536  /* No matches - use global level, if defined */
537  if (min_level >= 0)
538  return caller_level <= min_level;
539  /* All programs/services previously defaulted to WARNING.
540  * Now *we* default to WARNING, and THEY default to NULL.
541  * Or rather we default to MESSAGE, since things aren't always bad.
542  */
543  return caller_level <= GNUNET_ERROR_TYPE_MESSAGE;
544 }
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 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 325 of file common_logging.c.

327 {
328  static GNUNET_THREAD_LOCAL char ret[9];
329  struct GNUNET_HashCode hc;
330  char *tmp;
331 
333  buf_size,
334  &hc);
336  sizeof (hc));
337  memcpy (ret,
338  tmp,
339  8);
340  GNUNET_free (tmp);
341  ret[8] = '\0';
342  return ret;
343 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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:246
A 512-bit hashcode.

References buf, 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 36 of file common_endian.c.

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

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_records_serialize(), GNUNET_hton_double(), GNUNET_NAMESTORE_zone_iterator_next(), GNUNET_NAMESTORE_zone_monitor_next(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_relative_time(), GNUNET_PQ_query_param_uint64(), GNUNET_RECLAIM_attribute_store(), GNUNET_RECLAIM_credential_store(), GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_generate_peergetconfig_msg_(), GNUNET_TESTBED_generate_slavegetconfig_msg_(), GST_send_operation_fail_msg(), GST_send_operation_success_msg(), handle_client_accept(), hash_for_index_cb(), notify_change(), opstart_manage_service(), opstart_overlay_connect(), opstart_peer_create(), opstart_peer_destroy(), opstart_peer_reconfigure(), opstart_peer_start(), opstart_peer_stop(), opstart_shutdown_peers(), p2_controller_connect_cb(), print_record(), run(), save(), send_ack(), send_add_queue(), send_channel_data_ack(), send_client_done(), send_client_element(), send_controller_link_response(), send_hello_thru_rocc(), send_overlay_connect_success_msg(), 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 53 of file common_endian.c.

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

Referenced by abd_value_to_string(), backward_resolution(), cb_intersection_element_removed(), cmp_pow_value(), copy_element_cb(), find_proof(), forward_overlay_connect(), 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_FRAGMENT_print_ack(), GNUNET_FRAGMENT_process_ack(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_publish_stop(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_ntoh_double(), 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_iteration_next(), handle_link_controllers(), handle_link_controllers_result(), handle_manage_peer_service(), handle_monitor_next(), handle_op_fail_event(), handle_opsuccess(), handle_overlay_connect(), handle_peer_conevent(), handle_peer_config(), handle_peer_create(), handle_peer_create_success(), handle_peer_destroy(), handle_peer_event(), handle_peer_get_config(), handle_peer_reconfigure(), handle_peer_start(), handle_peer_stop(), handle_remote_overlay_connect(), handle_reserve(), handle_result(), handle_set(), handle_shutdown_peers(), handle_slave_config(), handle_slave_get_config(), handle_start(), handle_statistics_value(), handle_statistics_watch_value(), handle_stop(), handle_union_p2p_strata_estimator(), handle_update_queue_message(), process_result_with_request(), 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 69 of file common_endian.c.

70 {
71  double res;
72  uint64_t *in = (uint64_t *) &d;
73  uint64_t *out = (uint64_t *) &res;
74 
75  out[0] = GNUNET_htonll (in[0]);
76 
77  return res;
78 }
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36

References 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 82 of file common_endian.c.

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

References 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 130 of file consttime_memcmp.c.

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

References consensus-simulation::int, len, 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 469 of file common_allocation.c.

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

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

60 {
61  void *ret;
62 
63  /* As a security precaution, we generally do not allow very large
64  * allocations using the default 'GNUNET_malloc()' macro */
66  ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
67  if (NULL == ret)
68  {
70  GNUNET_assert (0);
71  }
72  return ret;
73 }
#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 91 of file common_allocation.c.

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

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

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

163 {
164  void *ret;
165 
166  /* As a security precaution, we generally do not allow very large
167  * allocations here */
169  GNUNET_assert_at (size < INT_MAX, filename, linenumber);
170  ret = malloc (size);
171  if (ret == NULL)
172  {
174  GNUNET_assert (0);
175  }
177  return ret;
178 }
#define INT_MAX
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.

References buf, 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 191 of file common_allocation.c.

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

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

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

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

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

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

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

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

1448 {
1449  *old_scope = current_async_scope;
1452 }
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 1461 of file common_logging.c.

1462 {
1463  current_async_scope = *old_scope;
1464 }

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

1488 {
1489  *scope_ret = current_async_scope;
1490 }

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

1474 {
1476  aid_ret,
1477  sizeof(struct GNUNET_AsyncScopeId));
1478 }
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 54 of file container_meta_data.c.

58 {
59  char *tmp;
60  uLongf dlen;
61 
62  *result = NULL;
63  *new_size = 0;
64 #ifdef compressBound
65  dlen = compressBound (old_size);
66 #else
67  dlen = old_size + (old_size / 100) + 20;
68  /* documentation says 100.1% oldSize + 12 bytes, but we
69  * should be able to overshoot by more to be safe */
70 #endif
71  tmp = GNUNET_malloc (dlen);
72  if (Z_OK ==
73  compress2 ((Bytef *) tmp,
74  &dlen,
75  (const Bytef *) data,
76  old_size, 9))
77  {
78  if (dlen < old_size)
79  {
80  *result = tmp;
81  *new_size = dlen;
82  return GNUNET_YES;
83  }
84  }
85  GNUNET_free (tmp);
86  return GNUNET_NO;
87 }

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

Referenced by GNUNET_CONTAINER_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 101 of file container_meta_data.c.

104 {
105  char *output;
106  uLongf olen;
107 
108  olen = output_size;
109  output = GNUNET_malloc (olen);
110  if (Z_OK ==
111  uncompress ((Bytef *) output,
112  &olen,
113  (const Bytef *) input,
114  input_size))
115  return output;
116  GNUNET_free (output);
117  return NULL;
118 }

References GNUNET_free, and GNUNET_malloc.

Referenced by GNUNET_CONTAINER_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 87 of file container_bloomfilter.c.

89 {
90  if (bf == NULL)
91  return 0;
92  return bf->addressesPerElement;
93 }
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 535 of file container_multihashmap32.c.

537 {
539 
541  iter->map = map;
543  iter->me = map->map[0];
544  return iter;
545 }
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
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, map, GNUNET_CONTAINER_MultiHashMap32Iterator::map, GNUNET_CONTAINER_MultiPeerMap::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 563 of file container_multihashmap32.c.

567 {
568  /* make sure the map has not been modified */
570 
571  /* look for the next entry, skipping empty buckets */
572  while (1)
573  {
574  if (iter->idx >= iter->map->map_length)
575  return GNUNET_NO;
576  if (NULL != iter->me)
577  {
578  if (NULL != key)
579  *key = iter->me->key;
580  if (NULL != value)
581  *value = iter->me->value;
582  iter->me = iter->me->next;
583  return GNUNET_YES;
584  }
585  iter->idx += 1;
586  if (iter->idx < iter->map->map_length)
587  iter->me = iter->map->map[iter->idx];
588  }
589 }
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 598 of file container_multihashmap32.c.

600 {
601  GNUNET_free (iter);
602 }

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 170 of file container_heap.c.

173 {
174  if (NULL == heap->root)
175  return GNUNET_NO;
176  if (NULL != element)
177  *element = heap->root->element;
178  if (NULL != cost)
179  *cost = heap->root->cost;
180  return GNUNET_YES;
181 }
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 109 of file crypto_crc.c.

110 {
111  const uint16_t *hdr = buf;
112 
113  for (; len >= 2; len -= 2)
114  sum += *(hdr++);
115  if (len == 1)
116  sum += (*hdr) & ntohs (0xFF00);
117  return sum;
118 }

References buf, len, and 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 122 of file crypto_crc.c.

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

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 220 of file crypto_symmetric.c.

228 {
229  char aes_salt[salt_len + 4];
230  char twofish_salt[salt_len + 4];
231 
232  GNUNET_memcpy (aes_salt, salt, salt_len);
233  GNUNET_memcpy (&aes_salt[salt_len], "AES!", 4);
234  GNUNET_memcpy (twofish_salt, salt, salt_len);
235  GNUNET_memcpy (&twofish_salt[salt_len], "FISH", 4);
237  sizeof(iv->aes_iv),
238  aes_salt,
239  salt_len + 4,
240  skey->aes_key,
241  sizeof(skey->aes_key),
242  argp);
244  sizeof(iv->twofish_iv),
245  twofish_salt,
246  salt_len + 4,
247  skey->twofish_key,
248  sizeof(skey->twofish_key),
249  argp);
250 }
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calcualations.
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:37
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 41 of file crypto_pow.c.

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

References buf, GNUNET_break, result, and salt.

Referenced by find_proof().

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

350 {
351  struct GNUNET_HashContext *hc;
352 
353  BENCHMARK_START (hash_context_start);
354  hc = GNUNET_new (struct GNUNET_HashContext);
355  GNUNET_assert (0 ==
356  gcry_md_open (&hc->hd,
357  GCRY_MD_SHA512,
358  0));
359  BENCHMARK_END (hash_context_start);
360  return hc;
361 }
#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:344

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

Referenced by create_randomized_element_iterator(), decode_and_send(), GCCH_get_id(), 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 376 of file crypto_hash.c.

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

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

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

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

Referenced by create_randomized_element_iterator(), decode_and_send(), GCCH_get_id(), 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 389 of file crypto_hash.c.

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

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_get_id(), 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 407 of file crypto_hash.c.

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

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

302 {
303  static int once;
304  static gcry_md_hd_t md;
305  const unsigned char *mc;
306 
307  if (! once)
308  {
309  once = 1;
310  GNUNET_assert (GPG_ERR_NO_ERROR ==
311  gcry_md_open (&md,
312  GCRY_MD_SHA512,
313  GCRY_MD_FLAG_HMAC));
314  }
315  else
316  {
317  gcry_md_reset (md);
318  }
319  GNUNET_assert (GPG_ERR_NO_ERROR ==
320  gcry_md_setkey (md, key, key_len));
321  gcry_md_write (md, plaintext, plaintext_len);
322  mc = gcry_md_read (md, GCRY_MD_SHA512);
323  GNUNET_assert (NULL != mc);
324  GNUNET_memcpy (hmac->bits, mc, sizeof(hmac->bits));
325 }
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:68
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 223 of file crypto_hash_file.c.

224 {
226  GNUNET_free (fhc->filename);
228  GNUNET_DISK_file_close (fhc->fh));
229  GNUNET_free (fhc);
230 }
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:943
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(), 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 176 of file crypto_hash.c.

177 {
178  const unsigned long long *llp = (const unsigned long long *) h;
179  unsigned int ret = 0;
180  unsigned int i;
181 
182  GNUNET_static_assert (8 == sizeof (unsigned long long));
183  GNUNET_static_assert (0 == sizeof (*h) % sizeof (unsigned long long));
184  for (i = 0; i<sizeof (*h) / sizeof (*llp); i++)
185  {
186  if (0LLU != llp[i])
187  break;
188  ret += sizeof (*llp) * 8;
189  }
190  if (ret == 8 * sizeof (*h))
191  return ret;
192  ret += __builtin_clzll (GNUNET_ntohll ((uint64_t) llp[i]));
193  return ret;
194 }
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 add_known_to_bloom(), datacache_get_iterator(), find_proof(), get_matching_bits(), 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 198 of file crypto_hash.c.

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

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

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

Referenced by GNUNET_CRYPTO_hmac_derive_key_v(), and GNUNET_CRYPTO_symmetric_derive_iv_v().

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

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

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

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

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

226 {
227  char *pubkeybuf;
228  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
229  char *end;
230 
231  if (keylen % 5 > 0)
232  keylen += 5 - keylen % 5;
233  keylen /= 5;
234  pubkeybuf = GNUNET_malloc (keylen + 1);
235  end =
236  GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
237  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
238  pubkeybuf,
239  keylen);
240  if (NULL == end)
241  {
242  GNUNET_free (pubkeybuf);
243  return NULL;
244  }
245  *end = '\0';
246  return pubkeybuf;
247 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:46
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 305 of file crypto_ecc.c.

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

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

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

336 {
337  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
338 
339  if (keylen % 5 > 0)
340  keylen += 5 - keylen % 5;
341  keylen /= 5;
342  if (enclen != keylen)
343  return GNUNET_SYSERR;
344 
345  if (GNUNET_OK !=
347  enclen,
348  pub,
349  sizeof(
351  return GNUNET_SYSERR;
352  return GNUNET_OK;
353 }
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

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

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

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

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

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

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  {
79  struct GNUNET_CRYPTO_EccScalar Ki;
80  struct GNUNET_PeerIdentity key;
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, max, GNUNET_CRYPTO_EccDlogContext::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;
118  struct GNUNET_CRYPTO_EccPoint q;
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  {
143  struct GNUNET_PeerIdentity key;
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 }

◆ 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 210 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]

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 210 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:37

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 210 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_CRYPTO_ecc_scalar_from_int(), GNUNET_CRYPTO_EccPoint::v, and GNUNET_CRYPTO_EccScalar::v.

Referenced by handle_alices_cryptodata_message(), and handle_bobs_cryptodata_message().

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

265 {
266  struct GNUNET_CRYPTO_EccScalar s;
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.

◆ 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_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 {
205  GNUNET_free (edc);
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_add(), 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 512 of file crypto_ecc.c.

603 {
604  unsigned char sk[crypto_sign_SECRETKEYBYTES];
605  unsigned char pk[crypto_sign_PUBLICKEYBYTES];
606  int res;
607 
608  GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
609  res = crypto_sign_detached ((uint8_t *) sig,
610  NULL,
611  (uint8_t *) data,
612  size,
613  sk);
614  return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
615 }
struct GNUNET_IDENTITY_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.

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 48 of file crypto_ecc_gnsrecord.c.

180 {
184  label,
185  context);
187  purpose,
188  sig);
189  GNUNET_free (key);
190  return res;
191 }
static pa_context * context
Pulseaudio context.
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:549
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.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96

References context, GNUNET_CRYPTO_kdf(), pub, and salt.

Here is the call 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 48 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.

◆ 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 446 of file crypto_ecc_gnsrecord.c.

449 {
450  unsigned char sk[32];
451 
452  memcpy (sk, priv->s, 32);
453 
458  crypto_scalarmult_ed25519_base_noclamp (pkey->q_y,
459  sk);
460 }

References pkey, and GNUNET_CRYPTO_EddsaPrivateScalar::s.

◆ GNUNET_CRYPTO_mpi_print_unsigned()

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

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

The MPI val may not be negative.

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

Definition at line 78 of file crypto_mpi.c.

81 {
82  size_t rsize;
83  int rc;
84 
85  if (gcry_mpi_get_flag (val, GCRYMPI_FLAG_OPAQUE))
86  {
87  /* Store opaque MPIs left aligned into the buffer. */
88  unsigned int nbits;
89  const void *p;
90 
91  p = gcry_mpi_get_opaque (val, &nbits);
92  GNUNET_assert (p);
93  rsize = (nbits + 7) / 8;
94  if (rsize > size)
95  rsize = size;
96  GNUNET_memcpy (buf, p, rsize);
97  if (rsize < size)
98  memset (buf + rsize, 0, size - rsize);
99  }
100  else
101  {
102  /* Store regular MPIs as unsigned integers right aligned into
103  the buffer. */
104  rsize = size;
105  if (0 !=
106  (rc = gcry_mpi_print (GCRYMPI_FMT_USG,
107  buf,
108  rsize, &rsize,
109  val)))
110  {
112  "gcry_mpi_print",
113  rc);
114  GNUNET_assert (0);
115  }
116  adjust (buf, rsize, size);
117  }
118 }
#define 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:39
static void adjust(void *buf, size_t size, size_t target)
If target != size, move target bytes to the end of the size-sized buffer and zero out the first targe...
Definition: crypto_mpi.c:54

References adjust(), buf, 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_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 131 of file crypto_mpi.c.

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

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

43 {
44  gcry_mpi_t p;
45  gcry_mpi_t q;
46  gcry_mpi_t phi;
47  gcry_mpi_t mu;
48  gcry_mpi_t n;
49 
50  /* Generate two distinct primes. The probability that the loop body
51  is executed more than once is very very low... */
52  p = NULL;
53  q = NULL;
54  do
55  {
56  if (NULL != p)
57  gcry_mpi_release (p);
58  if (NULL != q)
59  gcry_mpi_release (q);
60  GNUNET_assert (0 ==
61  gcry_prime_generate (&p,
63  0, NULL, NULL, NULL,
64  GCRY_STRONG_RANDOM, 0));
65  GNUNET_assert (0 ==
66  gcry_prime_generate (&q,
68  0, NULL, NULL, NULL,
69  GCRY_STRONG_RANDOM, 0));
70  }
71  while (0 == gcry_mpi_cmp (p, q));
72  /* n = p * q */
73  GNUNET_assert (NULL != (n = gcry_mpi_new (0)));
74  gcry_mpi_mul (n,
75  p,
76  q);
78  sizeof(struct
80  n);
81 
82  /* compute phi(n) = (p-1)(q-1) */
83  GNUNET_assert (NULL != (phi = gcry_mpi_new (0)));
84  gcry_mpi_sub_ui (p, p, 1);
85  gcry_mpi_sub_ui (q, q, 1);
86  gcry_mpi_mul (phi, p, q);
87  gcry_mpi_release (p);
88  gcry_mpi_release (q);
89 
90  /* lambda equals phi(n) in the simplified key generation */
93  phi);
94  /* mu = phi^{-1} mod n, as we use g = n + 1 */
95  GNUNET_assert (NULL != (mu = gcry_mpi_new (0)));
96  GNUNET_assert (0 != gcry_mpi_invm (mu,
97  phi,
98  n));
99  gcry_mpi_release (phi);
100  gcry_mpi_release (n);
101  GNUNET_CRYPTO_mpi_print_unsigned (private_key->mu,
103  mu);
104  gcry_mpi_release (mu);
105 }
#define GNUNET_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:78
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 220 of file crypto_paillier.c.

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

References ciphertext, GNUNET_assert, GNUNET_break_op, GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_CRYPTO_mpi_scan_unsigned(), GNUNET_CRYPTO_PAILLIER_BITS, GNUNET_MIN, GNUNET_SYSERR, and m.

Referenced by compute_service_response(), and send_alices_cryptodata_message().

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

◆ GNUNET_CRYPTO_paillier_decrypt()

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

Decrypt a paillier ciphertext with a private key.

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

Definition at line 327 of file crypto_paillier.c.

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

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

Referenced by compute_scalar_product(), and keygen_round2_new_element().

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

◆ GNUNET_CRYPTO_paillier_hom_add()

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

Compute a ciphertext that represents the sum of the plaintext in c1 and c2.

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

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

Definition at line 391 of file crypto_paillier.c.

398 {
399  gcry_mpi_t a;
400  gcry_mpi_t b;
401  gcry_mpi_t c;
402  gcry_mpi_t n;
403  gcry_mpi_t n_square;
404  int32_t o1;
405  int32_t o2;
406 
407  o1 = (int32_t) ntohl (c1->remaining_ops);
408  o2 = (int32_t) ntohl (c2->remaining_ops);
409  if ((0 >= o1) || (0 >= o2))
410  {
411  GNUNET_break_op (0);
412  return GNUNET_SYSERR;
413  }
414 
416  c1->bits,
417  sizeof(c1->bits));
419  c2->bits,
420  sizeof(c2->bits));
422  public_key,
423  sizeof(struct
425 
426  /* n_square = n * n */
427  GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
428  gcry_mpi_mul (n_square, n, n);
429  gcry_mpi_release (n);
430 
431  /* c = a * b mod n_square */
432  GNUNET_assert (0 != (c = gcry_mpi_new (0)));
433  gcry_mpi_mulm (c, a, b, n_square);
434  gcry_mpi_release (n_square);
435  gcry_mpi_release (a);
436  gcry_mpi_release (b);
437 
438  result->remaining_ops = htonl (GNUNET_MIN (o1, o2) - 1);
440  sizeof(result->bits),
441  c);
442  gcry_mpi_release (c);
443  return ntohl (result->remaining_ops);
444 }
int32_t remaining_ops
Guaranteed minimum number of homomorphic operations with this ciphertext, in network byte order (NBO)...
unsigned char bits[2048 *2/8]
The bits of the ciphertext.

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

Referenced by compute_service_response().

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

◆ GNUNET_CRYPTO_paillier_hom_get_remaining()

int GNUNET_CRYPTO_paillier_hom_get_remaining ( const struct GNUNET_CRYPTO_PaillierCiphertext c)

Get the number of remaining supported homomorphic operations.

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

Definition at line 454 of file crypto_paillier.c.

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

References GNUNET_assert, and GNUNET_CRYPTO_PaillierCiphertext::remaining_ops.

◆ GNUNET_CRYPTO_rsa_private_key_create()

struct GNUNET_CRYPTO_RsaPrivateKey* GNUNET_CRYPTO_rsa_private_key_create ( unsigned int  len)

Create a new private key.

Caller must free return value.

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

Definition at line 143 of file crypto_rsa.c.

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

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

Referenced by output_vectors().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_private_key_free()

void GNUNET_CRYPTO_rsa_private_key_free ( struct GNUNET_CRYPTO_RsaPrivateKey key)

Free memory occupied by the private key.

Parameters
keypointer to the memory to free

Definition at line 172 of file crypto_rsa.c.

173 {
174  gcry_sexp_release (key->sexp);
175  GNUNET_free (key);
176 }

References GNUNET_free, and key.

Referenced by GNUNET_CRYPTO_rsa_private_key_decode(), and output_vectors().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_rsa_private_key_encode()

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

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

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

Definition at line 180 of file crypto_rsa.c.

183 {
184  size_t n;
185  char *b;
186 
187  n = gcry_sexp_sprint (key->sexp,
188  GCRYSEXP_FMT_DEFAULT,