xref: /illumos-gate/usr/src/lib/libsasl/include/hmac-md5.h (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1 /*
2  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /* hmac-md5.h -- HMAC_MD5 functions
7  */
8 
9 #ifndef HMAC_MD5_H
10 #define HMAC_MD5_H 1
11 
12 #define HMAC_MD5_SIZE 16
13 
14 #ifdef _SUN_SDK_
15 #ifndef SASLPLUG_H
16 #include <sasl/saslplug.h>
17 #endif
18 #else
19 /* intermediate MD5 context */
20 typedef struct HMAC_MD5_CTX_s {
21     MD5_CTX ictx, octx;
22 } HMAC_MD5_CTX;
23 
24 /* intermediate HMAC state
25  *  values stored in network byte order (Big Endian)
26  */
27 typedef struct HMAC_MD5_STATE_s {
28     UINT4 istate[4];
29     UINT4 ostate[4];
30 } HMAC_MD5_STATE;
31 #endif /* _SUN_SDK */
32 
33 /* One step hmac computation
34  *
35  * digest may be same as text or key
36  */
37 void _sasl_hmac_md5(const unsigned char *text, int text_len,
38 		    const unsigned char *key, int key_len,
39 		    unsigned char digest[HMAC_MD5_SIZE]);
40 
41 /* create context from key
42  */
43 void _sasl_hmac_md5_init(HMAC_MD5_CTX *hmac,
44 			 const unsigned char *key, int key_len);
45 
46 /* precalculate intermediate state from key
47  */
48 void _sasl_hmac_md5_precalc(HMAC_MD5_STATE *hmac,
49 			    const unsigned char *key, int key_len);
50 
51 /* initialize context from intermediate state
52  */
53 void _sasl_hmac_md5_import(HMAC_MD5_CTX *hmac, HMAC_MD5_STATE *state);
54 
55 #define _sasl_hmac_md5_update(hmac, text, text_len) _sasl_MD5Update(&(hmac)->ictx, (text), (text_len))
56 
57 /* finish hmac from intermediate result.  Intermediate result is zeroed.
58  */
59 void _sasl_hmac_md5_final(unsigned char digest[HMAC_MD5_SIZE],
60 			  HMAC_MD5_CTX *hmac);
61 
62 #endif /* HMAC_MD5_H */
63