7 ** Copyright 1998 - 2005 Double Precision, Inc.
8 ** See COPYING for distribution information.
15 static const char hmac_h_rcsid
[]="$Id: hmac.h,v 1.7 2009/06/27 17:12:00 mrsam Exp $";
17 struct hmac_hashinfo
{ /* HMAC hash function descriptor */
19 const char *hh_name
; /* Name of this hash function (md5, sha1...) */
21 size_t hh_B
; /* Length of compression blocks */
22 size_t hh_L
; /* Length of hash outputs */
24 size_t hh_S
; /* Length of 'context structure' */
28 void (*hh_init
)(void *); /* Initialize context structure */
29 void (*hh_hash
)(void *, const void *, unsigned);
30 /* Feed the hash function */
31 void (*hh_endhash
)(void *, unsigned long); /* Calculate final hash */
33 void (*hh_getdigest
)(void *, unsigned char *); /* Get the hash value */
34 void (*hh_setdigest
)(void *, const unsigned char *);
35 /* Set the hash value */
37 /* Some helper functions */
39 /* Allocate context on stack, instead of mallocing it. Calls the
40 ** provided function pointer, with context as first arg. The second
41 ** arg will be passed as provided.
44 void (*hh_allocacontext
)(void (*)(void *, void *), void *);
46 /* Like allocacontext, but alloc buffer for hash value, hh_L */
48 void (*hh_allocaval
)(void (*)(unsigned char *, void *), void *);
52 /* Known hash functions */
54 extern struct hmac_hashinfo hmac_md5
, hmac_sha1
, hmac_sha256
;
57 ** List of installed hash functions, dynamically generated at configuration
61 extern struct hmac_hashinfo
*hmac_list
[];
64 To calculate an HMAC, allocate three buffers - outer, inner, and hash.
65 Call hmac_hashkey, then hmac_hashtext.
67 After hmac_haskey returns, the contents of inner and outer can be
68 saved, as they contain a complete intermediate state of the hash
73 const struct hmac_hashinfo
*,
74 const char *, /* Key */
75 size_t, /* Key length */
76 unsigned char *, /* Output - outer buffer, prehashed */
77 unsigned char *); /* Output - inner buffer, prehashed */
80 const struct hmac_hashinfo
*,
81 const char *, /* Text */
82 size_t, /* Text length */
83 const unsigned char *, /* outer buffer, prehashed */
84 const unsigned char *, /* inner buffer, prehashed */
85 unsigned char *); /* Output - the hash */