Corrected new hash API bug that prevented usage of plain hash functions.
dig->registered = 1;
dig->hd.rh.cc = cc;
- if (cc->init (algorithm, &dig->hd.rh.ctx) < 0)
+ if (cc->init (algorithm, &dig->hd.rh.ctx, key, keylen) < 0)
{
gnutls_assert ();
return GNUTLS_E_HASH_FAILED;
}
- if (key)
- {
- if (cc->setkey == NULL || cc->setkey (dig->hd.rh.ctx, key, keylen) < 0)
- {
- gnutls_assert ();
- cc->deinit (dig->hd.rh.ctx);
- return GNUTLS_E_HASH_FAILED;
- }
- }
-
dig->active = 1;
return 0;
}
dig->registered = 0;
- result = _gnutls_mac_ops.init (algorithm, &dig->hd.gc);
+ result = _gnutls_mac_ops.init (algorithm, &dig->hd.gc, key, keylen);
if (result < 0)
{
gnutls_assert ();
return result;
}
- if (key)
- {
- _gnutls_mac_ops.setkey (dig->hd.gc, key, keylen);
- }
-
dig->active = 1;
return 0;
}
typedef struct
{
- int (*init) (gnutls_mac_algorithm_t, void **ctx);
- int (*setkey) (void *ctx, const void *key, size_t keysize);
+ int (*init) (gnutls_mac_algorithm_t, void **ctx, const void* key, size_t keysize);
int (*hash) (void *ctx, const void *text, size_t textsize);
int (*copy) (void **dst_ctx, void *src_ctx);
int (*output) (void *src_ctx, void *digest, size_t digestsize);
#include <gcrypt.h>
static int
-wrap_gcry_mac_init (gnutls_digest_algorithm_t algo, void **ctx)
+wrap_gcry_mac_init (gnutls_digest_algorithm_t algo, void **ctx, const void* key, size_t keylen)
{
int err;
- unsigned int flags = GCRY_MD_FLAG_HMAC;
+ unsigned int flags = 0;
+
+ if (key) flags = GCRY_MD_FLAG_HMAC;
switch (algo)
{
return GNUTLS_E_INVALID_REQUEST;
}
+ if (key)
+ gcry_md_setkey ((gcry_md_hd_t) *ctx, key, keylen);
+
if (err == 0)
return 0;
return GNUTLS_E_ENCRYPTION_FAILED;
}
-static int
-wrap_gcry_md_setkey (void *ctx, const void *key, size_t keylen)
-{
- return gcry_md_setkey ((gcry_md_hd_t) ctx, key, keylen);
-}
-
static int
wrap_gcry_md_write (void *ctx, const void *text, size_t textsize)
{
gnutls_crypto_digest_st _gnutls_mac_ops = {
.init = wrap_gcry_mac_init,
- .setkey = wrap_gcry_md_setkey,
.hash = wrap_gcry_md_write,
.copy = wrap_gcry_md_copy,
.output = wrap_gcry_mac_output,
if (!md)
return NULL;
- _gnutls_hash_fast (GNUTLS_DIG_MD5, buf, len, NULL, 0, md);
+ _gnutls_hash_fast (GNUTLS_DIG_MD5, NULL, 0, buf, len, md);
return md;
}
if (!md)
return NULL;
- _gnutls_hash_fast (GNUTLS_DIG_RMD160, buf, len, NULL, 0, md);
+ _gnutls_hash_fast (GNUTLS_DIG_RMD160, NULL, 0, buf, len, md);
return md;
}
/* XXX: We need this to fix secure memory. */
gnutls_global_init ();
+ err =
+ _gnutls_hash_fast (GNUTLS_MAC_MD5, NULL, 0, "testtest", 8, digest);
+ if (err < 0)
+ fail ("_gnutls_hash_fast(MD5) failed: %d\n", err);
+ else
+ {
+ if (memcmp (digest, "\x05\xa6\x71\xc6\x6a\xef\xea\x12\x4c\xc0\x8b\x76\xea\x6d\x30\xbb", 16) == 0)
+ success ("HASH: _gnutls_hash_fast(MD5) OK\n");
+ else
+ {
+ hexprint (digest, 16);
+ fail ("HASH: _gnutls_hash_fast(MD5) failure\n");
+ }
+ }
+
+
err =
_gnutls_hash_fast (GNUTLS_MAC_MD5, "keykeykey", 9, "abcdefgh", 8, digest);
if (err < 0)