/**
* Hash block of given size.
*
- * @param block the data to GNUNET_CRYPTO_hash, length is given as a second argument
- * @param size the length of the data to GNUNET_CRYPTO_hash
+ * @param block the data to #GNUNET_CRYPTO_hash, length is given as a second argument
+ * @param size the length of the data to #GNUNET_CRYPTO_hash in @a block
* @param ret pointer to where to write the hashcode
*/
void
-GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * ret)
+GNUNET_CRYPTO_hash (const void *block,
+ size_t size,
+ struct GNUNET_HashCode *ret)
{
gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size);
}
int
GNUNET_CRYPTO_hash_from_string2 (const char *enc,
size_t enclen,
- struct GNUNET_HashCode *result)
+ struct GNUNET_HashCode *result)
{
char upper_enc[enclen];
- char* up_ptr = upper_enc;
+ char *up_ptr = upper_enc;
- GNUNET_STRINGS_utf8_toupper(enc, &up_ptr);
+ GNUNET_STRINGS_utf8_toupper (enc, up_ptr);
return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
(unsigned char*) result,
void
GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
const void *plaintext, size_t plaintext_len,
- struct GNUNET_HashCode * hmac)
+ struct GNUNET_HashCode *hmac)
{
- gcry_md_hd_t md;
+ static int once;
+ static gcry_md_hd_t md;
const unsigned char *mc;
- GNUNET_assert (GPG_ERR_NO_ERROR ==
- gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
+ if (! once)
+ {
+ once = 1;
+ GNUNET_assert (GPG_ERR_NO_ERROR ==
+ gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
+ }
+ else
+ {
+ gcry_md_reset (md);
+ }
gcry_md_setkey (md, key->key, sizeof (key->key));
gcry_md_write (md, plaintext, plaintext_len);
mc = gcry_md_read (md, GCRY_MD_SHA512);
- if (mc != NULL)
- memcpy (hmac->bits, mc, sizeof (hmac->bits));
- gcry_md_close (md);
+ GNUNET_assert (NULL != mc);
+ memcpy (hmac->bits, mc, sizeof (hmac->bits));
}