1 /***********************************************************************
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.
14 ***********************************************************************/
16 static char const RCSID
[] =
17 "$Id: auth.c,v 1.1.48.1 2005/08/08 12:05:25 honor Exp $";
23 /**********************************************************************
24 * %FUNCTION: auth_gen_response
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
34 * Computes a response for the challenge using "secret"
35 ***********************************************************************/
37 l2tp_auth_gen_response(uint16_t msg_type
,
39 unsigned char const *challenge
,
41 unsigned char buf
[16])
43 struct MD5Context ctx
;
44 unsigned char id
= (unsigned char) msg_type
;
47 MD5Update(&ctx
, &id
, 1);
48 MD5Update(&ctx
, (unsigned char *) secret
, strlen(secret
));
49 MD5Update(&ctx
, challenge
, chal_len
);
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]));