iPXE
Data Structures | Functions | Variables
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)
 
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. More...
 
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. More...
 

Variables

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

Detailed Description

MS-CHAPv2 authentication.

Definition in file mschapv2.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __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 
)

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 269 of file mschapv2.c.

272  {
273  union mschapv2_context ctx;
274  union mschapv2_challenge_hash chash;
275  union mschapv2_password_hash phash;
276 
277  /* Zero reserved fields */
278  memset ( response, 0, sizeof ( *response ) );
279 
280  /* Copy peer challenge to response */
281  memcpy ( &response->peer, peer, sizeof ( response->peer ) );
282 
283  /* Construct challenge hash */
284  mschapv2_challenge_hash ( &ctx, challenge, peer, username, &chash );
285 
286  /* Construct expanded password hash */
287  mschapv2_password_hash ( &ctx, password, &phash );
288  mschapv2_expand_hash ( &ctx, &phash );
289 
290  /* Construct NT response */
291  mschapv2_challenge_response ( &ctx, &chash, &phash, &response->nt );
292  DBGC ( &ctx, "MSCHAPv2 challenge response:\n" );
293  DBGC_HDA ( &ctx, 0, response, sizeof ( *response ) );
294 }
MS-CHAPv2 context block.
Definition: mschapv2.c:50
MS-CHAPv2 password hash.
Definition: mschapv2.c:87
MS-CHAPv2 challenge hash.
Definition: mschapv2.c:66
#define DBGC(...)
Definition: compiler.h:505
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct mschapv2_nt_response nt
NT response.
Definition: mschapv2.h:33
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:232
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:119
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:29
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:153
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:204
void * memset(void *dest, int character, size_t len) __nonnull

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

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 
)

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 308 of file mschapv2.c.

311  {
312  struct digest_algorithm *sha1 = &sha1_algorithm;
313  union mschapv2_context ctx;
314  union mschapv2_challenge_hash chash;
315  union mschapv2_password_hash phash;
316  char tmp[3];
317  char *wtf;
318  unsigned int i;
319 
320  /* Construct hash of password hash */
321  mschapv2_password_hash ( &ctx, password, &phash );
322  mschapv2_hash_hash ( &ctx, &phash );
323 
324  /* Construct unnamed intermediate hash */
325  digest_init ( sha1, ctx.sha1 );
326  digest_update ( sha1, ctx.sha1, phash.md4, sizeof ( phash.md4 ) );
327  digest_update ( sha1, ctx.sha1, &response->nt,
328  sizeof ( response->nt ) );
329  digest_update ( sha1, ctx.sha1, mschapv2_magic1,
330  sizeof ( mschapv2_magic1 ) );
331  digest_final ( sha1, ctx.sha1, phash.sha1 );
332  DBGC ( &ctx, "MSCHAPv2 NT response:\n" );
333  DBGC_HDA ( &ctx, 0, &response->nt, sizeof ( response->nt ) );
334  DBGC ( &ctx, "MSCHAPv2 unnamed intermediate hash:\n" );
335  DBGC_HDA ( &ctx, 0, phash.sha1, sizeof ( phash.sha1 ) );
336 
337  /* Construct challenge hash */
338  mschapv2_challenge_hash ( &ctx, challenge, &response->peer,
339  username, &chash );
340 
341  /* Construct authenticator response hash */
342  digest_init ( sha1, ctx.sha1 );
343  digest_update ( sha1, ctx.sha1, phash.sha1, sizeof ( phash.sha1 ) );
344  digest_update ( sha1, ctx.sha1, chash.des, sizeof ( chash.des ) );
345  digest_update ( sha1, ctx.sha1, mschapv2_magic2,
346  sizeof ( mschapv2_magic2 ) );
347  digest_final ( sha1, ctx.sha1, phash.sha1 );
348  DBGC ( &ctx, "MSCHAPv2 authenticator response hash:\n" );
349  DBGC_HDA ( &ctx, 0, phash.sha1, sizeof ( phash.sha1 ) );
350 
351  /* Encode authenticator response hash */
352  wtf = auth->wtf;
353  *(wtf++) = 'S';
354  *(wtf++) = '=';
355  DBGC ( &ctx, "MSCHAPv2 authenticator response: S=" );
356  for ( i = 0 ; i < sizeof ( phash.sha1 ) ; i++ ) {
357  snprintf ( tmp, sizeof ( tmp ), "%02X", phash.sha1[i] );
358  *(wtf++) = tmp[0];
359  *(wtf++) = tmp[1];
360  DBGC ( &ctx, "%s", tmp );
361  }
362  DBGC ( &ctx, "\n" );
363 }
MS-CHAPv2 context block.
Definition: mschapv2.c:50
static const char mschapv2_magic1[39]
MS-CHAPv2 magic constant 1.
Definition: mschapv2.c:99
MS-CHAPv2 password hash.
Definition: mschapv2.c:87
static void mschapv2_hash_hash(union mschapv2_context *ctx, union mschapv2_password_hash *phash)
Hash the MS-CHAPv2 password hash.
Definition: mschapv2.c:183
MS-CHAPv2 challenge hash.
Definition: mschapv2.c:66
#define DBGC(...)
Definition: compiler.h:505
uint8_t sha1[SHA1_DIGEST_SIZE]
SHA-1 digest.
Definition: mschapv2.c:91
static void void * auth
Definition: crypto.h:264
unsigned long tmp
Definition: linux_pci.h:53
char wtf[42]
Authenticator response string.
Definition: mschapv2.h:18
#define DBGC_HDA(...)
Definition: compiler.h:506
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct mschapv2_nt_response nt
NT response.
Definition: mschapv2.h:33
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:119
static const char mschapv2_magic2[41]
MS-CHAPv2 magic constant 2.
Definition: mschapv2.c:103
A message digest algorithm.
Definition: crypto.h:17
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:29
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:153
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
Definition: sha1.c:257

References auth, ctx, DBGC, DBGC_HDA, mschapv2_challenge_hash::des, mschapv2_password_hash::md4, mschapv2_challenge_hash(), mschapv2_hash_hash(), mschapv2_magic1, mschapv2_magic2, mschapv2_password_hash(), mschapv2_response::nt, mschapv2_response::peer, mschapv2_password_hash::sha1, sha1_algorithm, snprintf(), tmp, and wtf.

Referenced by mschapv2_okx().

Variable Documentation

◆ byte

Raw bytes.

Definition at line 12 of file mschapv2.h.

◆ block

uint16_t block

◆ peer

struct mschapv2_challenge peer

◆ reserved

uint8_t reserved[8]

Reserved, must be zero.

Definition at line 14 of file mschapv2.h.

◆ nt

NT response.

Definition at line 16 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 18 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 18 of file mschapv2.h.

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