7 ** Copyright 1998 - 2005 Double Precision, Inc.
8 ** See COPYING for distribution information.
16 struct hmac_hashinfo
{ /* HMAC hash function descriptor */
18 const char *hh_name
; /* Name of this hash function (md5, sha1...) */
20 size_t hh_B
; /* Length of compression blocks */
21 size_t hh_L
; /* Length of hash outputs */
23 size_t hh_S
; /* Length of 'context structure' */
27 void (*hh_init
)(void *); /* Initialize context structure */
28 void (*hh_hash
)(void *, const void *, unsigned);
29 /* Feed the hash function */
30 void (*hh_endhash
)(void *, unsigned long); /* Calculate final hash */
32 void (*hh_getdigest
)(void *, unsigned char *); /* Get the hash value */
33 void (*hh_setdigest
)(void *, const unsigned char *);
34 /* Set the hash value */
36 /* Some helper functions */
38 /* Allocate context on stack, instead of mallocing it. Calls the
39 ** provided function pointer, with context as first arg. The second
40 ** arg will be passed as provided.
43 void (*hh_allocacontext
)(void (*)(void *, void *), void *);
45 /* Like allocacontext, but alloc buffer for hash value, hh_L */
47 void (*hh_allocaval
)(void (*)(unsigned char *, void *), void *);
51 /* Known hash functions */
53 extern struct hmac_hashinfo hmac_md5
, hmac_sha1
, hmac_sha256
;
56 ** List of installed hash functions, dynamically generated at configuration
60 extern struct hmac_hashinfo
*hmac_list
[];
63 To calculate an HMAC, allocate three buffers - outer, inner, and hash.
64 Call hmac_hashkey, then hmac_hashtext.
66 After hmac_haskey returns, the contents of inner and outer can be
67 saved, as they contain a complete intermediate state of the hash
72 const struct hmac_hashinfo
*,
73 const char *, /* Key */
74 size_t, /* Key length */
75 unsigned char *, /* Output - outer buffer, prehashed */
76 unsigned char *); /* Output - inner buffer, prehashed */
79 const struct hmac_hashinfo
*,
80 const char *, /* Text */
81 size_t, /* Text length */
82 const unsigned char *, /* outer buffer, prehashed */
83 const unsigned char *, /* inner buffer, prehashed */
84 unsigned char *); /* Output - the hash */