Provides hashing and operations on hashes. More...
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 More... | |
Functions | |
uint8_t | GNUNET_CRYPTO_crc8_n (const void *buf, size_t len) |
Calculate the checksum of a buffer in one step. More... | |
uint16_t | GNUNET_CRYPTO_crc16_n (const void *buf, size_t len) |
Calculate the checksum of a buffer in one step. More... | |
int32_t | GNUNET_CRYPTO_crc32_n (const void *buf, size_t len) |
Compute the CRC32 checksum for the first len bytes of the buffer. More... | |
void | GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block, struct GNUNET_CRYPTO_HashAsciiEncoded *result) |
Convert hash to ASCII encoding. More... | |
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'. More... | |
uint32_t | GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b) |
Compute the distance between 2 hashcodes. More... | |
void | GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode *ret) |
Compute hash of a given block. More... | |
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) More... | |
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. More... | |
void | GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, struct GNUNET_HashCode *result) |
Create a random hash code. More... | |
void | GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result) |
compute result = b - a More... | |
void | GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *delta, struct GNUNET_HashCode *result) |
compute result = a + delta More... | |
void | GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result) |
compute result = a ^ b More... | |
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. More... | |
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. More... | |
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). More... | |
void | GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len, va_list argp) |
Derive an authentication key. More... | |
void | GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...) |
Derive an authentication key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hkdf (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,...) |
Derive key. More... | |
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. More... | |
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. More... | |
Provides hashing and operations on hashes.
#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
enc | the encoding |
result | where to store the hash code |
Definition at line 848 of file gnunet_crypto_lib.h.
uint8_t GNUNET_CRYPTO_crc8_n | ( | const void * | buf, |
size_t | len | ||
) |
Calculate the checksum of a buffer in one step.
buf | buffer to calculate CRC over |
len | number of bytes in buf |
Definition at line 151 of file crypto_crc.c.
uint16_t GNUNET_CRYPTO_crc16_n | ( | const void * | buf, |
size_t | len | ||
) |
Calculate the checksum of a buffer in one step.
buf | buffer to calculate CRC over (must be 16-bit aligned) |
len | number of bytes in buf, must be multiple of 2 |
Definition at line 133 of file crypto_crc.c.
References buf, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), len, and consensus-simulation::sum.
Referenced by GNUNET_TUN_initialize_ipv4_header().
int32_t GNUNET_CRYPTO_crc32_n | ( | const void * | buf, |
size_t | len | ||
) |
Compute the CRC32 checksum for the first len bytes of the buffer.
buf | the data over which we're taking the CRC |
len | the length of the buffer buf in bytes |
Definition at line 99 of file crypto_crc.c.
References buf, gn_crc32(), len, and Z_NULL.
Referenced by do_decrypt(), do_encrypt(), ibf_get_indices(), process_data(), and wlan_plugin_send().
void GNUNET_CRYPTO_hash_to_enc | ( | const struct GNUNET_HashCode * | block, |
struct GNUNET_CRYPTO_HashAsciiEncoded * | result | ||
) |
Convert hash to ASCII encoding.
block | the hash code |
result | where 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.
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().
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'.
enc | the encoding |
enclen | number of characters in enc (without 0-terminator, which can be missing) |
result | where to store the hash code |
Definition at line 55 of file crypto_hash.c.
References GNUNET_assert, GNUNET_STRINGS_data_to_string(), and result.
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.
a | some hash code |
b | some hash code |
Definition at line 89 of file crypto_hash.c.
References GNUNET_HashCode::bits.
Referenced by score_content().
void GNUNET_CRYPTO_hash | ( | const void * | block, |
size_t | size, | ||
struct GNUNET_HashCode * | ret | ||
) |
Compute hash of a given block.
block | the data to hash |
size | size of the block |
ret | pointer to where to write the hashcode |
Definition at line 41 of file crypto_hash.c.
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(), barrier_attached(), barrier_wait_cb(), bind_store_ego(), build_authz_response(), calculate_hmac(), callback_ego_create(), callback_ego_lookup(), callback_ego_rename(), check_and_remove_pending_reversal(), checkvec(), client_request_complete_alice(), code_redirect(), collector(), commit_set(), consume_fail(), consume_ticket(), convert_messenger_key_to_port(), cookie_identity_interpretation(), create_response(), create_target(), cs_full_domain_hash(), database_setup(), decode_short_message(), decrementBitCallback(), decrypt_new_element(), delayed_put(), delete_store_ego(), derive_aes_key(), derive_auth_key(), derive_iv(), derive_pong_iv(), determine_id(), do_flood(), do_rekey(), ego_get_all(), ego_get_response(), ego_sign_data(), encode_short_message(), encrypt_existing_match(), es_to_sh(), find_advertisable_hello(), find_target(), find_trees(), GC_u2h(), GCT_add_channel(), 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_ecc_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_HELLO_extract_address(), GNUNET_HELLO_sign_address(), GNUNET_IDENTITY_ego_get_anonymous(), GNUNET_NETWORK_shorten_unixpath(), GNUNET_p2s(), GNUNET_p2s2(), GNUNET_TESTBED_barrier_init_(), GNUNET_TESTING_barrier_get_node(), GNUNET_TESTING_get_topo_from_string(), GNUNET_TUN_service_name_to_hash(), GSC_KX_encrypt_and_transmit(), GSC_KX_init(), GSC_TYPEMAP_hash(), GSF_cadet_start_server(), handle_barrier_cancel(), handle_barrier_init(), handle_barrier_status(), handle_barrier_wait(), handle_client_decrypt(), handle_core_connect(), handle_encrypted(), handle_ephemeral_key(), handle_identity_update(), handle_put(), handle_regex_result(), handle_transport_notify_connect(), hash_message(), hash_pkey_and_label(), header_iterator(), iface_proc(), init_socket(), insert_decrypt_element(), insert_round1_element(), iterate_initial_edge(), load_state(), login_cont(), lookup_diff(), lookup_rfn(), lookup_set(), lookup_task(), maint_child_death(), mq_init(), mysql_plugin_put(), namestore_get(), notify_connect(), notify_srv_handle_message(), ns_lookup_result_cb(), on_identity(), on_peer(), output_vectors(), parse_credentials_basic_auth(), parse_credentials_post_body(), peerinfo_get(), peerstore_flat_store_record(), PEERSTORE_hash_key(), pending_reversal_timeout(), post_data_iter(), postgres_plugin_put(), process_kblock_for_unindex(), put_diff(), put_rfn(), put_set(), put_task(), queue(), 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(), reset_cadet(), run(), schedule_next_hello(), schedule_transmit_search_request(), score_content(), second_stage(), select_store_contact_map(), send_key(), send_kx_auth(), set_result_cb(), setup_filter(), sign_path(), sock_read(), sqlite_plugin_put(), start_helper(), start_intersection(), token_endpoint(), try_match_block(), try_open_exit(), try_top_down_reconstruction(), TST_interpreter_add_barrier(), TST_interpreter_get_barrier(), unbind_store_ego(), update_store_contact(), update_store_ego(), url_iterator(), and userinfo_endpoint().
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)
key | secret key |
plaintext | input plaintext |
plaintext_len | length of plaintext |
hmac | where to store the hmac |
Definition at line 329 of file crypto_hash.c.
References GNUNET_CRYPTO_hmac_raw(), and key.
Referenced by dv_hmac(), GSC_KX_encrypt_and_transmit(), handle_encrypted(), RPS_sampler_elem_next(), t_ax_hmac_hash(), and t_hmac().
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.
priority | scheduling priority to use |
filename | name of file to hash |
blocksize | number of bytes to process in one task |
callback | function to call upon completion |
callback_cls | closure for callback |
Definition at line 169 of file crypto_hash_file.c.
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, and GNUNET_CRYPTO_FileHashContext::task.
Referenced by deserialize_unindex_file(), GNUNET_FS_publish_main_(), GNUNET_FS_unindex_start(), and handle_client_index_start().
void GNUNET_CRYPTO_hash_create_random | ( | enum GNUNET_CRYPTO_Quality | mode, |
struct GNUNET_HashCode * | result | ||
) |
Create a random hash code.
mode | desired quality level |
result | hash code that is randomized |
Definition at line 100 of file crypto_hash.c.
References GNUNET_CRYPTO_random_u32(), mode, and result.
Referenced by commit_set(), do_consensus(), and run().
void GNUNET_CRYPTO_hash_difference | ( | const struct GNUNET_HashCode * | a, |
const struct GNUNET_HashCode * | b, | ||
struct GNUNET_HashCode * | result | ||
) |
compute result = b - a
a | some hash code |
b | some hash code |
result | set to b - a |
Definition at line 111 of file crypto_hash.c.
References GNUNET_HashCode::bits, and result.
void GNUNET_CRYPTO_hash_sum | ( | const struct GNUNET_HashCode * | a, |
const struct GNUNET_HashCode * | delta, | ||
struct GNUNET_HashCode * | result | ||
) |
compute result = a + delta
a | some hash code |
delta | some hash code |
result | set to a + delta |
Definition at line 123 of file crypto_hash.c.
References GNUNET_HashCode::bits, delta, and result.
Referenced by convert_messenger_key_to_port().
void GNUNET_CRYPTO_hash_xor | ( | const struct GNUNET_HashCode * | a, |
const struct GNUNET_HashCode * | b, | ||
struct GNUNET_HashCode * | result | ||
) |
compute result = a ^ b
a | some hash code |
b | some hash code |
result | set to a ^ b |
Definition at line 135 of file crypto_hash.c.
References GNUNET_static_assert, and result.
Referenced by add_known_to_bloom(), datacache_get_iterator(), determine_id(), filter_all(), filtered_map_initialization(), get_context_from_member(), get_matching_bits(), initialize_map_unfiltered(), iterator_bf_reduce(), process_sks_result(), and select_peer().
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.
hc | hash code that serves to generate the key |
skey | set to a valid session key |
iv | set to a valid initialization vector |
Definition at line 151 of file crypto_hash.c.
References GNUNET_assert, GNUNET_CRYPTO_kdf(), and GNUNET_YES.
Referenced by derive_ublock_encryption_key(), encrypt_existing_match(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_tree_encoder_next(), GNUNET_IDENTITY_decrypt(), GNUNET_IDENTITY_encrypt(), process_result_with_request(), and try_match_block().
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.
h1 | some hash code |
h2 | some hash code |
Definition at line 220 of file crypto_hash.c.
References consensus-simulation::int.
Referenced by check_member_session_completion(), create_message_request(), decode_short_message(), element_cmp(), get_store_message(), handle_client_join(), handle_core_connect(), handle_transport_notify_connect(), op_get_element_iterator(), REGEX_BLOCK_check_proof(), remove_from_list_messages(), RPS_sampler_elem_next(), and select_store_contact_map().
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).
h1 | some hash code |
h2 | some hash code |
target | some hash code |
Definition at line 242 of file crypto_hash.c.
References GNUNET_static_assert, and t.
Referenced by select_peer().
void GNUNET_CRYPTO_hmac_derive_key_v | ( | struct GNUNET_CRYPTO_AuthKey * | key, |
const struct GNUNET_CRYPTO_SymmetricSessionKey * | rkey, | ||
const void * | salt, | ||
size_t | salt_len, | ||
va_list | argp | ||
) |
Derive an authentication key.
key | authentication key |
rkey | root key |
salt | salt |
salt_len | size of the salt |
argp | pair of void * & size_t for context chunks, terminated by NULL |
Definition at line 285 of file crypto_hash.c.
References GNUNET_CRYPTO_kdf_v(), key, and salt.
Referenced by GNUNET_CRYPTO_hmac_derive_key().
void GNUNET_CRYPTO_hmac_derive_key | ( | struct GNUNET_CRYPTO_AuthKey * | key, |
const struct GNUNET_CRYPTO_SymmetricSessionKey * | rkey, | ||
const void * | salt, | ||
size_t | salt_len, | ||
... | |||
) |
Derive an authentication key.
key | authentication key |
rkey | root key |
salt | salt |
salt_len | size of the salt |
... | pair of void * & size_t for context chunks, terminated by NULL |
Definition at line 266 of file crypto_hash.c.
References GNUNET_CRYPTO_hmac_derive_key_v(), key, and salt.
Referenced by derive_auth_key(), t_ax_hmac_hash(), and t_hmac().
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf | ( | 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, | ||
... | |||
) |
Derive key.
result | buffer for the derived key, allocated by caller |
out_len | desired length of the derived key |
xtr_algo | hash algorithm for the extraction phase, GCRY_MD_... |
prf_algo | hash algorithm for the expansion phase, GCRY_MD_... |
xts | salt |
xts_len | length of xts |
skm | source key material |
skm_len | length of skm |
... | pair of void * & size_t for context chunks, terminated by NULL |
Definition at line 78 of file crypto_hkdf.c.
References buf, GNUNET_break, and key.
Referenced by calculate_cmac(), get_iv_key(), get_kid(), GNUNET_CRYPTO_cs_blinding_secrets_derive(), GNUNET_CRYPTO_cs_sign_derive(), and output_vectors().
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.
result | buffer for the derived key, allocated by caller |
out_len | desired length of the derived key |
xtr_algo | hash algorithm for the extraction phase, GCRY_MD_... |
prf_algo | hash algorithm for the expansion phase, GCRY_MD_... |
xts | salt |
xts_len | length of xts |
skm | source key material |
skm_len | length of skm |
argp | va_list of void * & size_t pairs for context chunks |
Definition at line 78 of file crypto_hkdf.c.
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.
result | buffer for the derived key, allocated by caller |
out_len | desired length of the derived key |
xts | salt |
xts_len | length of xts |
skm | source key material |
skm_len | length of skm |
... | void * & size_t pairs for context chunks |
Definition at line 1 of file crypto_kdf.c.
Referenced by checkvec(), compute_global_id(), derive_aes_key(), derive_h(), derive_ublock_encryption_key(), dh_key_derive_eph_pid(), GNR_derive_block_aes_key(), GNR_derive_block_xsalsa_key(), GNUNET_CRYPTO_cs_r_derive(), GNUNET_CRYPTO_ecdsa_sign_derived(), GNUNET_CRYPTO_hash_to_aes_key(), GNUNET_CRYPTO_kdf_mod_mpi(), hash_from_share_val(), output_vectors(), setup_cipher(), t_ax_decrypt_and_validate(), t_ax_encrypt(), t_hmac_derive_key(), and update_ax_by_kx().