Tor
0.4.7.0-alpha-dev
|
Block of functions related with digest and xof utilities and operations (NSS specific implementations). More...
#include "lib/container/smartlist.h"
#include "lib/crypt_ops/crypto_digest.h"
#include "lib/crypt_ops/crypto_util.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "keccak-tiny/keccak-tiny.h"
#include <stdlib.h>
#include <string.h>
#include "lib/arch/bytes.h"
#include <pk11pub.h>
Go to the source code of this file.
Data Structures | |
struct | crypto_digest_t |
Macros | |
#define | STRUCT_FIELD_SIZE(st, f) (sizeof( ((st*)0)->f )) |
#define | END_OF_FIELD(f) |
Functions | |
static SECOidTag | digest_alg_to_nss_oid (digest_algorithm_t alg) |
static int | digest_nss_internal (SECOidTag alg, char *digest, unsigned len_out, const char *msg, size_t msg_len) |
static bool | library_supports_digest (digest_algorithm_t alg) |
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) |
static size_t | crypto_digest_alloc_bytes (digest_algorithm_t alg) |
static crypto_digest_t * | crypto_digest_new_internal (digest_algorithm_t algorithm) |
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_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) |
Block of functions related with digest and xof utilities and operations (NSS specific implementations).
Definition in file crypto_digest_nss.c.
#define END_OF_FIELD | ( | f | ) |
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.
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.
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.
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.
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().
|
static |
Return the number of bytes we need to malloc in order to get a crypto_digest_t for alg, or the number of bytes we need to wipe when we free one.
Definition at line 196 of file crypto_digest_nss.c.
Referenced by crypto_digest_assign(), crypto_digest_checkpoint(), crypto_digest_dup(), crypto_digest_free_(), and crypto_digest_restore().
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().
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.
|
static |
Internal function: create and return a new digest object for 'algorithm'. Does not typecheck the algorithm.
Definition at line 224 of file crypto_digest_nss.c.
Referenced by crypto_digest_new(), and crypto_digest_smartlist_prefix().
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_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.
Definition at line 471 of file crypto_digest_nss.c.
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.
Definition at line 486 of file crypto_digest_nss.c.
Referenced by crypto_digest_smartlist().
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.
|
static |
Convert a digest_algorithm_t (used by tor) to a HashType (used by NSS). On failure, return SEC_OID_UNKNOWN.
Definition at line 34 of file crypto_digest_nss.c.
|
static |
Helper: Compute an unkeyed digest of the msg_len bytes at msg, using the digest algorithm specified by alg. Store the result in the len_out-byte buffer at digest. Return the number of bytes written on success, and -1 on failure.
Definition at line 53 of file crypto_digest_nss.c.
Referenced by crypto_digest().
|
static |
True iff alg is implemented in our crypto library, and we want to use that implementation
Definition at line 89 of file crypto_digest_nss.c.
Referenced by crypto_digest_assign(), crypto_digest_checkpoint(), crypto_digest_free_(), and crypto_digest_restore().