iPXE
mschapv2.h File Reference

MS-CHAPv2 authentication. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  mschapv2_challenge
 An MS-CHAPv2 challenge. More...
struct  mschapv2_nt_response
 An MS-CHAPv2 NT response. More...
struct  mschapv2_response
 An MS-CHAPv2 challenge response. More...
struct  mschapv2_auth
 An MS-CHAPv2 authenticator response. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
struct mschapv2_challenge __attribute__ ((packed))
void mschapv2_response (const char *username, const char *password, const struct mschapv2_challenge *challenge, const struct mschapv2_challenge *peer, struct mschapv2_response *response)
 Calculate MS-CHAPv2 challenge response.
void mschapv2_auth (const char *username, const char *password, const struct mschapv2_challenge *challenge, const struct mschapv2_response *response, struct mschapv2_auth *auth)
 Calculate MS-CHAPv2 authenticator response.

Variables

uint8_t byte [16]
 Raw bytes.
uint8_t block [3][8]
 DES-encrypted blocks.
struct mschapv2_challenge peer
 Peer challenge.
uint8_t reserved [8]
 Reserved, must be zero.
struct mschapv2_nt_response nt
 NT response.
uint8_t flags
 Flags, must be zero.
char wtf [42]
 Authenticator response string.

Detailed Description

MS-CHAPv2 authentication.

Definition in file mschapv2.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ __attribute__()

struct mschapv2_challenge __attribute__ ( (packed) )

◆ mschapv2_response()

void mschapv2_response ( const char * username,
const char * password,
const struct mschapv2_challenge * challenge,
const struct mschapv2_challenge * peer,
struct mschapv2_response * response )
extern

Calculate MS-CHAPv2 challenge response.

Parameters
usernameUser name (or NULL to use empty string)
passwordPassword (or NULL to use empty string)
challengeAuthenticator challenge
peerPeer challenge
responseChallenge response to fill in

This is essentially the GenerateNTResponse() function as documented in RFC 2759 section 8.1.

Definition at line 270 of file mschapv2.c.

273 {
274 union mschapv2_context ctx;
275 union mschapv2_challenge_hash chash;
276 union mschapv2_password_hash phash;
277
278 /* Zero reserved fields */
279 memset ( response, 0, sizeof ( *response ) );
280
281 /* Copy peer challenge to response */
282 memcpy ( &response->peer, peer, sizeof ( response->peer ) );
283
284 /* Construct challenge hash */
285 mschapv2_challenge_hash ( &ctx, challenge, peer, username, &chash );
286
287 /* Construct expanded password hash */
288 mschapv2_password_hash ( &ctx, password, &phash );
289 mschapv2_expand_hash ( &ctx, &phash );
290
291 /* Construct NT response */
292 mschapv2_challenge_response ( &ctx, &chash, &phash, &response->nt );
293 DBGC ( &ctx, "MSCHAPv2 challenge response:\n" );
294 DBGC_HDA ( &ctx, 0, response, sizeof ( *response ) );
295}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
#define DBGC(...)
Definition compiler.h:505
#define DBGC_HDA(...)
Definition compiler.h:506
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
static struct dynamic_item username
Definition login_ui.c:36
static struct dynamic_item password
Definition login_ui.c:37
static void mschapv2_challenge_response(union mschapv2_context *ctx, const union mschapv2_challenge_hash *chash, const union mschapv2_password_hash *phash, struct mschapv2_nt_response *nt)
Calculate MS-CHAPv2 challenge response.
Definition mschapv2.c:233
static void mschapv2_expand_hash(union mschapv2_context *ctx, union mschapv2_password_hash *phash)
Expand MS-CHAPv2 password hash by inserting DES dummy parity bits.
Definition mschapv2.c:205
static void mschapv2_challenge_hash(union mschapv2_context *ctx, const struct mschapv2_challenge *challenge, const struct mschapv2_challenge *peer, const char *username, union mschapv2_challenge_hash *chash)
Calculate MS-CHAPv2 challenge hash.
Definition mschapv2.c:120
static void mschapv2_password_hash(union mschapv2_context *ctx, const char *password, union mschapv2_password_hash *phash)
Calculate MS-CHAPv2 password hash.
Definition mschapv2.c:154
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:30
struct mschapv2_nt_response nt
NT response.
Definition mschapv2.h:34
MS-CHAPv2 challenge hash.
Definition mschapv2.c:67
MS-CHAPv2 context block.
Definition mschapv2.c:51
MS-CHAPv2 password hash.
Definition mschapv2.c:88

References ctx, DBGC, DBGC_HDA, memcpy(), memset(), mschapv2_challenge_hash(), mschapv2_challenge_response(), mschapv2_expand_hash(), mschapv2_password_hash(), mschapv2_response::nt, password, mschapv2_response::peer, peer, and username.

Referenced by eap_rx_mschapv2_request(), and mschapv2_okx().

◆ mschapv2_auth()

void mschapv2_auth ( const char * username,
const char * password,
const struct mschapv2_challenge * challenge,
const struct mschapv2_response * response,
struct mschapv2_auth * auth )
extern

Calculate MS-CHAPv2 authenticator response.

Parameters
usernameUser name (or NULL to use empty string)
passwordPassword (or NULL to use empty string)
challengeAuthenticator challenge
responseChallenge response
authAuthenticator response to fill in

This is essentially the GenerateAuthenticatorResponse() function as documented in RFC 2759 section 8.7.

Definition at line 309 of file mschapv2.c.

312 {
313 struct digest_algorithm *sha1 = &sha1_algorithm;
314 union mschapv2_context ctx;
315 union mschapv2_challenge_hash chash;
316 union mschapv2_password_hash phash;
317 char tmp[3];
318 char *wtf;
319 unsigned int i;
320
321 /* Construct hash of password hash */
322 mschapv2_password_hash ( &ctx, password, &phash );
323 mschapv2_hash_hash ( &ctx, &phash );
324
325 /* Construct unnamed intermediate hash */
326 digest_init ( sha1, ctx.sha1 );
327 digest_update ( sha1, ctx.sha1, phash.md4, sizeof ( phash.md4 ) );
328 digest_update ( sha1, ctx.sha1, &response->nt,
329 sizeof ( response->nt ) );
331 sizeof ( mschapv2_magic1 ) );
332 digest_final ( sha1, ctx.sha1, phash.sha1 );
333 DBGC ( &ctx, "MSCHAPv2 NT response:\n" );
334 DBGC_HDA ( &ctx, 0, &response->nt, sizeof ( response->nt ) );
335 DBGC ( &ctx, "MSCHAPv2 unnamed intermediate hash:\n" );
336 DBGC_HDA ( &ctx, 0, phash.sha1, sizeof ( phash.sha1 ) );
337
338 /* Construct challenge hash */
339 mschapv2_challenge_hash ( &ctx, challenge, &response->peer,
340 username, &chash );
341
342 /* Construct authenticator response hash */
343 digest_init ( sha1, ctx.sha1 );
344 digest_update ( sha1, ctx.sha1, phash.sha1, sizeof ( phash.sha1 ) );
345 digest_update ( sha1, ctx.sha1, chash.des, sizeof ( chash.des ) );
347 sizeof ( mschapv2_magic2 ) );
348 digest_final ( sha1, ctx.sha1, phash.sha1 );
349 DBGC ( &ctx, "MSCHAPv2 authenticator response hash:\n" );
350 DBGC_HDA ( &ctx, 0, phash.sha1, sizeof ( phash.sha1 ) );
351
352 /* Encode authenticator response hash */
353 wtf = auth->wtf;
354 *(wtf++) = 'S';
355 *(wtf++) = '=';
356 DBGC ( &ctx, "MSCHAPv2 authenticator response: S=" );
357 for ( i = 0 ; i < sizeof ( phash.sha1 ) ; i++ ) {
358 snprintf ( tmp, sizeof ( tmp ), "%02X", phash.sha1[i] );
359 *(wtf++) = tmp[0];
360 *(wtf++) = tmp[1];
361 DBGC ( &ctx, "%s", tmp );
362 }
363 DBGC ( &ctx, "\n" );
364}
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition crypto.h:219
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition crypto.h:230
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition crypto.h:224
unsigned long tmp
Definition linux_pci.h:65
static void mschapv2_hash_hash(union mschapv2_context *ctx, union mschapv2_password_hash *phash)
Hash the MS-CHAPv2 password hash.
Definition mschapv2.c:184
static const char mschapv2_magic1[39]
MS-CHAPv2 magic constant 1.
Definition mschapv2.c:100
static const char mschapv2_magic2[41]
MS-CHAPv2 magic constant 2.
Definition mschapv2.c:104
char wtf[42]
Authenticator response string.
Definition mschapv2.h:7
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
Definition sha1.c:258
A message digest algorithm.
Definition crypto.h:19
char wtf[42]
Authenticator response string.
Definition mschapv2.h:48
uint8_t sha1[SHA1_DIGEST_SIZE]
SHA-1 digest.
Definition mschapv2.c:92
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References ctx, DBGC, DBGC_HDA, mschapv2_challenge_hash::des, digest_final(), digest_init(), digest_update(), mschapv2_password_hash::md4, mschapv2_challenge_hash(), mschapv2_hash_hash(), mschapv2_magic1, mschapv2_magic2, mschapv2_password_hash(), mschapv2_response::nt, password, mschapv2_response::peer, mschapv2_password_hash::sha1, sha1_algorithm, snprintf(), tmp, username, mschapv2_auth::wtf, and wtf.

Referenced by mschapv2_okx().

Variable Documentation

◆ byte

Raw bytes.

Definition at line 1 of file mschapv2.h.

◆ block

◆ peer

◆ reserved

uint8_t reserved[8]

Reserved, must be zero.

Definition at line 3 of file mschapv2.h.

◆ nt

NT response.

Definition at line 5 of file mschapv2.h.

Referenced by mschapv2_challenge_response(), ntlm_authenticate(), ntlm_authenticate_okx(), and ntlm_response().

◆ flags

uint8_t flags

Flags, must be zero.

Definition at line 7 of file mschapv2.h.

◆ wtf

char wtf[42]

Authenticator response string.

This is an unterminated 42-byte string of the form "S=<auth_string>" where <auth_string> is the upper-cased hexadecimal encoding of the actual authenticator response value. Joy.

Definition at line 7 of file mschapv2.h.

Referenced by efi_driver_controller_name(), efi_driver_name(), efi_driver_name(), efi_driver_name2(), efi_veto_find(), and mschapv2_auth().