2 * chap.h - Challenge Handshake Authentication Protocol definitions.
4 * Copyright (c) 1993 The Australian National University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by the Australian National University. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 * Copyright (c) 1991 Gregory M. Christy
20 * All rights reserved.
22 * Redistribution and use in source and binary forms are permitted
23 * provided that the above copyright notice and this paragraph are
24 * duplicated in all such forms and that any documentation,
25 * advertising materials, and other materials related to such
26 * distribution and use acknowledge that the software was developed
29 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
31 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33 * $Id: chap.h,v 1.13 2002/05/21 17:26:49 dfs Exp $
36 #ifndef __CHAP_INCLUDE__
38 /* Code + ID + length */
39 #define CHAP_HEADERLEN 4
45 #define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
46 #define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
47 #define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
48 #define CHAP_MICROSOFT_V2 0x81 /* use Microsoft-compatible alg. */
51 * Digest type and selection.
54 /* bitmask of supported algorithms */
55 #define MDTYPE_MICROSOFT_V2 0x1
56 #define MDTYPE_MICROSOFT 0x2
57 #define MDTYPE_MD5 0x4
60 #define MDTYPE_ALL (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT |MDTYPE_MD5)
62 #define MDTYPE_ALL (MDTYPE_MD5)
66 /* Return the digest alg. ID for the most preferred digest type. */
67 #define CHAP_DIGEST(mdtype) \
68 ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \
69 ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
70 ((mdtype) & MDTYPE_MD5)? CHAP_DIGEST_MD5: \
73 /* Return the bit flag (lsb set) for our most preferred digest type. */
74 #define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
76 /* Return the bit flag for a given digest algorithm ID. */
77 #define CHAP_MDTYPE_D(digest) \
78 ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \
79 ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
80 ((digest) == CHAP_DIGEST_MD5)? MDTYPE_MD5: \
83 /* Can we do the requested digest? */
84 #define CHAP_CANDIGEST(mdtype, digest) \
85 ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \
86 ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
87 ((digest) == CHAP_DIGEST_MD5)? (mdtype) & MDTYPE_MD5: \
90 #define CHAP_CHALLENGE 1
91 #define CHAP_RESPONSE 2
92 #define CHAP_SUCCESS 3
93 #define CHAP_FAILURE 4
96 * Challenge lengths (for challenges we send) and other limits.
98 #define MIN_CHALLENGE_LENGTH 16
99 #define MAX_CHALLENGE_LENGTH 24 /* sufficient for MS-CHAP Peer Chal. */
100 #define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
101 #define MS_AUTH_RESPONSE_LENGTH 40 /* MS-CHAPv2 authenticator response, */
105 * Each interface is described by a chap structure.
108 typedef struct chap_state {
109 int unit; /* Interface unit number */
110 int clientstate; /* Client state */
111 int serverstate; /* Server state */
112 u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
113 u_char chal_len; /* challenge length */
114 u_char chal_id; /* ID of last challenge */
115 u_char chal_type; /* hash algorithm for challenges */
116 u_char id; /* Current id */
117 char *chal_name; /* Our name to use with challenge */
118 int chal_interval; /* Time until we challenge peer again */
119 int timeouttime; /* Timeout time in seconds */
120 int max_transmits; /* Maximum # of challenge transmissions */
121 int chal_transmits; /* Number of transmissions of challenge */
122 int resp_transmits; /* Number of transmissions of response */
123 u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
124 char saresponse[MS_AUTH_RESPONSE_LENGTH+1]; /* Auth response to send */
125 char earesponse[MS_AUTH_RESPONSE_LENGTH+1]; /* Auth response expected */
126 /* +1 for null terminator */
127 u_char resp_flags; /* flags from MS-CHAPv2 auth response */
128 u_char resp_length; /* length of response */
129 u_char resp_id; /* ID for response messages */
130 u_char resp_type; /* hash algorithm for responses */
131 char *resp_name; /* Our name to send with response */
134 /* We need the declaration of chap_state to use this prototype */
135 extern int (*chap_auth_hook) __P((char *user, u_char *remmd,
136 int remmd_len, chap_state *cstate));
139 * Client (peer) states.
141 #define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
142 #define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
143 #define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
144 #define CHAPCS_LISTEN 3 /* Listening for a challenge */
145 #define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
146 #define CHAPCS_OPEN 5 /* We've received Success */
149 * Server (authenticator) states.
151 #define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
152 #define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
153 #define CHAPSS_PENDING 2 /* Auth peer when lower up */
154 #define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
155 #define CHAPSS_OPEN 4 /* We've sent a Success msg */
156 #define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
157 #define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
162 #define CHAP_DEFTIMEOUT 3 /* Timeout time in seconds */
163 #define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */
165 extern chap_state chap[];
167 void ChapAuthWithPeer __P((int, char *, int));
168 void ChapAuthPeer __P((int, char *, int));
170 extern struct protent chap_protent;
172 #define __CHAP_INCLUDE__
173 #endif /* __CHAP_INCLUDE__ */