return GC_OK;
}
+
+int
+gc_hmac_sha1 (const char *key, size_t keylen,
+ const char *in, size_t inlen,
+ char outhash[GC_SHA1_LEN])
+{
+ size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
+ gcry_md_hd_t mdh;
+ unsigned char *hash;
+ gpg_error_t err;
+
+ assert (hlen == GC_SHA1_LEN);
+
+ err = gcry_md_open (&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
+ if (err != GPG_ERR_NO_ERROR)
+ return GC_INVALID_HASH;
+
+ err = gcry_md_setkey (mdh, key, keylen);
+ if (err != GPG_ERR_NO_ERROR)
+ return GC_INVALID_HASH;
+
+ gcry_md_write (mdh, in, inlen);
+
+ hash = gcry_md_read (mdh, GCRY_MD_SHA1);
+ if (hash == NULL)
+ return GC_INVALID_HASH;
+
+ memcpy (outhash, hash, hlen);
+
+ gcry_md_close (mdh);
+
+ return GC_OK;
+}
* gc_md5:
* @in: input character array of data to hash.
* @inlen: length of input character array of data to hash.
- * @out: newly allocated character array with hash of data.
+ * @out: pre-allocated character array with hash of data.
*
- * Compute hash of data using MD5. The @out buffer must be
- * deallocated by the caller.
+ * Compute hash of data using MD5.
*
* Return value: Returns %GC_OK iff successful.
**/
* @keylen: length of input character array with key to use.
* @in: input character array of data to hash.
* @inlen: length of input character array of data to hash.
- * @outhash: newly allocated character array with keyed hash of data.
+ * @outhash: pre-allocated character array with keyed hash of data.
*
- * Compute keyed checksum of data using HMAC-MD5. The @outhash buffer
- * must be deallocated by the caller.
+ * Compute keyed checksum of data using HMAC-MD5.
*
* Return value: Returns %GC_OK iff successful.
**/
return GC_OK;
}
+
+/**
+ * gc_hmac_sha1:
+ * @key: input character array with key to use.
+ * @keylen: length of input character array with key to use.
+ * @in: input character array of data to hash.
+ * @inlen: length of input character array of data to hash.
+ * @outhash: pre-allocated character array with keyed hash of data.
+ *
+ * Compute keyed checksum of data using HMAC-SHA1.
+ *
+ * Return value: Returns %GC_OK iff successful.
+ **/
+int
+gc_hmac_sha1 (const char *key, size_t keylen,
+ const char *in, size_t inlen,
+ char outhash[SHA1_DIGEST_SIZE])
+{
+ struct hmac_sha1_ctx ctx;
+
+ hmac_sha1_set_key (&ctx, keylen, key);
+ hmac_sha1_update (&ctx, inlen, in);
+ hmac_sha1_digest (&ctx, SHA1_DIGEST_SIZE, outhash);
+
+ return GC_OK;
+}
extern int gc_hmac_md5 (const char *key, size_t keylen,
const char *in, size_t inlen,
char outhash[GC_MD5_LEN]);
+extern int gc_hmac_sha1 (const char *key, size_t keylen,
+ const char *in, size_t inlen,
+ char outhash[GC_SHA1_LEN]);
#endif /* GC_H */