32#if PPP_SUPPORT && CHAP_SUPPORT
51#define CHAP_CHALLENGE 1
52#define CHAP_RESPONSE 2
61#define CHAP_MICROSOFT 0x80
62#define CHAP_MICROSOFT_V2 0x81
68#define MAX_CHALLENGE_LEN 64
69#define MAX_RESPONSE_LEN 64
75#define CHAL_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_CHALLENGE_LEN + MAXNAMELEN)
76#define RESP_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_RESPONSE_LEN + MAXNAMELEN)
80#define MDTYPE_MICROSOFT_V2 0x1
81#define MDTYPE_MICROSOFT 0x2
88#define CHAP_DIGEST(mdtype) \
89 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
90 ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \
91 ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
94#define CHAP_DIGEST(mdtype) \
95 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
100#define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
104#define CHAP_MDTYPE_D(digest) \
105 ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \
106 ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
107 ((digest) == CHAP_MD5)? MDTYPE_MD5: \
110#define CHAP_MDTYPE_D(digest) \
111 ((digest) == CHAP_MD5)? MDTYPE_MD5: \
117#define CHAP_CANDIGEST(mdtype, digest) \
118 ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \
119 ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
120 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
123#define CHAP_CANDIGEST(mdtype, digest) \
124 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
131struct chap_digest_type {
139 void (*generate_challenge)(ppp_pcb *pcb,
unsigned char *challenge);
140 int (*verify_response)(ppp_pcb *pcb,
int id,
const char *name,
141 const unsigned char *secret,
int secret_len,
142 const unsigned char *challenge,
const unsigned char *response,
143 char *message,
int message_space);
145 void (*make_response)(ppp_pcb *pcb,
unsigned char *response,
int id,
const char *our_name,
146 const unsigned char *challenge,
const char *secret,
int secret_len,
147 unsigned char *priv);
148 int (*check_success)(ppp_pcb *pcb,
unsigned char *pkt,
int len,
unsigned char *priv);
149 void (*handle_failure)(ppp_pcb *pcb,
unsigned char *pkt,
int len);
156typedef struct chap_client_state {
159 const struct chap_digest_type *digest;
160 unsigned char priv[64];
164typedef struct chap_server_state {
168 const struct chap_digest_type *digest;
170 int challenge_pktlen;
171 unsigned char challenge[CHAL_MAX_PKTLEN];
178extern int (*chap_verify_hook)(
char *name,
char *ourname,
int id,
179 const struct chap_digest_type *digest,
180 unsigned char *challenge,
unsigned char *response,
181 char *message,
int message_space);
186extern void chap_auth_peer(ppp_pcb *pcb,
const char *our_name,
int digest_code);
190extern void chap_auth_with_peer(ppp_pcb *pcb,
const char *our_name,
int digest_code);
193extern const struct protent chap_protent;