|
@@ -18,6 +18,7 @@
|
18
|
18
|
|
19
|
19
|
#include <stddef.h>
|
20
|
20
|
#include <stdlib.h>
|
|
21
|
+#include <string.h>
|
21
|
22
|
#include <errno.h>
|
22
|
23
|
#include <assert.h>
|
23
|
24
|
#include <malloc.h>
|
|
@@ -43,24 +44,24 @@
|
43
|
44
|
*/
|
44
|
45
|
int chap_init ( struct chap_challenge *chap,
|
45
|
46
|
struct digest_algorithm *digest ) {
|
|
47
|
+ size_t state_len;
|
|
48
|
+ void *state;
|
|
49
|
+
|
46
|
50
|
assert ( chap->digest == NULL );
|
47
|
51
|
assert ( chap->digest_context == NULL );
|
48
|
52
|
assert ( chap->response == NULL );
|
49
|
53
|
|
|
54
|
+ state_len = ( digest->context_len + digest->digest_len );
|
|
55
|
+ state = malloc ( state_len );
|
|
56
|
+ if ( ! state )
|
|
57
|
+ return -ENOMEM;
|
|
58
|
+
|
50
|
59
|
chap->digest = digest;
|
51
|
|
- chap->digest_context = malloc ( digest->context_len );
|
52
|
|
- if ( ! chap->digest_context )
|
53
|
|
- goto err;
|
54
|
|
- chap->response = malloc ( digest->digest_len );
|
55
|
|
- if ( ! chap->response )
|
56
|
|
- goto err;
|
|
60
|
+ chap->digest_context = state;
|
|
61
|
+ chap->response = ( state + digest->context_len );
|
57
|
62
|
chap->response_len = digest->digest_len;
|
58
|
63
|
chap->digest->init ( chap->digest_context );
|
59
|
64
|
return 0;
|
60
|
|
-
|
61
|
|
- err:
|
62
|
|
- chap_finish ( chap );
|
63
|
|
- return -ENOMEM;
|
64
|
65
|
}
|
65
|
66
|
|
66
|
67
|
/**
|
|
@@ -100,9 +101,8 @@ void chap_respond ( struct chap_challenge *chap ) {
|
100
|
101
|
* @v chap CHAP challenge/response
|
101
|
102
|
*/
|
102
|
103
|
void chap_finish ( struct chap_challenge *chap ) {
|
103
|
|
- free ( chap->digest_context );
|
104
|
|
- chap->digest_context = NULL;
|
105
|
|
- free ( chap->response );
|
106
|
|
- chap->response = NULL;
|
107
|
|
- chap->digest = NULL;
|
|
104
|
+ void *state = chap->digest_context;
|
|
105
|
+
|
|
106
|
+ free ( state );
|
|
107
|
+ memset ( chap, 0, sizeof ( *chap ) );
|
108
|
108
|
}
|