Imported Upstream version 0.66.1
[hcoop/debian/courier-authlib.git] / libs / libhmac / hmac.h
CommitLineData
d9898ee8 1#ifndef hmac_h
2#define hmac_h
3
4#include <string.h>
5
6/*
7** Copyright 1998 - 2005 Double Precision, Inc.
8** See COPYING for distribution information.
9*/
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
d9898ee8 15
16struct hmac_hashinfo { /* HMAC hash function descriptor */
17
18 const char *hh_name; /* Name of this hash function (md5, sha1...) */
19
20 size_t hh_B; /* Length of compression blocks */
21 size_t hh_L; /* Length of hash outputs */
22
23 size_t hh_S; /* Length of 'context structure' */
24
25 /* Hash functions */
26
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 */
31
32 void (*hh_getdigest)(void *, unsigned char *); /* Get the hash value */
33 void (*hh_setdigest)(void *, const unsigned char *);
34 /* Set the hash value */
35
36 /* Some helper functions */
37
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.
41 */
42
43 void (*hh_allocacontext)(void (*)(void *, void *), void *);
44
45 /* Like allocacontext, but alloc buffer for hash value, hh_L */
46
47 void (*hh_allocaval)(void (*)(unsigned char *, void *), void *);
48
49 } ;
50
51/* Known hash functions */
52
53extern struct hmac_hashinfo hmac_md5, hmac_sha1, hmac_sha256;
54
55/*
56** List of installed hash functions, dynamically generated at configuration
57** time.
58*/
59
60extern struct hmac_hashinfo *hmac_list[];
61
62/*
63 To calculate an HMAC, allocate three buffers - outer, inner, and hash.
64 Call hmac_hashkey, then hmac_hashtext.
65
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
68 calculation.
69*/
70
71void hmac_hashkey(
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 */
77
78void hmac_hashtext (
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 */
85
86#ifdef __cplusplus
8d138742 87}
d9898ee8 88#endif
89
90#endif