123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
-
-
- FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
- #include <stddef.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <assert.h>
- #include <ipxe/crypto.h>
- #include <ipxe/chap.h>
-
-
-
-
- int chap_init ( struct chap_response *chap,
- struct digest_algorithm *digest ) {
- size_t state_len;
- void *state;
-
- assert ( chap->digest == NULL );
- assert ( chap->digest_context == NULL );
- assert ( chap->response == NULL );
-
- DBG ( "CHAP %p initialising with %s digest\n", chap, digest->name );
-
- state_len = ( digest->ctxsize + digest->digestsize );
- state = malloc ( state_len );
- if ( ! state ) {
- DBG ( "CHAP %p could not allocate %zd bytes for state\n",
- chap, state_len );
- return -ENOMEM;
- }
-
- chap->digest = digest;
- chap->digest_context = state;
- chap->response = ( state + digest->ctxsize );
- chap->response_len = digest->digestsize;
- digest_init ( chap->digest, chap->digest_context );
- return 0;
- }
-
-
- void chap_update ( struct chap_response *chap, const void *data,
- size_t len ) {
- assert ( chap->digest != NULL );
- assert ( chap->digest_context != NULL );
-
- if ( ! chap->digest )
- return;
-
- digest_update ( chap->digest, chap->digest_context, data, len );
- }
-
-
- void chap_respond ( struct chap_response *chap ) {
- assert ( chap->digest != NULL );
- assert ( chap->digest_context != NULL );
- assert ( chap->response != NULL );
-
- DBG ( "CHAP %p responding to challenge\n", chap );
-
- if ( ! chap->digest )
- return;
-
- digest_final ( chap->digest, chap->digest_context, chap->response );
- }
-
-
- void chap_finish ( struct chap_response *chap ) {
- void *state = chap->digest_context;
-
- DBG ( "CHAP %p finished\n", chap );
-
- free ( state );
- memset ( chap, 0, sizeof ( *chap ) );
- }
|