GNUNET_free (fhc->filename);
if (!GNUNET_DISK_handle_invalid (fhc->fh))
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
+ gcry_md_close (fhc->md);
GNUNET_free (fhc); /* also frees fhc->buffer */
}
{
res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
file_hash_finish (fhc, res);
- gcry_md_close (fhc->md);
return;
}
fhc->task
result->bits[i] = delta->bits[i] + a->bits[i];
}
+
void
GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a,
- const GNUNET_HashCode * b, GNUNET_HashCode * result)
+ const GNUNET_HashCode * b,
+ GNUNET_HashCode * result)
{
int i;
for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
result->bits[i] = a->bits[i] ^ b->bits[i];
}
+
/**
* Convert a hashcode into a key.
*/
sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
}
+
/**
* Obtain a bit from a hashcode.
* @param code the GNUNET_CRYPTO_hash to index bit-wise
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit)
+GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code,
+ unsigned int bit)
{
GNUNET_assert (bit < 8 * sizeof (GNUNET_HashCode));
return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
*
* @return the number of bits that match
*/
-unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, const GNUNET_HashCode *second)
+unsigned int
+GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first,
+ const GNUNET_HashCode *second)
{
unsigned int i;
return sizeof (GNUNET_HashCode) * 8;
}
+
/**
* Compare function for HashCodes, producing a total ordering
* of all hashcodes.
return 0;
}
+
/**
* Find out which of the two GNUNET_CRYPTO_hash codes is closer to target
* in the XOR metric (Kademlia).
GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key,
const struct GNUNET_CRYPTO_AesSessionKey *rkey,
const void *salt,
- const size_t salt_len,
+ size_t salt_len,
...)
{
va_list argp;
GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key,
const struct GNUNET_CRYPTO_AesSessionKey *rkey,
const void *salt,
- const size_t salt_len,
+ size_t salt_len,
va_list argp)
{
- GNUNET_CRYPTO_kdf_v (key->key, sizeof(key->key), salt, salt_len, rkey->key,
- sizeof(rkey->key), argp);
+ GNUNET_CRYPTO_kdf_v (key->key,
+ sizeof(key->key),
+ salt, salt_len,
+ rkey->key,
+ sizeof(rkey->key),
+ argp);
}
+
/**
* Calculate HMAC of a message (RFC 2104)
*
GNUNET_HashCode *hmac)
{
gcry_md_hd_t md;
- unsigned char *mc;
+ const unsigned char *mc;
- GNUNET_assert (GPG_ERR_NO_ERROR == gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
+ GNUNET_assert (GPG_ERR_NO_ERROR == gcry_md_open (&md,
+ GCRY_MD_SHA512,
+ GCRY_MD_FLAG_HMAC));
gcry_md_setkey (md, key->key, sizeof(key->key));
gcry_md_write (md, plaintext, plaintext_len);
mc = gcry_md_read (md, GCRY_MD_SHA512);