summaryrefslogtreecommitdiffstats
path: root/src/crypto
diff options
context:
space:
mode:
authorMichael Brown2006-11-21 17:01:12 +0100
committerMichael Brown2006-11-21 17:01:12 +0100
commita9415d3da2b05d82aa2f0ad1904a368283c4116b (patch)
tree5ac35d2acc508e4122f194545dc6b13e60356338 /src/crypto
parentAdded generic CHAP layer, independent of iSCSI (diff)
downloadipxe-a9415d3da2b05d82aa2f0ad1904a368283c4116b.tar.gz
ipxe-a9415d3da2b05d82aa2f0ad1904a368283c4116b.tar.xz
ipxe-a9415d3da2b05d82aa2f0ad1904a368283c4116b.zip
Reduce from 157 to 123 bytes
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/chap.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/crypto/chap.c b/src/crypto/chap.c
index 997f5391..cbfef2d9 100644
--- a/src/crypto/chap.c
+++ b/src/crypto/chap.c
@@ -18,6 +18,7 @@
#include <stddef.h>
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <assert.h>
#include <malloc.h>
@@ -43,24 +44,24 @@
*/
int chap_init ( struct chap_challenge *chap,
struct digest_algorithm *digest ) {
+ size_t state_len;
+ void *state;
+
assert ( chap->digest == NULL );
assert ( chap->digest_context == NULL );
assert ( chap->response == NULL );
+ state_len = ( digest->context_len + digest->digest_len );
+ state = malloc ( state_len );
+ if ( ! state )
+ return -ENOMEM;
+
chap->digest = digest;
- chap->digest_context = malloc ( digest->context_len );
- if ( ! chap->digest_context )
- goto err;
- chap->response = malloc ( digest->digest_len );
- if ( ! chap->response )
- goto err;
+ chap->digest_context = state;
+ chap->response = ( state + digest->context_len );
chap->response_len = digest->digest_len;
chap->digest->init ( chap->digest_context );
return 0;
-
- err:
- chap_finish ( chap );
- return -ENOMEM;
}
/**
@@ -100,9 +101,8 @@ void chap_respond ( struct chap_challenge *chap ) {
* @v chap CHAP challenge/response
*/
void chap_finish ( struct chap_challenge *chap ) {
- free ( chap->digest_context );
- chap->digest_context = NULL;
- free ( chap->response );
- chap->response = NULL;
- chap->digest = NULL;
+ void *state = chap->digest_context;
+
+ free ( state );
+ memset ( chap, 0, sizeof ( *chap ) );
}