32 #define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-hash", __VA_ARGS__) 34 #define LOG_STRERROR_FILE(kind, syscall, \ 35 filename) GNUNET_log_from_strerror_file (kind, \ 46 gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size);
76 char upper_enc[enclen];
77 char *up_ptr = upper_enc;
82 (
unsigned char *) result,
91 unsigned int x1 = (a->
bits[1] - b->
bits[1]) >> 16;
92 unsigned int x2 = (b->
bits[1] - a->
bits[1]) >> 16;
102 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(uint32_t)) - 1;
114 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int)) - 1;
126 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int)) - 1;
138 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int)) - 1;
155 "Hash key derivation",
156 strlen (
"Hash key derivation"),
163 "Initialization vector derivation",
164 strlen (
"Initialization vector derivation"),
175 return (((
unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0;
184 return (((
unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
207 i1 = (
unsigned int *) h1;
208 i2 = (
unsigned int *) h2;
209 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int)) - 1;
230 for (ssize_t i =
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int) - 1;
234 d1 = ((
unsigned int *) h1)[i] ^ ((
unsigned int *) target)[i];
235 d2 = ((
unsigned int *) h2)[i] ^ ((
unsigned int *) target)[i];
249 const void *
salt,
size_t salt_len, ...)
253 va_start (argp, salt_len);
263 const void *
salt,
size_t salt_len,
275 const void *plaintext,
size_t plaintext_len,
279 static gcry_md_hd_t md;
280 const unsigned char *
mc;
286 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
292 gcry_md_setkey (md, key, key_len);
293 gcry_md_write (md, plaintext, plaintext_len);
294 mc = gcry_md_read (md, GCRY_MD_SHA512);
302 const void *plaintext,
size_t plaintext_len,
306 plaintext, plaintext_len,
329 gcry_md_open (&hc->
hd,
345 gcry_md_write (hc->
hd, buf, size);
357 gcry_md_copy (&cp->
hd,
367 const void *
res = gcry_md_read (hc->
hd, 0);
384 gcry_md_close (hc->
hd);
int GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2, const struct GNUNET_HashCode *target)
Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia)...
static struct GNUNET_TIME_Relative delta
#define BENCHMARK_START(opname)
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start()
Start incremental hashing operation.
unsigned int GNUNET_CRYPTO_hash_matching_bits(const struct GNUNET_HashCode *first, const struct GNUNET_HashCode *second)
Determine how many low order bits match in two struct GNUNET_HashCodes.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define BENCHMARK_END(opname)
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn' this be the standard hmac function and the abov...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
GNUNET_GenericReturnValue
Named constants for return values.
GNUNET_CRYPTO_Quality
Desired quality level for random numbers.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
int GNUNET_CRYPTO_hash_get_bit_rtl(const struct GNUNET_HashCode *code, unsigned int bit)
Obtain a bit from a hashcode.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf_v(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
Derive key.
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
void GNUNET_CRYPTO_hash_sum(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *delta, struct GNUNET_HashCode *result)
compute result = a + delta
void GNUNET_CRYPTO_hash_context_abort(struct GNUNET_HashContext *hc)
Abort hashing, do not bother calculating final result.
cryptographic primitives for GNUnet
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hash_from_string2(const char *enc, size_t enclen, struct GNUNET_HashCode *result)
Convert ASCII encoding back to a 'struct GNUNET_HashCode'.
void GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
void GNUNET_CRYPTO_hash_create_random(enum GNUNET_CRYPTO_Quality mode, struct GNUNET_HashCode *result)
Create a random hash code.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
static int once
Global to mark if we've run the initialization.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
static int result
Global testing status.
unsigned char key[(512/8)]
unsigned int GNUNET_CRYPTO_hash_distance_u32(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b)
Compute the distance between 2 hashcodes.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
void GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Convert a hashcode into a key.
struct GNUNET_HashCode key
The key used in the DHT.
void GNUNET_CRYPTO_hash_to_enc(const struct GNUNET_HashCode *block, struct GNUNET_CRYPTO_HashAsciiEncoded *result)
Convert hash to ASCII encoding.
static unsigned int size
Size of the "table".
void GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len, va_list argp)
Derive an authentication key.
gcry_md_hd_t hd
Internal state of the hash function.
0-terminated ASCII encoding of a struct GNUNET_HashCode.
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calcualations.
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
static OpusEncoder * enc
OPUS encoder.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_copy(const struct GNUNET_HashContext *hc)
Make a copy of the hash computation.
int GNUNET_CRYPTO_hash_get_bit_ltr(const struct GNUNET_HashCode *code, unsigned int bit)
Obtain a bit from a hashcode.
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
benchmarking for various operations
void GNUNET_CRYPTO_hash_difference(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = b - a
void GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
Derive an authentication key.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
type for (message) authentication keys
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t bits[512/8/sizeof(uint32_t)]