|
Tor 0.4.9.8
|
Go to the source code of this file.
Macros | |
| #define | tor_memneq(a, b, sz) |
| #define | fast_memcmp(a, b, c) |
| #define | fast_memeq(a, b, c) |
| #define | fast_memneq(a, b, c) |
| #define | dimap_free(map, free_fn) |
Typedefs | |
| typedef void(* | dimap_free_fn) (void *) |
Functions | |
| int | tor_memcmp (const void *a, const void *b, size_t sz) |
| int | tor_memeq (const void *a, const void *b, size_t sz) |
| int | safe_mem_is_zero (const void *mem, size_t sz) |
| void | dimap_free_ (di_digest256_map_t *map, dimap_free_fn free_fn) |
| void | dimap_add_entry (di_digest256_map_t **map, const uint8_t *key, void *val) |
| void * | dimap_search (const di_digest256_map_t *map, const uint8_t *key, void *dflt_val) |
| int | select_array_member_cumulative_timei (const uint64_t *entries, int n_entries, uint64_t total, uint64_t rand_val) |
| void | memcpy_if_true_timei (bool s, void *dest, const void *src, size_t n) |
| #define dimap_free | ( | map, | |
| free_fn ) |
Release all storage held in map, calling free_fn on each value as we go.
Additionally, set the pointer map to NULL.
Definition at line 63 of file di_ops.h.
Referenced by ntor_key_map_free_().
| #define fast_memcmp | ( | a, | |
| b, | |||
| c ) |
Alias for the platform's memcmp() function. This function is not data-independent: we define this alias so that we can mark cases where we are deliberately using a data-dependent memcmp() implementation.
Definition at line 28 of file di_ops.h.
Referenced by compare_dir_src_ents_by_authority_id_(), compare_members(), compare_old_routers_by_identity_(), compare_pairs_(), compare_reveal_(), compare_routerinfo_by_id_digest_(), compare_routerinfo_usefulness(), compare_srv_(), compare_vote_rs(), compare_votes_by_authority_id_(), dirserv_spool_sort_comparison_(), fast_mem_is_zero(), fast_memcmpstart(), geoip_ipv6_compare_entries_(), geoip_ipv6_compare_key_to_entry_(), networkstatus_compute_consensus(), networkstatus_parse_vote_from_string(), routers_make_ed_keys_unique(), signed_descriptor_get_body_impl(), tor_version_compare(), and write_escaped_data().
| #define fast_memeq | ( | a, | |
| b, | |||
| c ) |
Alias for the platform's memcmp() function, for use in testing equality.
This function is not data-independent: we define this alias so that we can mark cases where we are deliberately using a data-dependent memcmp() implementation.
Definition at line 35 of file di_ops.h.
Referenced by buf_peek_startswith(), cdm_diff_eq(), commit_is_authoritative(), consensus_digest_eq(), ddmap_entry_eq(), detect_compression_method(), dirvote_add_vote(), dirvote_format_all_microdesc_vote_lines(), dirvote_get_vote(), ed25519_keypair_blind(), ed25519_keypair_from_curve25519_keypair(), fast_mem_is_zero(), generate_ed_link_cert(), get_my_declared_family(), hs_pow_verify(), keypin_add_or_replace_entry_in_map(), keypin_check_and_add_impl(), line_starts_with_str(), lines_eq(), looks_like_a_consensus_diff(), mem_eq_token(), microdesc_cache_rebuild(), networkstatus_add_detached_signatures(), networkstatus_compute_consensus(), networkstatus_get_voter_by_id(), networkstatus_parse_vote_from_string(), nodefamily_contains_rsa_id(), nodefamily_eq(), nodefamily_from_members(), nodelist_assert_ok(), nonce_cache_entries_eq_(), pathbias_count_circs_in_states(), rotate_pow_seeds(), should_make_new_ed_keys(), tor_memmem(), and vote_routerstatus_find_microdesc_hash().
| #define fast_memneq | ( | a, | |
| b, | |||
| c ) |
Alias for the platform's memcmp() function, for use in testing inequality.
This function is not data-independent: we define this alias so that we can mark cases where we are deliberately using a data-dependent memcmp() implementation.
Definition at line 42 of file di_ops.h.
Referenced by cdm_diff_ht_purge(), cdm_diff_ht_set_status(), consdiffmgr_validate(), curve25519_basepoint_spot_check(), ed25519_impl_spot_check(), find_desc_intro_point_by_legacy_id(), is_valid_router_entry(), keypin_check_and_add_impl(), microdesc_cache_rebuild(), pem_decode(), router_parse_entry_from_string(), routerstatus_has_visibly_changed(), tor_x509_cert_decode(), and verify_commit_and_reveal().
| #define tor_memneq | ( | a, | |
| b, | |||
| sz ) |
Perform a constant-time comparison of the sz bytes at a and b, yielding true if they are different, and false otherwise.
Definition at line 21 of file di_ops.h.
Referenced by authority_cert_parse_from_string(), channel_remote_identity_matches(), channel_tls_process_authenticate_cell(), check_tap_onion_key_crosscert(), circuit_get_all_pending_on_channel(), circuit_is_acceptable(), conflux_process_linked(), connection_ap_can_use_exit(), connection_ap_fail_onehop(), connection_ext_or_auth_handle_client_hash(), connection_or_client_learned_peer_id(), connection_or_set_identity_digest(), construct_ntor_key_map(), crypto_pk_public_checksig_digest(), crypto_unpwbox(), curve25519_keypair_read_from_file(), decrypt_descriptor_cookie(), dump_desc_populate_one_file(), extrainfo_insert(), fast_client_handshake(), get_sampled_guard_for_bridge(), handle_control_authenticate(), handle_get_networkstatus_bridges(), init_keys(), networkstatus_check_document_signature(), networkstatus_parse_vote_from_string(), nodelist_set_consensus(), onion_ntor3_client_handshake(), onion_skin_ntor3_server_handshake_part1(), onion_skin_ntor_client_handshake(), onion_skin_ntor_server_handshake(), parse_socks5_userpass_auth(), router_parse_entry_from_string(), routerinfo_incompatible_with_extrainfo(), routerlist_remove_old_routers(), routerlist_replace(), routerstatus_format_entry(), rsa_ed25519_crosscert_check(), update_consensus_router_descriptor_downloads(), and verify_establish_intro_cell().
| typedef void(* dimap_free_fn) (void *) |
Type for a function used to free members of a di_digest256_map_t.
| void dimap_add_entry | ( | di_digest256_map_t ** | map, |
| const uint8_t * | key, | ||
| void * | val ) |
Adjust the map at *map, adding an entry for key -> val, where key is a DIGEST256_LEN-byte key.
The caller MUST NOT add a key that already appears in the map.
Definition at line 176 of file di_ops.c.
Referenced by construct_ntor_key_map().
| void dimap_free_ | ( | di_digest256_map_t * | map, |
| dimap_free_fn | free_fn ) |
| void * dimap_search | ( | const di_digest256_map_t * | map, |
| const uint8_t * | key, | ||
| void * | dflt_val ) |
Search the map at map for an entry whose key is key (a DIGEST256_LEN-byte key) returning the corresponding value if we found one, and returning dflt_val if the key wasn't found.
This operation takes an amount of time dependent only on the length of map, not on the position or presence of key within map.
Definition at line 200 of file di_ops.c.
Referenced by dimap_add_entry(), onion_skin_ntor3_server_handshake_part1(), and onion_skin_ntor_server_handshake().
| void memcpy_if_true_timei | ( | bool | s, |
| void * | dest, | ||
| const void * | src, | ||
| size_t | n ) |
If s is true, then copy n bytes from src to dest. Otherwise leave dest alone.
This function behaves the same as
if (s)
memcpy(dest, src, n);
except that it tries to run in the same amount of time whether s is true or not.
Definition at line 296 of file di_ops.c.
Referenced by get_introduce2_keys_and_verify_mac().
| int safe_mem_is_zero | ( | const void * | mem, |
| size_t | sz ) |
Return true iff the sz bytes at mem are all zero. Runs in time independent of the contents of mem.
Definition at line 224 of file di_ops.c.
Referenced by crypto_strongest_rand_raw(), curve25519_public_key_is_ok(), ed25519_public_key_is_zero(), get_introduce2_keys_and_verify_mac(), get_rendezvous1_key_material(), hs_ntor_service_get_introduce1_keys_multi(), load_ed_keys(), onion_ntor3_client_handshake(), onion_skin_ntor3_create_nokeygen(), onion_skin_ntor3_server_handshake_part1(), onion_skin_ntor3_server_handshake_part2_nokeygen(), onion_skin_ntor_client_handshake(), onion_skin_ntor_server_handshake(), tor_digest256_is_zero(), and tor_digest_is_zero().
| int select_array_member_cumulative_timei | ( | const uint64_t * | entries, |
| int | n_entries, | ||
| uint64_t | total, | ||
| uint64_t | rand_val ) |
Given an array of list of n_entries uint64_t values, whose sum is total, find the first i such that the total of all elements 0...i is greater than rand_val.
Try to perform this operation in a constant-time way.
Definition at line 259 of file di_ops.c.
Referenced by choose_array_element_by_weight().
| int tor_memcmp | ( | const void * | a, |
| const void * | b, | ||
| size_t | len ) |
Timing-safe version of memcmp. As memcmp, compare the sz bytes at a with the sz bytes at b, and return less than 0 if the bytes at a lexically precede those at b, 0 if the byte ranges are equal, and greater than zero if the bytes at a lexically follow those at b.
This implementation differs from memcmp in that its timing behavior is not data-dependent: it should return in the same amount of time regardless of the contents of a and b.
Note that if all you care about is equality, this implementation is overkill: it would be better to use tor_memeq() or tor_memneq().
Definition at line 31 of file di_ops.c.
Referenced by compare_digest_to_fetch_hsdir_index(), compare_digest_to_routerstatus_entry(), compare_digest_to_store_first_hsdir_index(), compare_digest_to_store_second_hsdir_index(), compare_digest_to_vote_routerstatus_entry(), compare_digests256_(), compare_digests_(), compare_node_fetch_hsdir_index(), compare_node_store_first_hsdir_index(), compare_node_store_second_hsdir_index(), compare_srvs_(), crypto_pk_cmp_keys(), hs_address_is_valid(), networkstatus_copy_old_consensus_info(), notify_control_networkstatus_changed(), routers_update_status_from_consensus_networkstatus(), service_authorized_client_cmp(), and tor_addr_compare_masked().
| int tor_memeq | ( | const void * | a, |
| const void * | b, | ||
| size_t | sz ) |
Timing-safe memory comparison. Return true if the sz bytes at a are the same as the sz bytes at b, and 0 otherwise.
This implementation differs from !memcmp(a,b,sz) in that its timing behavior is not data-dependent: it should return in the same amount of time regardless of the contents of a and b. It differs from !tor_memcmp(a,b,sz) by being faster.
Definition at line 107 of file di_ops.c.
Referenced by authority_cert_get_by_digests(), authority_cert_get_by_sk_digest(), authority_cert_parse_from_string(), bridge_has_digest(), cfx_add_leg(), cgo_crypt_client_backward(), cgo_crypt_relay_forward(), channel_get_for_extend(), circuit_find_to_cannibalize(), connection_control_process_inbuf(), decrypt_desc_layer(), digest256map_entries_eq(), digest_list_contains_best_consensus(), digestmap_entries_eq(), dimap_search(), dump_desc_fifo_bump_hash(), ed25519_pubkey_eq(), ed_key_init_from_file(), entry_guard_learned_bridge_identity(), environment_variable_names_equal(), find_bridge_by_digest(), fp_pair_map_entries_eq(), get_bridge_dl_status_by_id(), get_configured_bridge_by_addr_port_digest(), get_configured_bridge_by_exact_addr_port_digest(), get_configured_bridge_by_orports_digest(), get_introduce2_keys_and_verify_mac(), get_sampled_guard_with_id(), handle_control_authenticate(), hex_digest_nickname_matches(), hs_circuits_have_same_token(), hs_ntor_client_rendezvous2_mac_is_good(), hs_purge_hid_serv_from_last_hid_serv_requests(), keypin_check_and_add_impl(), keypin_ents_eq_ed(), load_ed_keys(), memeq_opt(), microdesc_cache_clean(), microdesc_eq_(), microdescs_add_to_cache(), networkstatus_check_consensus_signature(), networkstatus_copy_old_consensus_info(), networkstatus_parse_detached_signatures(), networkstatus_set_current_consensus(), or_handshake_certs_ed25519_ok(), parse_socks5_userpass_auth(), port_cfg_eq(), router_add_to_routerlist(), router_digest_is_me(), router_digest_is_trusted_dir_type(), router_extrainfo_digest_is_me(), router_get_fallback_dirserver_by_digest(), router_get_trusteddirserver_by_digest(), router_set_status(), router_tap_onion_keys_eq(), routerinfo_incompatible_with_extrainfo(), routerlist_assert_ok(), routerlist_remove_old_cached_routers_with_id(), routerlist_replace(), routers_update_status_from_consensus_networkstatus(), routerstatus_format_entry(), routerstatus_has_visibly_changed(), secret_to_key_check(), signed_desc_digest_is_recognized(), smartlist_contains_digest(), tor_cert_eq(), trusteddirserver_get_by_v3_auth_digest(), and validate_unlinked_legs().