2 Unix SMB/Netbios implementation.
4 Interface header: Scheduler service
5 Copyright (C) Luke Kenneth Casson Leighton 1996-1999
6 Copyright (C) Andrew Tridgell 1992-1999
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* taken direct from rfc2104 implementation and modified for suitable use
29 /***********************************************************************
30 the rfc 2104 version of hmac_md5 initialisation.
31 ***********************************************************************/
32 void hmac_md5_init_rfc2104(uchar* key, int key_len, HMACMD5Context *ctx)
36 /* if key is longer than 64 bytes reset it to key=MD5(key) */
40 struct MD5Context tctx;
43 MD5Update(&tctx, key, key_len);
50 /* start out by storing key in pads */
51 bzero( ctx->k_ipad, sizeof ctx->k_ipad);
52 bzero( ctx->k_opad, sizeof ctx->k_opad);
53 bcopy( key, ctx->k_ipad, key_len);
54 bcopy( key, ctx->k_opad, key_len);
56 /* XOR key with ipad and opad values */
59 ctx->k_ipad[i] ^= 0x36;
60 ctx->k_opad[i] ^= 0x5c;
64 MD5Update(&ctx->ctx, ctx->k_ipad, 64);
67 /***********************************************************************
68 the microsoft version of hmac_md5 initialisation.
69 ***********************************************************************/
70 void hmac_md5_init_limK_to_64(uchar* key, int key_len, HMACMD5Context *ctx)
74 /* if key is longer than 64 bytes truncate it */
80 /* start out by storing key in pads */
81 bzero( ctx->k_ipad, sizeof ctx->k_ipad);
82 bzero( ctx->k_opad, sizeof ctx->k_opad);
83 bcopy( key, ctx->k_ipad, key_len);
84 bcopy( key, ctx->k_opad, key_len);
86 /* XOR key with ipad and opad values */
89 ctx->k_ipad[i] ^= 0x36;
90 ctx->k_opad[i] ^= 0x5c;
94 MD5Update(&ctx->ctx, ctx->k_ipad, 64);
97 /***********************************************************************
98 update hmac_md5 "inner" buffer
99 ***********************************************************************/
100 void hmac_md5_update(uchar* text, int text_len, HMACMD5Context *ctx)
102 MD5Update(&ctx->ctx, text, text_len); /* then text of datagram */
105 /***********************************************************************
106 finish off hmac_md5 "inner" buffer and generate outer one.
107 ***********************************************************************/
108 void hmac_md5_final(caddr_t digest, HMACMD5Context *ctx)
111 struct MD5Context ctx_o;
113 MD5Final(digest, &ctx->ctx);
116 MD5Update(&ctx_o, ctx->k_opad, 64);
117 MD5Update(&ctx_o, digest, 16);
118 MD5Final(digest, &ctx_o);