chap.c File Reference

CHAP protocol. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <gpxe/crypto.h>
#include <gpxe/chap.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
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.


Detailed Description

CHAP protocol.

Definition in file chap.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

int chap_init ( struct chap_response chap,
struct digest_algorithm digest 
)

Initialise CHAP challenge/response.

Parameters:
chap CHAP challenge/response
digest Digest algorithm to use
Return values:
rc Return 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 46 of file chap.c.

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, and chap_response::response_len.

Referenced by iscsi_handle_chap_i_value(), and iscsi_handle_chap_r_value().

00047                                                   {
00048         size_t state_len;
00049         void *state;
00050 
00051         assert ( chap->digest == NULL );
00052         assert ( chap->digest_context == NULL );
00053         assert ( chap->response == NULL );
00054 
00055         DBG ( "CHAP %p initialising with %s digest\n", chap, digest->name );
00056 
00057         state_len = ( digest->ctxsize + digest->digestsize );
00058         state = malloc ( state_len );
00059         if ( ! state ) {
00060                 DBG ( "CHAP %p could not allocate %zd bytes for state\n",
00061                       chap, state_len );
00062                 return -ENOMEM;
00063         }
00064         
00065         chap->digest = digest;
00066         chap->digest_context = state;
00067         chap->response = ( state + digest->ctxsize );
00068         chap->response_len = digest->digestsize;
00069         digest_init ( chap->digest, chap->digest_context );
00070         return 0;
00071 }

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

Add data to the CHAP challenge.

Parameters:
chap CHAP response
data Data to add
len Length of data to add

Definition at line 80 of file chap.c.

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

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

00081                                 {
00082         assert ( chap->digest != NULL );
00083         assert ( chap->digest_context != NULL );
00084 
00085         if ( ! chap->digest )
00086                 return;
00087 
00088         digest_update ( chap->digest, chap->digest_context, data, len );
00089 }

void chap_respond ( struct chap_response chap  ) 

Respond to the CHAP challenge.

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

Definition at line 99 of file chap.c.

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

Referenced by iscsi_handle_chap_c_value(), and iscsi_handle_chap_r_value().

00099                                                  {
00100         assert ( chap->digest != NULL );
00101         assert ( chap->digest_context != NULL );
00102         assert ( chap->response != NULL );
00103 
00104         DBG ( "CHAP %p responding to challenge\n", chap );
00105 
00106         if ( ! chap->digest )
00107                 return;
00108 
00109         digest_final ( chap->digest, chap->digest_context, chap->response );
00110 }

void chap_finish ( struct chap_response chap  ) 

Free resources used by a CHAP response.

Parameters:
chap CHAP response

Definition at line 117 of file chap.c.

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

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

00117                                                 {
00118         void *state = chap->digest_context;
00119 
00120         DBG ( "CHAP %p finished\n", chap );
00121 
00122         free ( state );
00123         memset ( chap, 0, sizeof ( *chap ) );
00124 }


Generated on Tue Apr 6 20:01:15 2010 for gPXE by  doxygen 1.5.7.1