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.10 2002/03/01 14:39:18 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. */
50 * Digest type and selection.
53 /* bitmask of supported algorithms */
54 #define MDTYPE_MD5 0x1
55 #define MDTYPE_MICROSOFT 0x2
58 #define MDTYPE_ALL (MDTYPE_MD5 | MDTYPE_MICROSOFT)
60 #define MDTYPE_ALL (MDTYPE_MD5)
64 /* Return the digest alg. ID for the most preferred digest type. */
65 #define CHAP_DIGEST(mdtype) \
66 ((mdtype) & MDTYPE_MD5)? CHAP_DIGEST_MD5: \
67 ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
70 /* Return the bit flag (lsb set) for our most preferred digest type. */
71 #define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
73 /* Return the bit flag for a given digest algorithm ID. */
74 #define CHAP_MDTYPE_D(digest) \
75 ((digest) == CHAP_DIGEST_MD5)? MDTYPE_MD5: \
76 ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
79 /* Can we do the requested digest? */
80 #define CHAP_CANDIGEST(mdtype, digest) \
81 ((digest) == CHAP_DIGEST_MD5)? (mdtype) & MDTYPE_MD5: \
82 ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
85 #define CHAP_CHALLENGE 1
86 #define CHAP_RESPONSE 2
87 #define CHAP_SUCCESS 3
88 #define CHAP_FAILURE 4
91 * Challenge lengths (for challenges we send) and other limits.
93 #define MIN_CHALLENGE_LENGTH 16
94 #define MAX_CHALLENGE_LENGTH 24
95 #define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
98 * Each interface is described by a chap structure.
101 typedef struct chap_state {
102 int unit; /* Interface unit number */
103 int clientstate; /* Client state */
104 int serverstate; /* Server state */
105 u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
106 u_char chal_len; /* challenge length */
107 u_char chal_id; /* ID of last challenge */
108 u_char chal_type; /* hash algorithm for challenges */
109 u_char id; /* Current id */
110 char *chal_name; /* Our name to use with challenge */
111 int chal_interval; /* Time until we challenge peer again */
112 int timeouttime; /* Timeout time in seconds */
113 int max_transmits; /* Maximum # of challenge transmissions */
114 int chal_transmits; /* Number of transmissions of challenge */
115 int resp_transmits; /* Number of transmissions of response */
116 u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
117 u_char resp_length; /* length of response */
118 u_char resp_id; /* ID for response messages */
119 u_char resp_type; /* hash algorithm for responses */
120 char *resp_name; /* Our name to send with response */
123 /* We need the declaration of chap_state to use this prototype */
124 extern int (*chap_auth_hook) __P((char *user, u_char *remmd,
125 int remmd_len, chap_state *cstate));
128 * Client (peer) states.
130 #define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
131 #define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
132 #define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
133 #define CHAPCS_LISTEN 3 /* Listening for a challenge */
134 #define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
135 #define CHAPCS_OPEN 5 /* We've received Success */
138 * Server (authenticator) states.
140 #define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
141 #define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
142 #define CHAPSS_PENDING 2 /* Auth peer when lower up */
143 #define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
144 #define CHAPSS_OPEN 4 /* We've sent a Success msg */
145 #define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
146 #define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
151 #define CHAP_DEFTIMEOUT 3 /* Timeout time in seconds */
152 #define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */
154 extern chap_state chap[];
156 void ChapAuthWithPeer __P((int, char *, int));
157 void ChapAuthPeer __P((int, char *, int));
159 extern struct protent chap_protent;
161 #define __CHAP_INCLUDE__
162 #endif /* __CHAP_INCLUDE__ */