tor  master
Data Structures | Macros | Functions
crypto_digest.c File Reference

Block of functions related with digest and xof utilities and operations. More...

#include "container.h"
#include "crypto_digest.h"
#include "crypto_openssl_mgt.h"
#include "crypto_util.h"
#include "torlog.h"
#include "keccak-tiny/keccak-tiny.h"
#include <openssl/hmac.h>
#include <openssl/sha.h>
Include dependency graph for crypto_digest.c:

Data Structures

struct  crypto_digest_t
 
struct  crypto_xof_t
 

Macros

#define STRUCT_FIELD_SIZE(st, f)   (sizeof( ((st*)0)->f ))
 
#define END_OF_FIELD(f)
 

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)
 
const char * crypto_digest_algorithm_get_name (digest_algorithm_t alg)
 
int crypto_digest_algorithm_parse_name (const char *name)
 
size_t crypto_digest_algorithm_get_length (digest_algorithm_t alg)
 
crypto_digest_tcrypto_digest_new (void)
 
crypto_digest_tcrypto_digest256_new (digest_algorithm_t algorithm)
 
crypto_digest_tcrypto_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_tcrypto_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_digest_smartlist (char *digest_out, size_t len_out, const smartlist_t *lst, const char *append, digest_algorithm_t alg)
 
void crypto_digest_smartlist_prefix (char *digest_out, size_t len_out, const char *prepend, const smartlist_t *lst, const char *append, digest_algorithm_t alg)
 
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_tcrypto_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)
 

Detailed Description

Block of functions related with digest and xof utilities and operations.

Macro Definition Documentation

◆ END_OF_FIELD

#define END_OF_FIELD (   f)
Value:
(offsetof(crypto_digest_t, f) + \
STRUCT_FIELD_SIZE(crypto_digest_t, f))
Definition: crypto_digest.c:171

Function Documentation

◆ crypto_common_digests()

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.

Here is the call graph for this function:

◆ crypto_digest()

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.

Here is the caller graph for this function:

◆ crypto_digest256()

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.

Here is the caller graph for this function:

◆ crypto_digest256_new()

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

Here is the caller graph for this function:

◆ crypto_digest512()

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.

◆ crypto_digest512_new()

crypto_digest_t* crypto_digest512_new ( digest_algorithm_t  algorithm)

Allocate and return a new digest object to compute 512-bit digests using algorithm.

Here is the caller graph for this function:

◆ crypto_digest_add_bytes()

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

Here is the caller graph for this function:

◆ crypto_digest_algorithm_get_length()

size_t crypto_digest_algorithm_get_length ( digest_algorithm_t  alg)

Given an algorithm, return the digest length in bytes.

Here is the caller graph for this function:

◆ crypto_digest_algorithm_get_name()

const char* crypto_digest_algorithm_get_name ( digest_algorithm_t  alg)

Return the name of an algorithm, as used in directory documents.

◆ crypto_digest_algorithm_parse_name()

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.

◆ crypto_digest_assign()

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.

◆ crypto_digest_checkpoint()

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.

◆ crypto_digest_dup()

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

◆ crypto_digest_free_()

void crypto_digest_free_ ( crypto_digest_t digest)

Deallocate a digest object.

◆ crypto_digest_get_digest()

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

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

◆ crypto_digest_new()

crypto_digest_t* crypto_digest_new ( void  )

Allocate and return a new digest object to compute SHA1 digests.

Here is the caller graph for this function:

◆ crypto_digest_restore()

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()

◆ crypto_digest_smartlist()

void crypto_digest_smartlist ( char *  digest_out,
size_t  len_out,
const smartlist_t lst,
const char *  append,
digest_algorithm_t  alg 
)

Given a list of strings in lst, set the len_out-byte digest at digest_out to the hash of the concatenation of those strings, plus the optional string append, computed with the algorithm alg. out_len must be <= DIGEST512_LEN.

Here is the call graph for this function:

◆ crypto_digest_smartlist_prefix()

void crypto_digest_smartlist_prefix ( char *  digest_out,
size_t  len_out,
const char *  prepend,
const smartlist_t lst,
const char *  append,
digest_algorithm_t  alg 
)

Given a list of strings in lst, set the len_out-byte digest at digest_out to the hash of the concatenation of: the optional string prepend, those strings, and the optional string append, computed with the algorithm alg. len_out must be <= DIGEST512_LEN.

Here is the caller graph for this function:

◆ crypto_hmac_sha256()

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.

Here is the caller graph for this function:

◆ crypto_mac_sha3_256()

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.

Here is the call graph for this function:

◆ crypto_xof_add_bytes()

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.

◆ crypto_xof_free_()

void crypto_xof_free_ ( crypto_xof_t xof)

Cleanse and deallocate a XOF object.

Here is the call graph for this function:

◆ crypto_xof_new()

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.

◆ crypto_xof_squeeze_bytes()

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.