Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / rp-l2tp / auth.c
bloba51a911da146763076d32d532d4cb265df599f19
1 /***********************************************************************
3 * auth.c
5 * Code for doing CHAP-style authentication
7 * Copyright (C) 2002 by Roaring Penguin Software Inc.
9 * This software may be distributed under the terms of the GNU General
10 * Public License, Version 2, or (at your option) any later version.
12 * LIC: GPL
14 ***********************************************************************/
16 static char const RCSID[] =
17 "$Id: auth.c,v 1.1.48.1 2005/08/08 12:05:25 honor Exp $";
19 #include "l2tp.h"
20 #include "md5.h"
21 #include <string.h>
23 /**********************************************************************
24 * %FUNCTION: auth_gen_response
25 * %ARGUMENTS:
26 * msg_type -- message type
27 * secret -- secret to use
28 * challenge -- challenge received from peer
29 * chal_len -- length of challenge
30 * buf -- buffer in which to place 16-byte response
31 * %RETURNS:
32 * Nothing
33 * %DESCRIPTION:
34 * Computes a response for the challenge using "secret"
35 ***********************************************************************/
36 void
37 l2tp_auth_gen_response(uint16_t msg_type,
38 char const *secret,
39 unsigned char const *challenge,
40 size_t chal_len,
41 unsigned char buf[16])
43 struct MD5Context ctx;
44 unsigned char id = (unsigned char) msg_type;
46 MD5Init(&ctx);
47 MD5Update(&ctx, &id, 1);
48 MD5Update(&ctx, (unsigned char *) secret, strlen(secret));
49 MD5Update(&ctx, challenge, chal_len);
50 MD5Final(buf, &ctx);
51 DBG(l2tp_db(DBG_AUTH, "auth_gen_response(secret=%s) -> %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", secret,
52 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
53 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]));