GNUnet 0.26.2-20-ga2d76f2e4
 
Loading...
Searching...
No Matches
Crypto library: hash operations

Provides hashing and operations on hashes. More...

Collaboration diagram for Crypto library: hash operations:

Macros

#define GNUNET_CRYPTO_hash_from_string(enc, result)    GNUNET_CRYPTO_hash_from_string2 (enc, strlen (enc), result)
 Convert ASCII encoding back to struct GNUNET_HashCode
 
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len, ...)
 A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
 
#define GNUNET_CRYPTO_hkdf_expand(result, out_len, prk, ...)
 HKDF-Expand using SHA256.
 

Functions

uint8_t GNUNET_CRYPTO_crc8_n (const void *buf, size_t len)
 Calculate the checksum of a buffer in one step.
 
uint16_t GNUNET_CRYPTO_crc16_n (const void *buf, size_t len)
 Calculate the checksum of a buffer in one step.
 
int32_t GNUNET_CRYPTO_crc32_n (const void *buf, size_t len)
 Compute the CRC32 checksum for the first len bytes of the buffer.
 
void GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block, struct GNUNET_CRYPTO_HashAsciiEncoded *result)
 Convert hash to ASCII encoding.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, struct GNUNET_HashCode *result)
 Convert ASCII encoding back to a 'struct GNUNET_HashCode'.
 
uint32_t GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b)
 Compute the distance between 2 hashcodes.
 
void GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode *ret)
 Compute hash of a given block.
 
void GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
 Calculate HMAC of a message (RFC 2104)
 
struct GNUNET_CRYPTO_FileHashContextGNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, void *callback_cls)
 Compute the hash of an entire file.
 
void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, struct GNUNET_HashCode *result)
 Create a random hash code.
 
void GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
 compute result = b - a
 
void GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *delta, struct GNUNET_HashCode *result)
 compute result = a + delta
 
void GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
 compute result = a ^ b
 
void GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
 Convert a hashcode into a key.
 
int GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
 Compare function for HashCodes, producing a total ordering of all hashcodes.
 
int GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2, const struct GNUNET_HashCode *target)
 Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia).
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_extract (struct GNUNET_ShortHashCode *prk, const void *salt, size_t salt_len, const void *ikm, size_t ikm_len)
 HKDF-Extract using SHA256.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_gnunet_v (void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, size_t hkdf_args_count, const struct GNUNET_CRYPTO_KdfInputArgument hkdf_args[hkdf_args_count])
 Derive key.
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_expand_v (void *result, size_t out_len, const struct GNUNET_ShortHashCode *prk, size_t hkdf_args_count, const struct GNUNET_CRYPTO_KdfInputArgument hkdf_args[hkdf_args_count])
 HKDF-Expand using SHA256.
 

Detailed Description

Provides hashing and operations on hashes.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_CRYPTO_hash_from_string

#define GNUNET_CRYPTO_hash_from_string (   enc,
  result 
)     GNUNET_CRYPTO_hash_from_string2 (enc, strlen (enc), result)

Convert ASCII encoding back to struct GNUNET_HashCode

Parameters
encthe encoding
resultwhere to store the hash code
Returns
GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding

Definition at line 1010 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_hkdf_gnunet

#define GNUNET_CRYPTO_hkdf_gnunet (   result,
  out_len,
  xts,
  xts_len,
  skm,
  skm_len,
  ... 
)
Value:
GNUNET_CRYPTO_hkdf_gnunet_v (result, out_len, xts, xts_len, skm, \
skm_len, \
_HKDF_ARGS_VECLEN_HELPER (__VA_ARGS__ \
), \
_HKDF_ARGS_VEC_HELPER (__VA_ARGS__))
static int result
Global testing status.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_gnunet_v(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, size_t hkdf_args_count, const struct GNUNET_CRYPTO_KdfInputArgument hkdf_args[hkdf_args_count])
Derive key.
#define _HKDF_ARGS_VEC_HELPER(...)
#define _HKDF_ARGS_VECLEN_HELPER(...)

A peculiar HKDF instantiation that tried to mimic Truncated NMAC.

But, what it actually does is HKDF-Extract with SHA512 and instead of truncating the PRK, it uses it as a 64 byte key in the HKDF-Expand phase with SHA256. (Truncated NMAC would require us to, well, truncate it to 32 byte.) ONLY USE FOR COMPATIBILITY WITH OLDER KEY DERIVATIONS. Use the more standard GNUNET_CRYPTO_hkdf_extract and #GNUNET_CRYPTO_HKDF_expand instead!

"Finally, we point out to a particularly advantageous instantiation using HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from SHA-512 is truncated to 256 bits). This makes sense in two ways: First, the extraction part is where we need a stronger hash function due to the unconventional demand from the hash function in the extraction setting. Second, as shown in Section 6, using HMAC with a truncated output as an extractor allows to prove the security of HKDF under considerably weaker assumptions on the underlying hash function."

http://eprint.iacr.org/2010/264

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
...set of struct GNUNET_CRYPTO_KdfInputArgument for context chunks
Returns
GNUNET_YES on success

Definition at line 1449 of file gnunet_crypto_lib.h.

◆ GNUNET_CRYPTO_hkdf_expand

#define GNUNET_CRYPTO_hkdf_expand (   result,
  out_len,
  prk,
  ... 
)
Value:
prk, \
_HKDF_ARGS_VECLEN_HELPER (__VA_ARGS__ \
), \
_HKDF_ARGS_VEC_HELPER (__VA_ARGS__))
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_expand_v(void *result, size_t out_len, const struct GNUNET_ShortHashCode *prk, size_t hkdf_args_count, const struct GNUNET_CRYPTO_KdfInputArgument hkdf_args[hkdf_args_count])
HKDF-Expand using SHA256.

HKDF-Expand using SHA256.

RFC 5869

Parameters
resultbuffer for the derived key, allocated by caller
out_lendesired length of the derived key
prkpesudorandom key
...set of struct GNUNET_CRYPTO_KdfInputArgument for context chunks
Returns
GNUNET_YES on success

Definition at line 1490 of file gnunet_crypto_lib.h.

Function Documentation

◆ GNUNET_CRYPTO_crc8_n()

uint8_t GNUNET_CRYPTO_crc8_n ( const void *  buf,
size_t  len 
)

Calculate the checksum of a buffer in one step.

Parameters
bufbuffer to calculate CRC over
lennumber of bytes in buf
Returns
crc8 value

Definition at line 151 of file crypto_crc.c.

153{
154 const uint8_t *data = buf;
155 unsigned int crc = 0;
156 int i;
157 int j;
158
159 for (j = len; 0 != j; j--)
160 {
161 crc ^= (*data++ << 8);
162 for (i = 8; 0 != i; i--)
163 {
164 if (0 != (crc & 0x8000))
165 crc ^= (0x1070 << 3);
166 crc <<= 1;
167 }
168 }
169 return (uint8_t) (crc >> 8);
170}
static char * data
The data to insert into the dht.

References data.

◆ GNUNET_CRYPTO_crc16_n()

uint16_t GNUNET_CRYPTO_crc16_n ( const void *  buf,
size_t  len 
)

Calculate the checksum of a buffer in one step.

Parameters
bufbuffer to calculate CRC over (must be 16-bit aligned)
lennumber of bytes in buf, must be multiple of 2
Returns
crc16 value

Definition at line 133 of file crypto_crc.c.

134{
135 const uint16_t *hdr = buf;
136 uint32_t sum = GNUNET_CRYPTO_crc16_step (0, hdr, len);
137
138 return GNUNET_CRYPTO_crc16_finish (sum);
139}
uint16_t GNUNET_CRYPTO_crc16_finish(uint32_t sum)
Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
Definition crypto_crc.c:123
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.
Definition crypto_crc.c:110

References GNUNET_CRYPTO_crc16_finish(), and GNUNET_CRYPTO_crc16_step().

Referenced by GNUNET_TUN_initialize_ipv4_header().

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

◆ GNUNET_CRYPTO_crc32_n()

int32_t GNUNET_CRYPTO_crc32_n ( const void *  buf,
size_t  len 
)

Compute the CRC32 checksum for the first len bytes of the buffer.

Parameters
bufthe data over which we're taking the CRC
lenthe length of the buffer buf in bytes
Returns
the resulting CRC32 checksum

Definition at line 99 of file crypto_crc.c.

100{
101 GNUNET_uLong crc;
102
103 crc = gn_crc32 (0L, Z_NULL, 0);
104 crc = gn_crc32 (crc, (char *) buf, len);
105 return crc;
106}
static GNUNET_uLong gn_crc32(GNUNET_uLong crc, const char *buf, size_t len)
Definition crypto_crc.c:87
#define Z_NULL
Definition crypto_crc.c:45

References gn_crc32(), and Z_NULL.

Referenced by ibf_get_indices(), read_handle_encryption_key(), read_handle_epoch_key(), store_handle_encryption_key(), and store_handle_epoch_key().

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

◆ GNUNET_CRYPTO_hash_to_enc()

void GNUNET_CRYPTO_hash_to_enc ( const struct GNUNET_HashCode block,
struct GNUNET_CRYPTO_HashAsciiEncoded result 
)

Convert hash to ASCII encoding.

Parameters
blockthe hash code
resultwhere to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be safely cast to char*, a '\0' termination is set).

Definition at line 55 of file crypto_hash.c.

57{
58 char *np;
59
60 np = GNUNET_STRINGS_data_to_string ((const unsigned char *) block,
61 sizeof(struct GNUNET_HashCode),
62 (char *) result,
63 sizeof(struct
65 - 1);
66 GNUNET_assert (NULL != np);
67 *np = '\0';
68}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:757
0-terminated ASCII encoding of a struct GNUNET_HashCode.
A 512-bit hashcode.

References GNUNET_assert, GNUNET_STRINGS_data_to_string(), and result.

Referenced by get_update_information_directory(), GNUNET_e2s(), GNUNET_e2s2(), GNUNET_h2s(), GNUNET_h2s2(), GNUNET_h2s_full(), GNUNET_NETWORK_shorten_unixpath(), GNUNET_p2s(), GNUNET_p2s2(), store_and_free_entries(), uri_chk_to_string(), and uri_loc_to_string().

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

◆ GNUNET_CRYPTO_hash_from_string2()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hash_from_string2 ( const char *  enc,
size_t  enclen,
struct GNUNET_HashCode result 
)

Convert ASCII encoding back to a 'struct GNUNET_HashCode'.

Parameters
encthe encoding
enclennumber of characters in enc (without 0-terminator, which can be missing)
resultwhere to store the hash code
Returns
GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding

Definition at line 72 of file crypto_hash.c.

75{
77 char *up_ptr;
78
80 if (NULL == up_ptr)
81 return GNUNET_SYSERR;
83 strlen (up_ptr),
84 (unsigned char *) result,
85 sizeof(struct GNUNET_HashCode));
86 GNUNET_free (up_ptr);
87 return ret;
88}
static int ret
Final status code.
Definition gnunet-arm.c:93
static OpusEncoder * enc
OPUS encoder.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_utf8_toupper(const char *input)
Convert the utf-8 input string to upper case.
Definition strings.c:500
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:837

References enc, GNUNET_free, GNUNET_STRINGS_string_to_data(), GNUNET_STRINGS_utf8_toupper(), GNUNET_SYSERR, result, and ret.

Here is the call graph for this function:

◆ GNUNET_CRYPTO_hash_distance_u32()

uint32_t GNUNET_CRYPTO_hash_distance_u32 ( const struct GNUNET_HashCode a,
const struct GNUNET_HashCode b 
)

Compute the distance between 2 hashcodes.

The computation must be fast, not involve a[0] or a[4] (they're used elsewhere), and be somewhat consistent. And of course, the result should be a positive number.

Parameters
asome hash code
bsome hash code
Returns
number between 0 and UINT32_MAX

Definition at line 92 of file crypto_hash.c.

94{
95 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16;
96 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16;
97
98 return(x1 * x2);
99}
uint32_t bits[512/8/sizeof(uint32_t)]

References GNUNET_HashCode::bits.

Referenced by score_content().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash()

void GNUNET_CRYPTO_hash ( const void *  block,
size_t  size,
struct GNUNET_HashCode ret 
)

Compute hash of a given block.

Parameters
blockthe data to hash
sizesize of the block
retpointer to where to write the hashcode

Definition at line 41 of file crypto_hash.c.

44{
45 BENCHMARK_START (hash);
46 gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size);
47 BENCHMARK_END (hash);
48}
#define BENCHMARK_START(opname)
Definition benchmark.h:57
#define BENCHMARK_END(opname)
Definition benchmark.h:58
static unsigned int size
Size of the "table".
Definition peer.c:68

References BENCHMARK_END, BENCHMARK_START, ret, and size.

Referenced by add_file(), add_member_session(), add_to_keyword_counter(), add_to_meta_counter(), advertise_dns_exit(), automaton_create_proofs(), block_plugin_dht_check_block(), block_plugin_dht_check_reply(), block_plugin_dht_get_key(), block_plugin_dns_check_reply(), block_plugin_fs_check_reply(), block_plugin_fs_get_key(), block_plugin_gns_check_reply(), block_plugin_regex_check_reply(), block_plugin_revocation_get_key(), block_plugin_test_check_reply(), build_authz_response(), calculate_hmac(), calculate_hmac(), check_and_remove_pending_reversal(), check_and_remove_pending_reversal(), checkvec(), client_request_complete_alice(), code_redirect(), collector(), commit_set(), connection_destroy(), consume_fail(), consume_ticket(), convert_messenger_key_to_port(), cookie_identity_interpretation(), create_peers(), create_response(), create_stream(), create_subnet_peers(), create_subnets(), create_target(), cs_full_domain_hash(), data_to_ecdsa_value(), decode_short_message(), decrypt_new_element(), delayed_put(), determine_id(), ego_get_all(), ego_get_response(), ego_sign_data(), encode_short_message(), encrypt_existing_match(), es_to_sh(), extract_blind_sign_pub(), find_advertisable_hello(), find_stream(), find_target(), find_trees(), forward_reply(), GC_u2h(), GCT_handle_kx_auth(), GDS_helper_sign_path(), GDS_try_connect(), GDS_u_connect(), get_cadet(), get_context_from_member(), get_destination_key_from_ip(), get_fair_encryption_challenge(), get_file_handle(), get_gns_cont(), get_matching_bits(), get_member_session(), get_node_info(), get_store_contact(), get_update_information_directory(), get_url_parameter_copy(), GNUNET_b2s(), GNUNET_BLOCK_mingle_hash(), GNUNET_CONVERSATION_phone_create(), GNUNET_CRYPTO_blind_sign_keys_create_va(), GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdh_ecdsa(), GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_ecdsa_ecdh(), GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_CRYPTO_edx25519_key_create_from_seed(), GNUNET_CRYPTO_rsa_public_key_hash(), GNUNET_DHT_verify_path(), GNUNET_e2s(), GNUNET_e2s2(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_namespace_list_updateable(), GNUNET_FS_publish_ublock_(), GNUNET_FS_search_start_searching_(), GNUNET_FS_tree_encoder_next(), GNUNET_FS_unindex_do_remove_kblocks_(), GNUNET_FS_uri_to_key(), GNUNET_GNSRECORD_query_from_block(), GNUNET_GNSRECORD_query_from_public_key(), GNUNET_IDENTITY_ego_get_anonymous(), GNUNET_MESSENGER_create_room_key(), GNUNET_NETWORK_shorten_unixpath(), GNUNET_p2s(), GNUNET_p2s2(), GNUNET_TESTING_barrier_name_hash_(), GNUNET_TESTING_get_topo_from_string_(), GNUNET_TESTING_interpreter_get_command(), GNUNET_TESTING_interpreter_run_cmd_(), GNUNET_TUN_service_name_to_hash(), GSF_cadet_start_server(), handle_client_decrypt(), handle_core_connect(), handle_identity_update(), handle_identity_update(), handle_initiator_hello(), handle_initiator_hello_cont(), handle_put(), handle_query_message(), handle_regex_result(), hash_message(), hash_pkey_and_label(), header_iterator(), iface_proc(), init_socket(), init_socket(), insert_decrypt_element(), insert_round1_element(), iterate_initial_edge(), iterateBits(), join_room_run(), load_state(), login_cont(), lookup_diff(), lookup_rfn(), lookup_set(), lookup_task(), maint_child_death(), mq_init(), mq_init(), mq_init(), mq_init(), namestore_get(), notify_connect(), notify_srv_handle_message(), ns_lookup_result_cb(), output_vectors(), parse_credentials_basic_auth(), parse_credentials_post_body(), peer_destroy(), PEERSTORE_hash_key(), pending_reversal_timeout(), pending_reversal_timeout(), pid_change_cb(), pils_sign_address(), post_data_iter(), postgres_plugin_put(), process(), process_client_result(), process_kblock_for_unindex(), process_reply(), publicize_rm(), put_diff(), put_rfn(), put_set(), put_task(), queue(), queue_destroy(), queue_destroy(), REGEX_BLOCK_check_proof(), REGEX_BLOCK_get_key(), REGEX_INTERNAL_get_first_key(), remove_high_frequency_keywords(), remove_member_session(), remove_room_member_session(), remove_store_contact(), remove_stream(), reset_cadet(), restart_kx(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), schedule_next_hello(), schedule_transmit_search_request(), score_content(), select_store_contact_map(), send_initiator_hello(), send_kx_auth(), setup_filter(), sock_read(), sock_read(), sock_read(), sqlite_plugin_put(), start_address_validation(), start_intersection(), store_handle_encryption_key(), token_endpoint(), try_match_block(), try_open_exit(), try_top_down_reconstruction(), update_store_contact(), url_iterator(), and userinfo_endpoint().

◆ GNUNET_CRYPTO_hmac()

void GNUNET_CRYPTO_hmac ( const struct GNUNET_CRYPTO_AuthKey key,
const void *  plaintext,
size_t  plaintext_len,
struct GNUNET_HashCode hmac 
)

Calculate HMAC of a message (RFC 2104)

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

Definition at line 295 of file crypto_hash.c.

298{
299 GNUNET_CRYPTO_hmac_raw ((void *) key->key, sizeof(key->key),
300 plaintext, plaintext_len,
301 hmac);
302}
struct GNUNET_HashCode key
The key used in the DHT.
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 abo...

References GNUNET_CRYPTO_hmac_raw(), and key.

Referenced by calc_message_hmac(), decrypt_secret_message(), dv_hmac(), encrypt_secret_message(), generate_initiator_finished(), generate_responder_finished(), RPS_sampler_elem_next(), t_ax_hmac_hash(), and t_hmac().

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

◆ GNUNET_CRYPTO_hash_file()

struct GNUNET_CRYPTO_FileHashContext * GNUNET_CRYPTO_hash_file ( enum GNUNET_SCHEDULER_Priority  priority,
const char *  filename,
size_t  blocksize,
GNUNET_CRYPTO_HashCompletedCallback  callback,
void *  callback_cls 
)

Compute the hash of an entire file.

Parameters
priorityscheduling priority to use
filenamename of file to hash
blocksizenumber of bytes to process in one task
callbackfunction to call upon completion
callback_clsclosure for callback
Returns
NULL on (immediate) error

Definition at line 169 of file crypto_hash_file.c.

174{
176
177 GNUNET_assert (blocksize > 0);
178 GNUNET_assert (blocksize <= (SIZE_MAX - sizeof (*fhc)));
179 fhc =
180 GNUNET_malloc (sizeof(*fhc) + blocksize);
181 fhc->callback = callback;
183 fhc->buffer = (unsigned char *) &fhc[1];
185 if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0))
186 {
187 GNUNET_break (0);
188 GNUNET_free (fhc->filename);
189 GNUNET_free (fhc);
190 return NULL;
191 }
192 fhc->bsize = blocksize;
193 if (GNUNET_OK !=
195 &fhc->fsize,
196 GNUNET_NO,
197 GNUNET_YES))
198 {
199 GNUNET_free (fhc->filename);
200 GNUNET_free (fhc);
201 return NULL;
202 }
206 if (! fhc->fh)
207 {
208 GNUNET_free (fhc->filename);
209 GNUNET_free (fhc);
210 return NULL;
211 }
212 fhc->priority = priority;
215 fhc);
216 return fhc;
217}
static void file_hash_task(void *cls)
File hashing task.
static char * filename
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition disk.c:1308
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition disk.c:235
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition scheduler.c:1237
#define SIZE_MAX
Definition platform.h:209
Context used when hashing a file.
uint64_t fsize
Size of the file.
gcry_md_hd_t md
Cumulated hash.
unsigned char * buffer
IO buffer.
GNUNET_CRYPTO_HashCompletedCallback callback
Function to call upon completion.
struct GNUNET_DISK_FileHandle * fh
File descriptor.
void * callback_cls
Closure for callback.
struct GNUNET_SCHEDULER_Task * task
Current task for hashing.
char * filename
Name of the file we are hashing.
enum GNUNET_SCHEDULER_Priority priority
Priority we use.

References GNUNET_CRYPTO_FileHashContext::bsize, GNUNET_CRYPTO_FileHashContext::buffer, GNUNET_CRYPTO_FileHashContext::callback, GNUNET_CRYPTO_FileHashContext::callback_cls, GNUNET_CRYPTO_FileHashContext::fh, file_hash_task(), filename, GNUNET_CRYPTO_FileHashContext::filename, GNUNET_CRYPTO_FileHashContext::fsize, GNUNET_assert, GNUNET_break, GNUNET_DISK_file_open(), GNUNET_DISK_file_size(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_free, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_with_priority(), GNUNET_strdup, GNUNET_YES, GNUNET_CRYPTO_FileHashContext::md, GNUNET_CRYPTO_FileHashContext::priority, SIZE_MAX, and GNUNET_CRYPTO_FileHashContext::task.

Referenced by deserialize_unindex_file(), GNUNET_FS_publish_main_(), GNUNET_FS_unindex_start(), and handle_client_index_start().

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

◆ GNUNET_CRYPTO_hash_create_random()

void GNUNET_CRYPTO_hash_create_random ( enum GNUNET_CRYPTO_Quality  mode,
struct GNUNET_HashCode result 
)

Create a random hash code.

Parameters
modedesired quality level
resulthash code that is randomized

Definition at line 103 of file crypto_hash.c.

105{
107}
static enum @49 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.

References GNUNET_CRYPTO_random_block(), mode, and result.

Referenced by commit_set(), run(), and run().

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

◆ GNUNET_CRYPTO_hash_difference()

void GNUNET_CRYPTO_hash_difference ( const struct GNUNET_HashCode a,
const struct GNUNET_HashCode b,
struct GNUNET_HashCode result 
)

compute result = b - a

Parameters
asome hash code
bsome hash code
resultset to b - a

Definition at line 111 of file crypto_hash.c.

114{
115 for (ssize_t i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1;
116 i >= 0;
117 i--)
118 result->bits[i] = b->bits[i] - a->bits[i];
119}

References GNUNET_HashCode::bits, and result.

◆ GNUNET_CRYPTO_hash_sum()

void GNUNET_CRYPTO_hash_sum ( const struct GNUNET_HashCode a,
const struct GNUNET_HashCode delta,
struct GNUNET_HashCode result 
)

compute result = a + delta

Parameters
asome hash code
deltasome hash code
resultset to a + delta

Definition at line 123 of file crypto_hash.c.

126{
127 for (ssize_t i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1;
128 i >= 0;
129 i--)
130 result->bits[i] = delta->bits[i] + a->bits[i];
131}
static struct GNUNET_TIME_Relative delta
Definition speedup.c:36

References GNUNET_HashCode::bits, delta, and result.

Referenced by convert_messenger_key_to_port().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_xor()

void GNUNET_CRYPTO_hash_xor ( const struct GNUNET_HashCode a,
const struct GNUNET_HashCode b,
struct GNUNET_HashCode result 
)

compute result = a ^ b

Parameters
asome hash code
bsome hash code
resultset to a ^ b

Definition at line 135 of file crypto_hash.c.

138{
139 const unsigned long long *lla = (const unsigned long long *) a;
140 const unsigned long long *llb = (const unsigned long long *) b;
141 unsigned long long *llr = (unsigned long long *) result;
142
143 GNUNET_static_assert (8 == sizeof (unsigned long long));
144 GNUNET_static_assert (0 == sizeof (*a) % sizeof (unsigned long long));
145
146 for (int i = sizeof (*result) / sizeof (*llr) - 1; i>=0; i--)
147 llr[i] = lla[i] ^ llb[i];
148}
#define GNUNET_static_assert(cond)
Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime an...

References GNUNET_static_assert, and result.

Referenced by determine_id(), filter_all(), filter_all(), filtered_map_initialization(), filtered_map_initialization(), find_bucket(), GDS_DATACACHE_handle_put(), get_context_from_member(), get_matching_bits(), initialize_map_unfiltered(), initialize_map_unfiltered(), iterator_bf_reduce(), iterator_bf_reduce(), process_sks_result(), and select_peer().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_to_aes_key()

void GNUNET_CRYPTO_hash_to_aes_key ( const struct GNUNET_HashCode hc,
struct GNUNET_CRYPTO_SymmetricSessionKey skey,
struct GNUNET_CRYPTO_SymmetricInitializationVector iv 
)

Convert a hashcode into a key.

Parameters
hchash code that serves to generate the key
skeyset to a valid session key
ivset to a valid initialization vector

Definition at line 152 of file crypto_hash.c.

156{
159 skey,
160 sizeof(*skey),
161 "Hash key derivation",
162 strlen ("Hash key derivation"),
163 hc, sizeof(*hc)));
166 iv,
167 sizeof(*iv),
168 "Initialization vector derivation",
169 strlen ("Initialization vector derivation"),
170 hc, sizeof(*hc)));
171}
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.

References GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet, and GNUNET_YES.

Referenced by derive_ublock_encryption_key(), encrypt_existing_match(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_tree_encoder_next(), process_result_with_request(), and try_match_block().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_cmp()

int GNUNET_CRYPTO_hash_cmp ( const struct GNUNET_HashCode h1,
const struct GNUNET_HashCode h2 
)

Compare function for HashCodes, producing a total ordering of all hashcodes.

Parameters
h1some hash code
h2some hash code
Returns
1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.

Definition at line 219 of file crypto_hash.c.

221{
222 unsigned int *i1;
223 unsigned int *i2;
224
225 i1 = (unsigned int *) h1;
226 i2 = (unsigned int *) h2;
227 for (ssize_t i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1;
228 i >= 0;
229 i--)
230 {
231 if (i1[i] > i2[i])
232 return 1;
233 if (i1[i] < i2[i])
234 return -1;
235 }
236 return 0;
237}

Referenced by check_member_session_completion(), clear_linked_hash(), create_message_request(), decode_short_message(), decrypt_secret_message(), do_generate_pid(), element_cmp(), element_cmp(), element_cmp(), element_cmp(), find_closest(), find_linked_hash(), get_epoch_membership_member_hash(), get_epoch_membership_member_position(), get_epoch_previous_announcement(), get_epoch_previous_group(), get_store_message(), handle_access_message(), handle_client_join(), handle_core_connect(), handle_initiator_hello_cont(), is_epoch_previous_of_other(), it_update_epoch_member(), iterate_cancel_action_by(), op_get_element_iterator(), op_get_element_iterator(), propose_epoch_group(), put_store_message(), REGEX_BLOCK_check_proof(), remove_from_list_messages(), restart_kx(), RPS_sampler_elem_next(), select_store_contact_map(), send_epoch_group(), send_message_to_room(), and verify_message_by_key().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hash_xorcmp()

int GNUNET_CRYPTO_hash_xorcmp ( const struct GNUNET_HashCode h1,
const struct GNUNET_HashCode h2,
const struct GNUNET_HashCode target 
)

Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia).

Parameters
h1some hash code
h2some hash code
targetsome hash code
Returns
-1 if h1 is closer, 1 if h2 is closer and 0 if h1== h2.

Definition at line 241 of file crypto_hash.c.

244{
245 const unsigned long long *l1 = (const unsigned long long *) h1;
246 const unsigned long long *l2 = (const unsigned long long *) h2;
247 const unsigned long long *t = (const unsigned long long *) target;
248
249 GNUNET_static_assert (0 == sizeof (*h1) % sizeof (*l1));
250 for (size_t i = 0; i < sizeof(*h1) / sizeof(*l1); i++)
251 {
252 unsigned long long x1 = l1[i] ^ t[i];
253 unsigned long long x2 = l2[i] ^ t[i];
254
255 if (x1 > x2)
256 return 1;
257 if (x1 < x2)
258 return -1;
259 }
260 return 0;
261}
static struct GNUNET_SCHEDULER_Task * t
Main task.

References GNUNET_static_assert, and t.

Referenced by GDS_am_closest_peer(), and select_peer().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hkdf_extract()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_extract ( struct GNUNET_ShortHashCode prk,
const void *  salt,
size_t  salt_len,
const void *  ikm,
size_t  ikm_len 
)

HKDF-Extract using SHA256.

RFC 5869

Parameters
prkthe PRK
saltsalt
salt_lenlength of xts
ikmsource key material
ikm_lenlength of skm
Returns
GNUNET_YES on success

Definition at line 182 of file crypto_hkdf.c.

187{
188 crypto_auth_hmacsha256_state st;
189 if (crypto_auth_hmacsha256_init (&st, xts, xts_len))
190 return GNUNET_SYSERR;
191 if (crypto_auth_hmacsha256_update (&st, skm, skm_len))
192 return GNUNET_SYSERR;
193 crypto_auth_hmacsha256_final (&st, (unsigned char*) prk);
194 sodium_memzero (&st, sizeof st);
195 return GNUNET_OK;
196}
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.

References GNUNET_OK, GNUNET_SYSERR, and st.

Referenced by derive_es_ets(), derive_hs(), derive_ms(), get_kid(), GNUNET_PILS_derive_pid(), and labeled_extract().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_hkdf_gnunet_v()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_gnunet_v ( void *  result,
size_t  out_len,
const void *  xts,
size_t  xts_len,
const void *  skm,
size_t  skm_len,
size_t  hkdf_args_count,
const struct GNUNET_CRYPTO_KdfInputArgument  hkdf_args[hkdf_args_count] 
)

Derive key.

See GNUNET_CRYPTO_hkdf_gnunet

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
hkdf_args_countsize of the input argument array that follows
hkdf_argsarray of struct GNUNET_CRYPTO_KdfInputArgument for context chunks
Returns
GNUNET_YES on success

◆ GNUNET_CRYPTO_hkdf_expand_v()

enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_expand_v ( void *  result,
size_t  out_len,
const struct GNUNET_ShortHashCode prk,
size_t  hkdf_args_count,
const struct GNUNET_CRYPTO_KdfInputArgument  hkdf_args[hkdf_args_count] 
)

HKDF-Expand using SHA256.

See GNUNET_CRYPTO_hkdf_expand

Parameters
resultbuffer for the derived key, allocated by caller
out_lendesired length of the derived key
prkpesudorandom key
hkdf_args_countsize of the input argument array that follows
hkdf_argsarray of struct GNUNET_CRYPTO_KdfInputArgument for context chunks
Returns
GNUNET_YES on success