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