Tor
0.4.7.0-alpha-dev
|
Headers for crypto_digest.c. More...
#include "lib/cc/torint.h"
#include "lib/defs/digest_sizes.h"
#include "lib/malloc/malloc.h"
#include "lib/testsupport/testsupport.h"
Go to the source code of this file.
Data Structures | |
struct | crypto_digest_checkpoint_t |
struct | common_digests_t |
Macros | |
#define | BASE32_DIGEST_LEN 32 |
#define | BASE64_DIGEST_LEN 27 |
#define | BASE64_DIGEST256_LEN 43 |
#define | BASE64_DIGEST512_LEN 86 |
#define | HEX_DIGEST_LEN 40 |
#define | HEX_DIGEST256_LEN 64 |
#define | HEX_DIGEST512_LEN 128 |
#define | N_DIGEST_ALGORITHMS (DIGEST_SHA3_512+1) |
#define | N_COMMON_DIGEST_ALGORITHMS (DIGEST_SHA256+1) |
#define | DIGEST_CHECKPOINT_BYTES (SIZEOF_VOID_P + 512) |
#define | crypto_digest_free(d) FREE_AND_NULL(crypto_digest_t, crypto_digest_free_, (d)) |
#define | crypto_xof_free(xof) FREE_AND_NULL(crypto_xof_t, crypto_xof_free_, (xof)) |
Enumerations | |
enum | digest_algorithm_t { DIGEST_SHA1 = 0 , DIGEST_SHA256 = 1 , DIGEST_SHA512 = 2 , DIGEST_SHA3_256 = 3 , DIGEST_SHA3_512 = 4 } |
Functions | |
int | crypto_digest (char *digest, const char *m, size_t len) |
int | crypto_digest256 (char *digest, const char *m, size_t len, digest_algorithm_t algorithm) |
int | crypto_digest512 (char *digest, const char *m, size_t len, digest_algorithm_t algorithm) |
int | crypto_common_digests (common_digests_t *ds_out, const char *m, size_t len) |
void | crypto_digest_smartlist_prefix (char *digest_out, size_t len_out, const char *prepend, const struct smartlist_t *lst, const char *append, digest_algorithm_t alg) |
void | crypto_digest_smartlist (char *digest_out, size_t len_out, const struct smartlist_t *lst, const char *append, digest_algorithm_t alg) |
const char * | crypto_digest_algorithm_get_name (digest_algorithm_t alg) |
size_t | crypto_digest_algorithm_get_length (digest_algorithm_t alg) |
int | crypto_digest_algorithm_parse_name (const char *name) |
crypto_digest_t * | crypto_digest_new (void) |
crypto_digest_t * | crypto_digest256_new (digest_algorithm_t algorithm) |
crypto_digest_t * | crypto_digest512_new (digest_algorithm_t algorithm) |
void | crypto_digest_free_ (crypto_digest_t *digest) |
void | crypto_digest_add_bytes (crypto_digest_t *digest, const char *data, size_t len) |
void | crypto_digest_get_digest (crypto_digest_t *digest, char *out, size_t out_len) |
crypto_digest_t * | crypto_digest_dup (const crypto_digest_t *digest) |
void | crypto_digest_checkpoint (crypto_digest_checkpoint_t *checkpoint, const crypto_digest_t *digest) |
void | crypto_digest_restore (crypto_digest_t *digest, const crypto_digest_checkpoint_t *checkpoint) |
void | crypto_digest_assign (crypto_digest_t *into, const crypto_digest_t *from) |
void | crypto_hmac_sha256 (char *hmac_out, const char *key, size_t key_len, const char *msg, size_t msg_len) |
void | crypto_mac_sha3_256 (uint8_t *mac_out, size_t len_out, const uint8_t *key, size_t key_len, const uint8_t *msg, size_t msg_len) |
crypto_xof_t * | crypto_xof_new (void) |
void | crypto_xof_add_bytes (crypto_xof_t *xof, const uint8_t *data, size_t len) |
void | crypto_xof_squeeze_bytes (crypto_xof_t *xof, uint8_t *out, size_t len) |
void | crypto_xof_free_ (crypto_xof_t *xof) |
void | crypto_xof (uint8_t *output, size_t output_len, const uint8_t *input, size_t input_len) |
Headers for crypto_digest.c.
Definition in file crypto_digest.h.
#define BASE32_DIGEST_LEN 32 |
Length of a sha1 message digest when encoded in base32 with trailing = signs removed.
Definition at line 23 of file crypto_digest.h.
#define BASE64_DIGEST256_LEN 43 |
Length of a sha256 message digest when encoded in base64 with trailing = signs removed.
Definition at line 29 of file crypto_digest.h.
#define BASE64_DIGEST512_LEN 86 |
Length of a sha512 message digest when encoded in base64 with trailing = signs removed.
Definition at line 32 of file crypto_digest.h.
#define BASE64_DIGEST_LEN 27 |
Length of a sha1 message digest when encoded in base64 with trailing = signs removed.
Definition at line 26 of file crypto_digest.h.
#define crypto_digest_free | ( | d | ) | FREE_AND_NULL(crypto_digest_t, crypto_digest_free_, (d)) |
Release all storage held in d, and set it to NULL.
Definition at line 130 of file crypto_digest.h.
#define crypto_xof_free | ( | xof | ) | FREE_AND_NULL(crypto_xof_t, crypto_xof_free_, (xof)) |
Release all storage held in xof, and set it to NULL.
Definition at line 158 of file crypto_digest.h.
#define DIGEST_CHECKPOINT_BYTES (SIZEOF_VOID_P + 512) |
Bytes of storage needed to record the state of an in-progress SHA-1 digest.
This is a deliberate overestimate.
Definition at line 65 of file crypto_digest.h.
#define HEX_DIGEST256_LEN 64 |
Length of hex encoding of SHA256 digest, not including final NUL.
Definition at line 37 of file crypto_digest.h.
#define HEX_DIGEST512_LEN 128 |
Length of hex encoding of SHA512 digest, not including final NUL.
Definition at line 39 of file crypto_digest.h.
#define HEX_DIGEST_LEN 40 |
Length of hex encoding of SHA1 digest, not including final NUL.
Definition at line 35 of file crypto_digest.h.
#define N_COMMON_DIGEST_ALGORITHMS (DIGEST_SHA256+1) |
Number of digest algorithms to compute when computing "all the commonly used digests."
(This is used in common_digests_t and related functions.)
Definition at line 58 of file crypto_digest.h.
#define N_DIGEST_ALGORITHMS (DIGEST_SHA3_512+1) |
Number of digest algorithms that we know
Definition at line 52 of file crypto_digest.h.
enum digest_algorithm_t |
An identifier for a cryptographic digest algorithm.
Definition at line 44 of file crypto_digest.h.
int crypto_common_digests | ( | common_digests_t * | ds_out, |
const char * | m, | ||
size_t | len | ||
) |
Set the common_digests_t in ds_out to contain every digest on the len bytes in m that we know how to compute. Return 0 on success, -1 on failure.
Definition at line 30 of file crypto_digest.c.
Referenced by router_get_hashes_impl().
int crypto_digest | ( | char * | digest, |
const char * | m, | ||
size_t | len | ||
) |
Compute the SHA1 digest of the len bytes on data stored in m. Write the DIGEST_LEN byte result into digest. Return 0 on success, -1 on failure.
Definition at line 110 of file crypto_digest_nss.c.
Referenced by crypto_common_digests(), crypto_pk_get_hashed_fingerprint(), crypto_pk_private_sign_digest(), and crypto_pk_public_checksig_digest().
int crypto_digest256 | ( | char * | digest, |
const char * | m, | ||
size_t | len, | ||
digest_algorithm_t | algorithm | ||
) |
Compute a 256-bit digest of len bytes in data stored in m, using the algorithm algorithm. Write the DIGEST_LEN256-byte result into digest. Return 0 on success, -1 on failure.
Definition at line 121 of file crypto_digest_nss.c.
Referenced by build_hs_checksum(), cdm_labels_prepend_sha3(), consensus_compute_digest(), and router_get_networkstatus_v3_sha3_as_signed().
crypto_digest_t* crypto_digest256_new | ( | digest_algorithm_t | algorithm | ) |
Allocate and return a new digest object to compute 256-bit digests using algorithm.
C_RUST_COUPLED: external::crypto_digest::crypto_digest256_new
C_RUST_COUPLED: crypto::digest::Sha256::default
Definition at line 272 of file crypto_digest_nss.c.
Referenced by build_mac(), compute_disaster_srv(), crypto_mac_sha3_256(), dirserv_read_measured_bandwidths(), generate_ope_cipher_for_desc(), hs_build_hs_index(), hs_build_hsdir_index(), hs_get_subcredential(), and or_handshake_state_record_var_cell().
int crypto_digest512 | ( | char * | digest, |
const char * | m, | ||
size_t | len, | ||
digest_algorithm_t | algorithm | ||
) |
Compute a 512-bit digest of len bytes in data stored in m, using the algorithm algorithm. Write the DIGEST_LEN512-byte result into digest. Return 0 on success, -1 on failure.
Definition at line 145 of file crypto_digest_nss.c.
crypto_digest_t* crypto_digest512_new | ( | digest_algorithm_t | algorithm | ) |
Allocate and return a new digest object to compute 512-bit digests using algorithm.
Definition at line 281 of file crypto_digest_nss.c.
Referenced by ed25519_keypair_from_curve25519_keypair().
void crypto_digest_add_bytes | ( | crypto_digest_t * | digest, |
const char * | data, | ||
size_t | len | ||
) |
Add len bytes from data to the digest object.
C_RUST_COUPLED: external::crypto_digest::crypto_digest_add_bytess
C_RUST_COUPLED: crypto::digest::Sha256::process
Definition at line 308 of file crypto_digest_nss.c.
Referenced by crypto_digest_smartlist_prefix(), and relay_set_digest().
size_t crypto_digest_algorithm_get_length | ( | digest_algorithm_t | alg | ) |
Given an algorithm, return the digest length in bytes.
Definition at line 86 of file crypto_digest.c.
Referenced by crypto_digest_get_digest().
const char* crypto_digest_algorithm_get_name | ( | digest_algorithm_t | alg | ) |
Return the name of an algorithm, as used in directory documents.
Definition at line 44 of file crypto_digest.c.
Referenced by disk_state_put_commit_line().
int crypto_digest_algorithm_parse_name | ( | const char * | name | ) |
Given the name of a digest algorithm, return its integer value, or -1 if the name is not recognized.
Definition at line 68 of file crypto_digest.c.
void crypto_digest_assign | ( | crypto_digest_t * | into, |
const crypto_digest_t * | from | ||
) |
Replace the state of the digest object into with the state of the digest object from. Requires that 'into' and 'from' have the same digest type.
Definition at line 450 of file crypto_digest_nss.c.
void crypto_digest_checkpoint | ( | crypto_digest_checkpoint_t * | checkpoint, |
const crypto_digest_t * | digest | ||
) |
Temporarily save the state of digest in checkpoint. Asserts that digest is a SHA1 digest object.
Definition at line 409 of file crypto_digest_nss.c.
crypto_digest_t* crypto_digest_dup | ( | const crypto_digest_t * | digest | ) |
Allocate and return a new digest object with the same state as digest
C_RUST_COUPLED: external::crypto_digest::crypto_digest_dup
C_RUST_COUPLED: impl Clone for crypto::digest::Sha256
Definition at line 392 of file crypto_digest_nss.c.
void crypto_digest_free_ | ( | crypto_digest_t * | digest | ) |
Deallocate a digest object.
Definition at line 290 of file crypto_digest_nss.c.
void crypto_digest_get_digest | ( | crypto_digest_t * | digest, |
char * | out, | ||
size_t | out_len | ||
) |
Compute the hash of the data that has been passed to the digest object; write the first out_len bytes of the result to out. out_len must be <= DIGEST512_LEN.
C_RUST_COUPLED: external::crypto_digest::crypto_digest_get_digest
C_RUST_COUPLED: impl digest::FixedOutput for Sha256
Definition at line 348 of file crypto_digest_nss.c.
Referenced by crypto_digest_smartlist_prefix(), relay_crypto_record_sendme_digest(), and relay_set_digest().
crypto_digest_t* crypto_digest_new | ( | void | ) |
Allocate and return a new digest object to compute SHA1 digests.
Definition at line 260 of file crypto_digest_nss.c.
void crypto_digest_restore | ( | crypto_digest_t * | digest, |
const crypto_digest_checkpoint_t * | checkpoint | ||
) |
Restore the state of digest from checkpoint. Asserts that digest is a SHA1 digest object. Requires that the state was previously stored with crypto_digest_checkpoint()
Definition at line 431 of file crypto_digest_nss.c.
void crypto_hmac_sha256 | ( | char * | hmac_out, |
const char * | key, | ||
size_t | key_len, | ||
const char * | msg, | ||
size_t | msg_len | ||
) |
Compute the HMAC-SHA-256 of the msg_len bytes in msg, using the key of length key_len. Store the DIGEST256_LEN-byte result in hmac_out. Asserts on failure.
Definition at line 508 of file crypto_digest_nss.c.
Referenced by crypto_expand_key_material_rfc5869_sha256_legacy(), and h_tweak().
void crypto_mac_sha3_256 | ( | uint8_t * | mac_out, |
size_t | len_out, | ||
const uint8_t * | key, | ||
size_t | key_len, | ||
const uint8_t * | msg, | ||
size_t | msg_len | ||
) |
Compute a MAC using SHA3-256 of msg_len bytes in msg using a key of length key_len and a salt of length salt_len. Store the result of len_out bytes in in mac_out. This function can't fail.
Definition at line 110 of file crypto_digest.c.
Referenced by compute_introduce_mac().
void crypto_xof | ( | uint8_t * | output, |
size_t | output_len, | ||
const uint8_t * | input, | ||
size_t | input_len | ||
) |
Compute the XOF (SHAKE256) of a input_len bytes at input, putting output_len bytes at output.
Definition at line 229 of file crypto_digest.c.
void crypto_xof_add_bytes | ( | crypto_xof_t * | xof, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Absorb bytes into a XOF object. Must not be called after a call to crypto_xof_squeeze_bytes() for the same instance, and will assert if attempted.
Definition at line 186 of file crypto_digest.c.
Referenced by build_kdf_key(), crypto_fast_rng_add_entopy(), and crypto_xof().
void crypto_xof_free_ | ( | crypto_xof_t * | xof | ) |
Cleanse and deallocate a XOF object.
Definition at line 214 of file crypto_digest.c.
crypto_xof_t* crypto_xof_new | ( | void | ) |
Allocate a new XOF object backed by SHAKE-256. The security level provided is a function of the length of the output used. Read and understand FIPS-202 A.2 "Additional Consideration for Extendable-Output Functions" before using this construct.
Definition at line 166 of file crypto_digest.c.
Referenced by build_kdf_key(), crypto_fast_rng_add_entopy(), and crypto_xof().
void crypto_xof_squeeze_bytes | ( | crypto_xof_t * | xof, |
uint8_t * | out, | ||
size_t | len | ||
) |
Squeeze bytes out of a XOF object. Calling this routine will render the XOF instance ineligible to absorb further data.
Definition at line 201 of file crypto_digest.c.
Referenced by crypto_xof().