iPXE
chap.h File Reference

CHAP protocol. More...

#include <stdint.h>
#include <ipxe/md5.h>

Go to the source code of this file.

Data Structures

struct  chap_response
 A CHAP response. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int chap_init (struct chap_response *chap, struct digest_algorithm *digest)
 Initialise CHAP challenge/response.
void chap_update (struct chap_response *chap, const void *data, size_t len)
 Add data to the CHAP challenge.
void chap_respond (struct chap_response *chap)
 Respond to the CHAP challenge.
void chap_finish (struct chap_response *chap)
 Free resources used by a CHAP response.
static void chap_set_identifier (struct chap_response *chap, unsigned int identifier)
 Add identifier data to the CHAP challenge.

Detailed Description

CHAP protocol.

Definition in file chap.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ chap_init()

int chap_init ( struct chap_response * chap,
struct digest_algorithm * digest )
extern

Initialise CHAP challenge/response.

Parameters
chapCHAP challenge/response
digestDigest algorithm to use
Return values
rcReturn status code

Initialises a CHAP challenge/response structure. This routine allocates memory, and so may fail. The allocated memory must eventually be freed by a call to chap_finish().

Definition at line 52 of file chap.c.

53 {
54 size_t state_len;
55 void *state;
56
57 assert ( chap->digest == NULL );
58 assert ( chap->digest_context == NULL );
59 assert ( chap->response == NULL );
60
61 DBG ( "CHAP %p initialising with %s digest\n", chap, digest->name );
62
63 state_len = ( digest->ctxsize + digest->digestsize );
64 state = malloc ( state_len );
65 if ( ! state ) {
66 DBG ( "CHAP %p could not allocate %zd bytes for state\n",
67 chap, state_len );
68 return -ENOMEM;
69 }
70
71 chap->digest = digest;
72 chap->digest_context = state;
73 chap->response = ( state + digest->ctxsize );
74 chap->response_len = digest->digestsize;
75 digest_init ( chap->digest, chap->digest_context );
76 return 0;
77}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint8_t state
State.
Definition eth_slow.h:36
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define ENOMEM
Not enough space.
Definition errno.h:535
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition crypto.h:219
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
uint8_t * digest_context
Context used by the digest algorithm.
Definition chap.h:23
uint8_t * response
CHAP response.
Definition chap.h:25
struct digest_algorithm * digest
Digest algorithm used for the response.
Definition chap.h:21
size_t response_len
Length of CHAP response.
Definition chap.h:27
size_t digestsize
Digest size.
Definition crypto.h:27
size_t ctxsize
Context size.
Definition crypto.h:23
const char * name
Algorithm name.
Definition crypto.h:21

References assert, digest_algorithm::ctxsize, DBG, chap_response::digest, chap_response::digest_context, digest_init(), digest_algorithm::digestsize, ENOMEM, malloc(), digest_algorithm::name, NULL, chap_response::response, chap_response::response_len, and state.

Referenced by eap_rx_md5(), iscsi_handle_chap_i_value(), and iscsi_handle_chap_r_value().

◆ chap_update()

void chap_update ( struct chap_response * chap,
const void * data,
size_t len )
extern

Add data to the CHAP challenge.

Parameters
chapCHAP response
dataData to add
lenLength of data to add

Definition at line 86 of file chap.c.

87 {
88 assert ( chap->digest != NULL );
89 assert ( chap->digest_context != NULL );
90
91 if ( ! chap->digest )
92 return;
93
94 digest_update ( chap->digest, chap->digest_context, data, len );
95}
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition crypto.h:224

References assert, data, chap_response::digest, chap_response::digest_context, digest_update(), len, and NULL.

Referenced by chap_set_identifier(), eap_rx_md5(), iscsi_handle_chap_c_value(), iscsi_handle_chap_i_value(), and iscsi_handle_chap_r_value().

◆ chap_respond()

void chap_respond ( struct chap_response * chap)
extern

Respond to the CHAP challenge.

Parameters
chapCHAP response

Calculates the final CHAP response value, and places it in chap->response, with a length of chap->response_len.

Definition at line 105 of file chap.c.

105 {
106 assert ( chap->digest != NULL );
107 assert ( chap->digest_context != NULL );
108 assert ( chap->response != NULL );
109
110 DBG ( "CHAP %p responding to challenge\n", chap );
111
112 if ( ! chap->digest )
113 return;
114
115 digest_final ( chap->digest, chap->digest_context, chap->response );
116}
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition crypto.h:230

References assert, DBG, chap_response::digest, chap_response::digest_context, digest_final(), NULL, and chap_response::response.

Referenced by eap_rx_md5(), iscsi_handle_chap_c_value(), and iscsi_handle_chap_r_value().

◆ chap_finish()

void chap_finish ( struct chap_response * chap)
extern

Free resources used by a CHAP response.

Parameters
chapCHAP response

Definition at line 123 of file chap.c.

123 {
124 void *state = chap->digest_context;
125
126 DBG ( "CHAP %p finished\n", chap );
127
128 free ( state );
129 memset ( chap, 0, sizeof ( *chap ) );
130}
void * memset(void *dest, int character, size_t len) __nonnull
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55

References DBG, chap_response::digest_context, free, memset(), and state.

Referenced by eap_rx_md5(), iscsi_close_connection(), iscsi_free(), iscsi_handle_chap_i_value(), iscsi_handle_chap_r_value(), and iscsi_login_request_done().

◆ chap_set_identifier()

void chap_set_identifier ( struct chap_response * chap,
unsigned int identifier )
inlinestatic

Add identifier data to the CHAP challenge.

Parameters
chapCHAP response
identifierCHAP identifier

The CHAP identifier is the first byte of the CHAP challenge. This function is a notational convenience for calling chap_update() for the identifier byte.

Definition at line 47 of file chap.h.

48 {
49 uint8_t ident_byte = identifier;
50
51 chap_update ( chap, &ident_byte, sizeof ( ident_byte ) );
52}
unsigned char uint8_t
Definition stdint.h:10
void chap_update(struct chap_response *chap, const void *data, size_t len)
Add data to the CHAP challenge.
Definition chap.c:86

References chap_update().

Referenced by eap_rx_md5(), iscsi_handle_chap_i_value(), and iscsi_handle_chap_r_value().