19 #include "keccak-tiny/keccak-tiny.h"
33 memset(ds_out, 0,
sizeof(*ds_out));
60 return "??unknown_digest??";
70 if (!strcmp(
name,
"sha1"))
72 else if (!strcmp(
name,
"sha256"))
74 else if (!strcmp(
name,
"sha512"))
76 else if (!strcmp(
name,
"sha3-256"))
77 return DIGEST_SHA3_256;
78 else if (!strcmp(
name,
"sha3-512"))
79 return DIGEST_SHA3_512;
111 const uint8_t *key,
size_t key_len,
112 const uint8_t *msg,
size_t msg_len)
116 const uint64_t key_len_netorder =
tor_htonll(key_len);
127 sizeof(key_len_netorder));
138 #ifdef OPENSSL_HAS_SHAKE3_EVP
170 #ifdef OPENSSL_HAS_SHAKE256
171 xof->ctx = EVP_MD_CTX_new();
173 int r = EVP_DigestInit(xof->ctx, EVP_shake256());
176 keccak_xof_init(&xof->
s, 256);
188 #ifdef OPENSSL_HAS_SHAKE256
189 int r = EVP_DigestUpdate(xof->ctx, data, len);
192 int i = keccak_xof_absorb(&xof->
s, data, len);
203 #ifdef OPENSSL_HAS_SHAKE256
204 int r = EVP_DigestFinalXOF(xof->ctx, out, len);
207 int i = keccak_xof_squeeze(&xof->
s, out, len);
218 #ifdef OPENSSL_HAS_SHAKE256
220 EVP_MD_CTX_free(xof->ctx);
230 const uint8_t *input,
size_t input_len)
232 #ifdef OPENSSL_HAS_SHA3
233 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
235 int r = EVP_DigestInit(ctx, EVP_shake256());
237 r = EVP_DigestUpdate(ctx, input, input_len);
239 r = EVP_DigestFinalXOF(ctx, output, output_len);
241 EVP_MD_CTX_free(ctx);
Inline functions for reading and writing multibyte values from the middle of strings,...
static uint64_t tor_htonll(uint64_t a)
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)
size_t crypto_digest_algorithm_get_length(digest_algorithm_t alg)
void crypto_xof(uint8_t *output, size_t output_len, const uint8_t *input, size_t input_len)
void crypto_xof_squeeze_bytes(crypto_xof_t *xof, uint8_t *out, size_t len)
int crypto_common_digests(common_digests_t *ds_out, const char *m, size_t len)
crypto_xof_t * crypto_xof_new(void)
void crypto_xof_add_bytes(crypto_xof_t *xof, const uint8_t *data, size_t len)
const char * crypto_digest_algorithm_get_name(digest_algorithm_t alg)
void crypto_xof_free_(crypto_xof_t *xof)
int crypto_digest_algorithm_parse_name(const char *name)
Headers for crypto_digest.c.
int crypto_digest256(char *digest, const char *m, size_t len, digest_algorithm_t algorithm)
void crypto_digest_get_digest(crypto_digest_t *digest, char *out, size_t out_len)
#define crypto_xof_free(xof)
crypto_digest_t * crypto_digest256_new(digest_algorithm_t algorithm)
#define crypto_digest_free(d)
int crypto_digest(char *digest, const char *m, size_t len)
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data, size_t len)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
char d[N_COMMON_DIGEST_ALGORITHMS][DIGEST256_LEN]
Macros to manage assertions, fatal and non-fatal.
#define tor_fragile_assert()