iPXE
Data Structures | Macros | Functions | Variables
mschapv2_test.c File Reference

MS-CHAPv2 authentication self-tests. More...

#include <stdlib.h>
#include <string.h>
#include <ipxe/mschapv2.h>
#include <ipxe/test.h>

Go to the source code of this file.

Data Structures

struct  mschapv2_test
 An MS-CHAPv2 test. More...
 

Macros

#define DATA(...)   { __VA_ARGS__ }
 Define inline data. More...
 
#define MSCHAPV2_TEST(name, USERNAME, PASSWORD, CHALLENGE, PEER, RESPONSE, AUTH)
 Define an MS-CHAPv2 test. More...
 
#define mschapv2_ok(test)   mschapv2_okx ( test, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 MSCHAPV2_TEST (rfc2759_test, "User", "clientPass", DATA(0x5b, 0x5d, 0x7c, 0x7d, 0x7b, 0x3f, 0x2f, 0x3e, 0x3c, 0x2c, 0x60, 0x21, 0x32, 0x26, 0x26, 0x28), DATA(0x21, 0x40, 0x23, 0x24, 0x25, 0x5e, 0x26, 0x2a, 0x28, 0x29, 0x5f, 0x2b, 0x3a, 0x33, 0x7c, 0x7e), DATA(0x21, 0x40, 0x23, 0x24, 0x25, 0x5e, 0x26, 0x2a, 0x28, 0x29, 0x5f, 0x2b, 0x3a, 0x33, 0x7c, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x30, 0x9e, 0xcd, 0x8d, 0x70, 0x8b, 0x5e, 0xa0, 0x8f, 0xaa, 0x39, 0x81, 0xcd, 0x83, 0x54, 0x42, 0x33, 0x11, 0x4a, 0x3d, 0x85, 0xd6, 0xdf, 0x00), "S=407A5589115FD0D6209F510FE9C04566932CDA56")
 RFC 2759 section 9.2 test case. More...
 
static void mschapv2_okx (struct mschapv2_test *test, const char *file, unsigned int line)
 Report an MS-CHAPv2 test result. More...
 
static void mschapv2_test_exec (void)
 Perform MS-CHAPv2 self-test. More...
 

Variables

struct self_test mschapv2_test __self_test
 MS-CHAPv2 self-test. More...
 

Detailed Description

MS-CHAPv2 authentication self-tests.

Definition in file mschapv2_test.c.

Macro Definition Documentation

◆ DATA

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 57 of file mschapv2_test.c.

◆ MSCHAPV2_TEST

#define MSCHAPV2_TEST (   name,
  USERNAME,
  PASSWORD,
  CHALLENGE,
  PEER,
  RESPONSE,
  AUTH 
)
Value:
static const struct mschapv2_challenge name ## _challenge = { \
.byte = CHALLENGE, \
}; \
static const struct mschapv2_challenge name ## _peer = { \
.byte = PEER, \
}; \
static const union { \
struct mschapv2_response response; \
uint8_t byte[ sizeof ( struct mschapv2_response ) ]; \
} name ## _response = { \
.byte = RESPONSE, \
}; \
static const union { \
struct mschapv2_auth auth; \
uint8_t byte[ sizeof ( struct mschapv2_auth ) ]; \
} name ## _auth = { \
.byte = AUTH, \
}; \
static struct mschapv2_test name = { \
.username = USERNAME, \
.password = PASSWORD, \
.challenge = &name ## _challenge, \
.peer = &name ## _peer, \
.response = &name ## _response.response, \
.auth = &name ## _auth.auth, \
};
#define AUTH(...)
Define inline authentication tag.
Definition: cipher_test.h:60
const char * name
Definition: ath9k_hw.c:1984
static void void * auth
Definition: crypto.h:264
An MS-CHAPv2 challenge.
Definition: mschapv2.h:15
An MS-CHAPv2 challenge response.
Definition: mschapv2.h:27
An MS-CHAPv2 test.
Definition: mschapv2_test.c:41
An MS-CHAPv2 authenticator response.
Definition: mschapv2.h:39

Define an MS-CHAPv2 test.

Definition at line 60 of file mschapv2_test.c.

◆ mschapv2_ok

#define mschapv2_ok (   test)    mschapv2_okx ( test, __FILE__, __LINE__ )

Definition at line 128 of file mschapv2_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ MSCHAPV2_TEST()

MSCHAPV2_TEST ( rfc2759_test  ,
"User"  ,
"clientPass"  ,
DATA(0x5b, 0x5d, 0x7c, 0x7d, 0x7b, 0x3f, 0x2f, 0x3e, 0x3c, 0x2c, 0x60, 0x21, 0x32, 0x26, 0x26, 0x28)  ,
DATA(0x21, 0x40, 0x23, 0x24, 0x25, 0x5e, 0x26, 0x2a, 0x28, 0x29, 0x5f, 0x2b, 0x3a, 0x33, 0x7c, 0x7e)  ,
DATA(0x21, 0x40, 0x23, 0x24, 0x25, 0x5e, 0x26, 0x2a, 0x28, 0x29, 0x5f, 0x2b, 0x3a, 0x33, 0x7c, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x30, 0x9e, 0xcd, 0x8d, 0x70, 0x8b, 0x5e, 0xa0, 0x8f, 0xaa, 0x39, 0x81, 0xcd, 0x83, 0x54, 0x42, 0x33, 0x11, 0x4a, 0x3d, 0x85, 0xd6, 0xdf, 0x00)   
)

RFC 2759 section 9.2 test case.

◆ mschapv2_okx()

static void mschapv2_okx ( struct mschapv2_test test,
const char *  file,
unsigned int  line 
)
static

Report an MS-CHAPv2 test result.

Parameters
testAuthentication test
fileTest code file
lineTest code line

Definition at line 112 of file mschapv2_test.c.

113  {
114  struct mschapv2_response response;
115  struct mschapv2_auth auth;
116 
117  /* Compute challenge response */
118  mschapv2_response ( test->username, test->password, test->challenge,
119  test->peer, &response );
120  okx ( memcmp ( &response, test->response, sizeof ( response ) ) == 0,
121  file, line );
122 
123  /* Compute authenticator response */
124  mschapv2_auth ( test->username, test->password, test->challenge,
125  test->response, &auth );
126  okx ( memcmp ( &auth, test->auth, sizeof ( auth ) ) == 0, file, line );
127 }
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.
Definition: mschapv2.c:269
static void void * auth
Definition: crypto.h:264
#define okx(success, file, line)
Report test result.
Definition: test.h:44
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.
Definition: mschapv2.c:308
An MS-CHAPv2 challenge response.
Definition: mschapv2.h:27
An MS-CHAPv2 authenticator response.
Definition: mschapv2.h:39
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
static int test
Definition: epic100.c:73

References auth, memcmp(), mschapv2_auth(), mschapv2_response(), okx, and test.

◆ mschapv2_test_exec()

static void mschapv2_test_exec ( void  )
static

Perform MS-CHAPv2 self-test.

Definition at line 135 of file mschapv2_test.c.

135  {
136 
137  mschapv2_ok ( &rfc2759_test );
138 }
#define mschapv2_ok(test)

References mschapv2_ok.

Variable Documentation

◆ __self_test

struct self_test mschapv2_test __self_test
Initial value:
= {
.name = "mschapv2",
}
static void mschapv2_test_exec(void)
Perform MS-CHAPv2 self-test.

MS-CHAPv2 self-test.

Definition at line 141 of file mschapv2_test.c.