|
Tor 0.4.9.8
|
Formatting and parsing code for crypto-related data structures. More...
#include "orconfig.h"#include "lib/container/smartlist.h"#include "lib/crypt_ops/crypto_curve25519.h"#include "lib/crypt_ops/crypto_digest.h"#include "lib/crypt_ops/crypto_ed25519.h"#include "lib/crypt_ops/crypto_format.h"#include "lib/crypt_ops/crypto_util.h"#include "lib/string/compat_string.h"#include "lib/string/util_string.h"#include "lib/string/printf.h"#include "lib/encoding/binascii.h"#include "lib/log/log.h"#include "lib/log/util_bug.h"#include "lib/fs/files.h"#include <string.h>#include <errno.h>Go to the source code of this file.
Functions | |
| int | crypto_write_tagged_contents_to_file (const char *fname, const char *typestring, const char *tag, const uint8_t *data, size_t datalen) |
| ssize_t | crypto_read_tagged_contents_from_file (const char *fname, const char *typestring, char **tag_out, uint8_t *data_out, ssize_t data_out_len) |
| void | curve25519_public_to_base64 (char *output, const curve25519_public_key_t *pkey, bool pad) |
| int | curve25519_public_from_base64 (curve25519_public_key_t *pkey, const char *input) |
| const char * | ed25519_fmt (const ed25519_public_key_t *pkey) |
| int | ed25519_public_from_base64 (ed25519_public_key_t *pkey, const char *input) |
| void | ed25519_public_to_base64 (char *output, const ed25519_public_key_t *pkey) |
| void | ed25519_signature_to_base64 (char *output, const ed25519_signature_t *sig) |
| int | ed25519_signature_from_base64 (ed25519_signature_t *sig, const char *input) |
| void | digest_to_base64 (char *d64, const char *digest) |
| int | digest_from_base64 (char *digest, const char *d64) |
| void | digest256_to_base64 (char *d64, const char *digest) |
| int | digest256_from_base64 (char *digest, const char *d64) |
Formatting and parsing code for crypto-related data structures.
Definition in file crypto_format.c.
| ssize_t crypto_read_tagged_contents_from_file | ( | const char * | fname, |
| const char * | typestring, | ||
| char ** | tag_out, | ||
| uint8_t * | data_out, | ||
| ssize_t | data_out_len ) |
Read a tagged-data file from fname into the data_out_len-byte buffer in data_out. Check that the typestring matches typestring; store the tag into a newly allocated string in tag_out. Return -1 on failure, and the number of bytes of data on success. Preserves the errno from reading the file.
Definition at line 77 of file crypto_format.c.
Referenced by curve25519_keypair_read_from_file(), ed25519_pubkey_read_from_file(), ed25519_seckey_read_from_file(), and ed_key_init_from_file().
| int crypto_write_tagged_contents_to_file | ( | const char * | fname, |
| const char * | typestring, | ||
| const char * | tag, | ||
| const uint8_t * | data, | ||
| size_t | datalen ) |
Write the datalen bytes from data to the file named fname in the tagged-data format. This format contains a 32-byte header, followed by the data itself. The header is the NUL-padded string "== <b>typestring</b>: <b>tag</b> ==". The length of typestring and tag must therefore be no more than 24.
Definition at line 42 of file crypto_format.c.
Referenced by curve25519_keypair_write_to_file(), ed25519_pubkey_write_to_file(), ed25519_seckey_write_to_file(), and ed_key_init_from_file().
| int curve25519_public_from_base64 | ( | curve25519_public_key_t * | pkey, |
| const char * | input ) |
Try to decode a base64-encoded curve25519 public key from input into the object at pkey. Return 0 on success, -1 on failure. Accepts keys with or without a trailing "=".
Definition at line 170 of file crypto_format.c.
Referenced by decode_introduction_point(), desc_decode_superencrypted_v3(), microdesc_parse_fields(), router_parse_entry_from_string(), and set_intro_point_onion_key().
| void curve25519_public_to_base64 | ( | char * | output, |
| const curve25519_public_key_t * | pkey, | ||
| bool | pad ) |
Encode pkey as a base64-encoded string in the buffer output. If pad is false do not include trailing "=" characters, otherwise include them. output must have at least CURVE25519_BASE64_PADDED_LEN+1 bytes available, even if pad is false. Can not fail.
Careful! CURVE25519_BASE64_PADDED_LEN is one byte longer than ED25519_BASE64_LEN.
Definition at line 144 of file crypto_format.c.
Referenced by dirvote_create_microdescriptor(), encode_enc_key(), encode_onion_key(), get_outer_encrypted_layer_plaintext(), and router_dump_router_to_string().
| int digest256_from_base64 | ( | char * | digest, |
| const char * | d64 ) |
Given a base64 encoded, nul-terminated digest in d64 (without trailing newline or = characters), decode it and store the result in the first DIGEST256_LEN bytes at digest.
Definition at line 320 of file crypto_format.c.
Referenced by curve25519_public_from_base64(), dirserv_load_fingerprint_file(), ed25519_public_from_base64(), router_parse_entry_from_string(), and vote_routerstatus_find_microdesc_hash().
| void digest256_to_base64 | ( | char * | d64, |
| const char * | digest ) |
Base64 encode DIGEST256_LINE bytes from digest, remove the trailing = characters, and store the nul-terminated result in the first BASE64_DIGEST256_LEN+1 bytes of d64. Can not fail.
Definition at line 304 of file crypto_format.c.
Referenced by cache_clean_v3_as_client(), cache_clean_v3_as_dir(), cache_clean_v3_by_downloaded_as_dir(), dir_microdesc_download_failed(), dirvote_format_microdesc_vote_line(), do_list_fingerprint(), ed25519_public_to_base64(), format_networkstatus_vote(), hs_cache_remove_as_client(), initiate_descriptor_downloads(), keypin_journal_append_entry(), networkstatus_compute_consensus(), router_dump_router_to_string(), router_write_fingerprint(), and routerstatus_format_entry().
| int digest_from_base64 | ( | char * | digest, |
| const char * | d64 ) |
Given a base64 encoded, nul-terminated digest in d64 (without trailing newline or = characters), decode it and store the result in the first DIGEST_LEN bytes at digest.
Definition at line 291 of file crypto_format.c.
| void digest_to_base64 | ( | char * | d64, |
| const char * | digest ) |
Base64 encode DIGEST_LEN bytes from digest, remove the trailing = characters, and store the nul-terminated result in the first BASE64_DIGEST_LEN+1 bytes of d64. Can not fail.
Definition at line 275 of file crypto_format.c.
Referenced by dirvote_create_microdescriptor(), keypin_journal_append_entry(), routerstatus_format_entry(), service_desc_hsdirs_changed(), and service_desc_note_upload().
| const char * ed25519_fmt | ( | const ed25519_public_key_t * | pkey | ) |
For logging convenience: Convert pkey to a statically allocated base64 string and return it. Not threadsafe. Format not meant to be computer-readable; it may change in the future. Subsequent calls invalidate previous returns.
Definition at line 193 of file crypto_format.c.
Referenced by add_ed25519_to_dir(), can_client_refetch_desc(), client_get_random_intro(), close_directory_connections(), connection_or_client_learned_peer_id(), connection_or_init_conn_from_address(), connection_or_set_identity_digest(), directory_launch_v3_desc_fetch(), do_keygen_family(), hs_client_circuit_cleanup_on_free(), hs_service_set_conn_addr_port(), intro_point_is_usable(), load_family_id_keys(), load_family_id_keys_impl(), service_handle_intro_established(), service_handle_introduce2(), service_intro_circ_has_opened(), and service_rendezvous_circ_has_opened().
| int ed25519_public_from_base64 | ( | ed25519_public_key_t * | pkey, |
| const char * | input ) |
Try to decode the string input into an ed25519 public key. On success, store the value in pkey and return 0. Otherwise return -1.
Definition at line 212 of file crypto_format.c.
Referenced by cache_lookup_v3_as_dir(), handle_get_hs_descriptor_v3(), microdesc_parse_fields(), options_validate_relay_mode(), and router_parse_entry_from_string().
| void ed25519_public_to_base64 | ( | char * | output, |
| const ed25519_public_key_t * | pkey ) |
Encode the public key pkey into the buffer at output, which must have space for ED25519_BASE64_LEN bytes of encoded key, plus one byte for a terminating NUL. Can not fail.
Careful! ED25519_BASE64_LEN is one byte shorter than CURVE25519_BASE64_PADDED_LEN.
Definition at line 227 of file crypto_format.c.
Referenced by check_one_family_cert(), connection_describe_peer_internal(), connection_or_client_learned_peer_id(), directory_launch_v3_desc_fetch(), dirvote_create_microdescriptor(), ed25519_fmt(), format_node_description(), handle_introduce1(), hs_control_desc_event_content(), hs_control_desc_event_created(), hs_control_desc_event_failed(), hs_control_desc_event_received(), hs_control_desc_event_upload(), pick_hsdir_v3(), purge_hid_serv_request(), and router_dump_router_to_string().
| int ed25519_signature_from_base64 | ( | ed25519_signature_t * | sig, |
| const char * | input ) |
Try to decode the string input into an ed25519 signature. On success, store the value in sig and return 0. Otherwise return -1.
Definition at line 255 of file crypto_format.c.
Referenced by desc_sig_is_valid(), extrainfo_parse_entry_from_string(), and router_parse_entry_from_string().
| void ed25519_signature_to_base64 | ( | char * | output, |
| const ed25519_signature_t * | sig ) |
Encode the signature sig into the buffer at output, which must have space for ED25519_SIG_BASE64_LEN bytes of encoded signature, plus one byte for a terminating NUL. Can not fail.
Definition at line 239 of file crypto_format.c.
Referenced by desc_encode_v3(), extrainfo_dump_to_string_ed_sig_helper(), and router_dump_router_to_string().