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