sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
chap-new.h
Go to the documentation of this file.
1/*
2 * chap-new.c - New CHAP implementation.
3 *
4 * Copyright (c) 2003 Paul Mackerras. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. The name(s) of the authors of this software must not be used to
14 * endorse or promote products derived from this software without
15 * prior written permission.
16 *
17 * 3. Redistributions of any form whatsoever must retain the following
18 * acknowledgment:
19 * "This product includes software developed by Paul Mackerras
20 * <paulus@samba.org>".
21 *
22 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
23 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
28 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 */
30
35#include "netif/ppp/ppp_opts.h"
36#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
37
38#ifndef CHAP_H
39#define CHAP_H
40
41#include "ppp.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/*
48 * CHAP packets begin with a standard header with code, id, len (2 bytes).
49 */
50#define CHAP_HDRLEN 4
51
52/*
53 * Values for the code field.
54 */
55#define CHAP_CHALLENGE 1
56#define CHAP_RESPONSE 2
57#define CHAP_SUCCESS 3
58#define CHAP_FAILURE 4
59
60/*
61 * CHAP digest codes.
62 */
63#define CHAP_MD5 5
64#if MSCHAP_SUPPORT
65#define CHAP_MICROSOFT 0x80
66#define CHAP_MICROSOFT_V2 0x81
67#endif /* MSCHAP_SUPPORT */
68
69/*
70 * Semi-arbitrary limits on challenge and response fields.
71 */
72#define MAX_CHALLENGE_LEN 64
73#define MAX_RESPONSE_LEN 64
74
75/*
76 * These limits apply to challenge and response packets we send.
77 * The +4 is the +1 that we actually need rounded up.
78 */
79#define CHAL_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_CHALLENGE_LEN + MAXNAMELEN)
80#define RESP_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_RESPONSE_LEN + MAXNAMELEN)
81
82/* bitmask of supported algorithms */
83#if MSCHAP_SUPPORT
84#define MDTYPE_MICROSOFT_V2 0x1
85#define MDTYPE_MICROSOFT 0x2
86#endif /* MSCHAP_SUPPORT */
87#define MDTYPE_MD5 0x4
88#define MDTYPE_NONE 0
89
90#if MSCHAP_SUPPORT
91/* Return the digest alg. ID for the most preferred digest type. */
92#define CHAP_DIGEST(mdtype) \
93 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
94 ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \
95 ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
96 0
97#else /* !MSCHAP_SUPPORT */
98#define CHAP_DIGEST(mdtype) \
99 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
100 0
101#endif /* MSCHAP_SUPPORT */
102
103/* Return the bit flag (lsb set) for our most preferred digest type. */
104#define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
105
106/* Return the bit flag for a given digest algorithm ID. */
107#if MSCHAP_SUPPORT
108#define CHAP_MDTYPE_D(digest) \
109 ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \
110 ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
111 ((digest) == CHAP_MD5)? MDTYPE_MD5: \
112 0
113#else /* !MSCHAP_SUPPORT */
114#define CHAP_MDTYPE_D(digest) \
115 ((digest) == CHAP_MD5)? MDTYPE_MD5: \
116 0
117#endif /* MSCHAP_SUPPORT */
118
119/* Can we do the requested digest? */
120#if MSCHAP_SUPPORT
121#define CHAP_CANDIGEST(mdtype, digest) \
122 ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \
123 ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
124 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
125 0
126#else /* !MSCHAP_SUPPORT */
127#define CHAP_CANDIGEST(mdtype, digest) \
128 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
129 0
130#endif /* MSCHAP_SUPPORT */
131
132/*
133 * The code for each digest type has to supply one of these.
134 */
135struct chap_digest_type {
136 int code;
137
138#if PPP_SERVER
139 /*
140 * Note: challenge and response arguments below are formatted as
141 * a length byte followed by the actual challenge/response data.
142 */
143 void (*generate_challenge)(ppp_pcb *pcb, unsigned char *challenge);
144 int (*verify_response)(ppp_pcb *pcb, int id, const char *name,
145 const unsigned char *secret, int secret_len,
146 const unsigned char *challenge, const unsigned char *response,
147 char *message, int message_space);
148#endif /* PPP_SERVER */
149 void (*make_response)(ppp_pcb *pcb, unsigned char *response, int id, const char *our_name,
150 const unsigned char *challenge, const char *secret, int secret_len,
151 unsigned char *priv);
152 int (*check_success)(ppp_pcb *pcb, unsigned char *pkt, int len, unsigned char *priv);
153 void (*handle_failure)(ppp_pcb *pcb, unsigned char *pkt, int len);
154};
155
156/*
157 * Each interface is described by chap structure.
158 */
159#if CHAP_SUPPORT
160typedef struct chap_client_state {
161 u8_t flags;
162 const char *name;
163 const struct chap_digest_type *digest;
164 unsigned char priv[64]; /* private area for digest's use */
165} chap_client_state;
166
167#if PPP_SERVER
168typedef struct chap_server_state {
169 u8_t flags;
170 u8_t id;
171 const char *name;
172 const struct chap_digest_type *digest;
173 int challenge_xmits;
174 int challenge_pktlen;
175 unsigned char challenge[CHAL_MAX_PKTLEN];
176} chap_server_state;
177#endif /* PPP_SERVER */
178#endif /* CHAP_SUPPORT */
179
180#if 0 /* UNUSED */
181/* Hook for a plugin to validate CHAP challenge */
182extern int (*chap_verify_hook)(char *name, char *ourname, int id,
183 const struct chap_digest_type *digest,
184 unsigned char *challenge, unsigned char *response,
185 char *message, int message_space);
186#endif /* UNUSED */
187
188#if PPP_SERVER
189/* Called by authentication code to start authenticating the peer. */
190extern void chap_auth_peer(ppp_pcb *pcb, const char *our_name, int digest_code);
191#endif /* PPP_SERVER */
192
193/* Called by auth. code to start authenticating us to the peer. */
194extern void chap_auth_with_peer(ppp_pcb *pcb, const char *our_name, int digest_code);
195
196/* Represents the CHAP protocol to the main pppd code */
197extern const struct protent chap_protent;
198
199#ifdef __cplusplus
200}
201#endif
202
203#endif /* CHAP_H */
204#endif /* PPP_SUPPORT && CHAP_SUPPORT */