ike_eap_mschapv2.h
Go to the documentation of this file.
1 /**
2  * @file ike_eap_mschapv2.h
3  * @brief EAP MS-CHAP-V2 authentication method
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneIPSEC Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.8
29  **/
30 
31 #ifndef _IKE_EAP_MSCHAPV2_H
32 #define _IKE_EAP_MSCHAPV2_H
33 
34 //Dependencies
35 #include "ike/ike.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /**
44  * @brief MS-CHAP-V2 opcodes
45  **/
46 
47 typedef enum
48 {
53  IKE_EAP_MSCHAPV2_CODE_FAILURE = 4 ///<Failure
55 
56 
57 //CC-RX, CodeWarrior or Win32 compiler?
58 #if defined(__CCRX__)
59  #pragma pack
60 #elif defined(__CWCC__) || defined(_WIN32)
61  #pragma pack(push, 1)
62 #endif
63 
64 
65 /**
66  * @brief EAP MS-CHAP-V2 packet
67  **/
68 
70 {
71  uint8_t code; //0
72  uint8_t identifier; //1
73  uint16_t length; //2-3
74  uint8_t type; //4
75  uint8_t opcode; //5
77 
78 
79 /**
80  * @brief EAP MS-CHAP-V2 Challenge packet
81  **/
82 
83 typedef __packed_struct
84 {
85  uint8_t code; //0
86  uint8_t identifier; //1
87  uint16_t length; //2-3
88  uint8_t type; //4
89  uint8_t opcode; //5
90  uint8_t mschapv2Id; //6
91  uint16_t msLength; //7-8
92  uint8_t valueSize; //9
93  uint8_t challenge[16]; //10-25
94  uint8_t name[]; //26
96 
97 
98 /**
99  * @brief EAP MS-CHAP-V2 Response packet
100  **/
101 
102 typedef __packed_struct
103 {
104  uint8_t code; //0
105  uint8_t identifier; //1
106  uint16_t length; //2-3
107  uint8_t type; //4
108  uint8_t opcode; //5
109  uint8_t mschapv2Id; //6
110  uint16_t msLength; //7-8
111  uint8_t valueSize; //9
112  uint8_t peerChallenge[16]; //10-25
113  uint8_t reserved[8]; //26-33
114  uint8_t ntResponse[24]; //34-57
115  uint8_t flags; //58
116  uint8_t name[]; //59
118 
119 
120 /**
121  * @brief EAP MS-CHAP-V2 Success Request packet
122  **/
123 
124 typedef __packed_struct
125 {
126  uint8_t code; //0
127  uint8_t identifier; //1
128  uint16_t length; //2-3
129  uint8_t type; //4
130  uint8_t opcode; //5
131  uint8_t mschapv2Id; //6
132  uint16_t msLength; //7-8
133  uint8_t message[]; //9
135 
136 
137 /**
138  * @brief EAP MS-CHAP-V2 Success Response packet
139  **/
140 
141 typedef __packed_struct
142 {
143  uint8_t code; //0
144  uint8_t identifier; //1
145  uint16_t length; //2-3
146  uint8_t type; //4
147  uint8_t opcode; //5
149 
150 
151 /**
152  * @brief EAP MS-CHAP-V2 Failure Request packet
153  **/
154 
155 typedef __packed_struct
156 {
157  uint8_t code; //0
158  uint8_t identifier; //1
159  uint16_t length; //2-3
160  uint8_t type; //4
161  uint8_t opcode; //5
162  uint8_t mschapv2Id; //6
163  uint16_t msLength; //7-8
164  uint8_t message[]; //9
166 
167 
168 /**
169  * @brief EAP MS-CHAP-V2 Failure Response packet
170  **/
171 
172 typedef __packed_struct
173 {
174  uint8_t code; //0
175  uint8_t identifier; //1
176  uint16_t length; //2-3
177  uint8_t type; //4
178  uint8_t opcode; //5
180 
181 
182 /**
183  * @brief EAP MS-CHAP-V2 Change-Password packet
184  **/
185 
186 typedef __packed_struct
187 {
188  uint8_t code; //0
189  uint8_t identifier; //1
190  uint16_t length; //2-3
191  uint8_t type; //4
192  uint8_t opcode; //5
193  uint8_t mschapv2Id; //6
194  uint16_t msLength; //7-8
195  uint8_t data[]; //9
197 
198 
199 //CC-RX, CodeWarrior or Win32 compiler?
200 #if defined(__CCRX__)
201  #pragma unpack
202 #elif defined(__CWCC__) || defined(_WIN32)
203  #pragma pack(pop)
204 #endif
205 
206 //EAP MS-CHAP-V2 related functions
208  const IkeEapMschapv2Packet *request, size_t length);
209 
211  const IkeEapMschapv2Challenge *challenge, size_t length);
212 
214  const IkeEapMschapv2SuccessRequest *request, size_t length);
215 
217  const IkeEapMschapv2FailureRequest *request, size_t length);
218 
220  size_t *written);
221 
223  size_t *written);
224 
226  size_t *written);
227 
228 void ikeEapMschapv2GenerateNtResponse(const uint8_t *authChallenge,
229  const uint8_t *peerChallenge, const char_t *username,
230  const char_t *password, uint8_t *response);
231 
232 void ikeEapMschapv2ChallengeHash(const uint8_t *peerChallenge,
233  const uint8_t *authChallenge, const char_t *username, uint8_t *challenge);
234 
235 void ikeEapMschapv2NtPasswordHash(const char_t *password, uint8_t *passwordHash);
236 
237 void ikeEapMschapv2HashNtPasswordHash(const uint8_t *passwordHash,
238  uint8_t *passwordHashHash);
239 
240 void ikeEapMschapv2ChallengeResponse(const uint8_t *challenge,
241  const uint8_t *passwordHash, uint8_t *response);
242 
243 void ikeEapMschapv2GenerateAuthResponse(const char_t *password,
244  const uint8_t *ntResponse, const uint8_t *peerChallenge,
245  const uint8_t *authChallenge, const char_t *username, uint8_t *authResponse);
246 
248  const uint8_t *ntResponse, const uint8_t *peerChallenge,
249  const uint8_t *authChallenge, const char_t *username,
250  const uint8_t *receivedResponse);
251 
253  const uint8_t *ntResponse, uint8_t *masterSessionKey);
254 
255 void ikeEapMschapv2GetMasterKey(const uint8_t *passwordHashHash,
256  const uint8_t *ntResponse, uint8_t *masterKey);
257 
258 void ikeEapMschapv2GetAsymmetricStartKey(const uint8_t *masterKey,
259  uint8_t *sessionKey, size_t sessionKeyLen, bool_t isSend);
260 
261 //C++ guard
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif
error_t ikeFormatEapMschapv2FailureResponse(IkeSaEntry *sa, uint8_t *p, size_t *written)
Format EAP MS-CHAP-V2 Failure Response packet.
uint8_t code
Definition: coap_common.h:179
int bool_t
Definition: compiler_port.h:63
@ IKE_EAP_MSCHAPV2_CODE_SUCCESS
Success.
error_t ikeProcessEapMschapv2SuccessRequest(IkeSaEntry *sa, const IkeEapMschapv2SuccessRequest *request, size_t length)
Process EAP MS-CHAP-V2 Success Request packet.
uint8_t p
Definition: ndp.h:300
uint16_t msLength
uint8_t challenge[16]
IkeEapMschapv2FailureRequest
IkeEapMschapv2Challenge
error_t ikeProcessEapMschapv2Request(IkeSaEntry *sa, const IkeEapMschapv2Packet *request, size_t length)
Process EAP MS-CHAP-V2 request.
@ IKE_EAP_MSCHAPV2_CODE_INVALID
uint8_t message[]
typedef __packed_struct
EAP MS-CHAP-V2 packet.
error_t ikeProcessEapMschapv2Challenge(IkeSaEntry *sa, const IkeEapMschapv2Challenge *challenge, size_t length)
Process EAP MS-CHAP-V2 Challenge packet.
void ikeEapMschapv2GenerateMasterSessionKey(const char_t *password, const uint8_t *ntResponse, uint8_t *masterSessionKey)
Generate master session key.
uint16_t length
void ikeEapMschapv2GetAsymmetricStartKey(const uint8_t *masterKey, uint8_t *sessionKey, size_t sessionKeyLen, bool_t isSend)
GetAsymmetricStartKey routine.
error_t
Error codes.
Definition: error.h:43
void ikeEapMschapv2ChallengeResponse(const uint8_t *challenge, const uint8_t *passwordHash, uint8_t *response)
ChallengeResponse routine.
uint8_t identifier
uint8_t flags
void ikeEapMschapv2GenerateAuthResponse(const char_t *password, const uint8_t *ntResponse, const uint8_t *peerChallenge, const uint8_t *authChallenge, const char_t *username, uint8_t *authResponse)
GenerateAuthenticatorResponse routine.
uint8_t valueSize
uint8_t opcode
uint8_t type
@ IKE_EAP_MSCHAPV2_CODE_CHALLENGE
Challenge.
void ikeEapMschapv2NtPasswordHash(const char_t *password, uint8_t *passwordHash)
NtPasswordHash routine.
error_t ikeFormatEapMschapv2Response(IkeSaEntry *sa, uint8_t *p, size_t *written)
Format EAP MS-CHAP-V2 Response packet.
error_t ikeFormatEapMschapv2SuccessResponse(IkeSaEntry *sa, uint8_t *p, size_t *written)
Format EAP MS-CHAP-V2 Success Response packet.
IkeEapMschapv2ChangePassword
IkeEapMschapv2Response
IKEv2 (Internet Key Exchange Protocol)
error_t ikeProcessEapMschapv2FailureRequest(IkeSaEntry *sa, const IkeEapMschapv2FailureRequest *request, size_t length)
Process EAP MS-CHAP-V2 Failure Request packet.
uint8_t mschapv2Id
uint8_t peerChallenge[16]
char char_t
Definition: compiler_port.h:55
#define IkeSaEntry
Definition: ike.h:887
IkeEapMschapv2Code
MS-CHAP-V2 opcodes.
void ikeEapMschapv2GetMasterKey(const uint8_t *passwordHashHash, const uint8_t *ntResponse, uint8_t *masterKey)
GetMasterKey routine.
IkeEapMschapv2SuccessResponse
IkeEapMschapv2Packet
uint8_t ntResponse[24]
IkeEapMschapv2FailureResponse
@ IKE_EAP_MSCHAPV2_CODE_RESPONSE
Response.
uint8_t data[]
uint8_t name[]
void ikeEapMschapv2HashNtPasswordHash(const uint8_t *passwordHash, uint8_t *passwordHashHash)
HashNtPasswordHash routine.
void ikeEapMschapv2GenerateNtResponse(const uint8_t *authChallenge, const uint8_t *peerChallenge, const char_t *username, const char_t *password, uint8_t *response)
GenerateNTResponse routine.
void ikeEapMschapv2ChallengeHash(const uint8_t *peerChallenge, const uint8_t *authChallenge, const char_t *username, uint8_t *challenge)
ChallengeHash routine.
IkeEapMschapv2SuccessRequest
@ IKE_EAP_MSCHAPV2_CODE_FAILURE
Failure.
bool_t ikeEapMschapv2CheckAuthResponse(const char_t *password, const uint8_t *ntResponse, const uint8_t *peerChallenge, const uint8_t *authChallenge, const char_t *username, const uint8_t *receivedResponse)
CheckAuthenticatorResponse routine.
uint8_t reserved[8]