iPXE
Data Structures | Functions
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)
 
int chap_init (struct chap_response *chap, struct digest_algorithm *digest)
 Initialise CHAP challenge/response. More...
 
void chap_update (struct chap_response *chap, const void *data, size_t len)
 Add data to the CHAP challenge. More...
 
void chap_respond (struct chap_response *chap)
 Respond to the CHAP challenge. More...
 
void chap_finish (struct chap_response *chap)
 Free resources used by a CHAP response. More...
 
static void chap_set_identifier (struct chap_response *chap, unsigned int identifier)
 Add identifier data to the CHAP challenge. More...
 

Detailed Description

CHAP protocol.

Definition in file chap.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ chap_init()

int chap_init ( struct chap_response chap,
struct digest_algorithm digest 
)

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 51 of file chap.c.

52  {
53  size_t state_len;
54  void *state;
55 
56  assert ( chap->digest == NULL );
57  assert ( chap->digest_context == NULL );
58  assert ( chap->response == NULL );
59 
60  DBG ( "CHAP %p initialising with %s digest\n", chap, digest->name );
61 
62  state_len = ( digest->ctxsize + digest->digestsize );
63  state = malloc ( state_len );
64  if ( ! state ) {
65  DBG ( "CHAP %p could not allocate %zd bytes for state\n",
66  chap, state_len );
67  return -ENOMEM;
68  }
69 
70  chap->digest = digest;
71  chap->digest_context = state;
72  chap->response = ( state + digest->ctxsize );
74  digest_init ( chap->digest, chap->digest_context );
75  return 0;
76 }
uint8_t * response
CHAP response.
Definition: chap.h:24
uint8_t state
State.
Definition: eth_slow.h:47
uint8_t * digest_context
Context used by the digest algorithm.
Definition: chap.h:22
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
struct digest_algorithm * digest
Digest algorithm used for the response.
Definition: chap.h:20
size_t response_len
Length of CHAP response.
Definition: chap.h:26
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
size_t ctxsize
Context size.
Definition: crypto.h:21
size_t digestsize
Digest size.
Definition: crypto.h:25
const char * name
Algorithm name.
Definition: crypto.h:19
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), digest_algorithm::ctxsize, DBG, chap_response::digest, digest, chap_response::digest_context, 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 
)

Add data to the CHAP challenge.

Parameters
chapCHAP response
dataData to add
lenLength of data to add

Definition at line 85 of file chap.c.

86  {
87  assert ( chap->digest != NULL );
88  assert ( chap->digest_context != NULL );
89 
90  if ( ! chap->digest )
91  return;
92 
93  digest_update ( chap->digest, chap->digest_context, data, len );
94 }
uint8_t * digest_context
Context used by the digest algorithm.
Definition: chap.h:22
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct digest_algorithm * digest
Digest algorithm used for the response.
Definition: chap.h:20
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), data, chap_response::digest, chap_response::digest_context, 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)

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 104 of file chap.c.

104  {
105  assert ( chap->digest != NULL );
106  assert ( chap->digest_context != NULL );
107  assert ( chap->response != NULL );
108 
109  DBG ( "CHAP %p responding to challenge\n", chap );
110 
111  if ( ! chap->digest )
112  return;
113 
114  digest_final ( chap->digest, chap->digest_context, chap->response );
115 }
uint8_t * response
CHAP response.
Definition: chap.h:24
uint8_t * digest_context
Context used by the digest algorithm.
Definition: chap.h:22
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct digest_algorithm * digest
Digest algorithm used for the response.
Definition: chap.h:20
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), DBG, chap_response::digest, chap_response::digest_context, 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)

Free resources used by a CHAP response.

Parameters
chapCHAP response

Definition at line 122 of file chap.c.

122  {
123  void *state = chap->digest_context;
124 
125  DBG ( "CHAP %p finished\n", chap );
126 
127  free ( state );
128  memset ( chap, 0, sizeof ( *chap ) );
129 }
uint8_t state
State.
Definition: eth_slow.h:47
uint8_t * digest_context
Context used by the digest algorithm.
Definition: chap.h:22
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
void * memset(void *dest, int character, size_t len) __nonnull

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()

static 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 46 of file chap.h.

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

References chap_update().

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