11
11
struct _beecrypt_digest {
12
12
struct cf_digest digest ;
13
13
hashFunction * hash ;
14
- hashFunctionParam * param ;
14
+ char param [ 1 ] ;
15
15
};
16
16
17
+ /* Minus 1 to account for space taken by param */
18
+ #define BEECRYPT_DIGEST_STRUCT_SIZE (paramSize ) (sizeof(struct _beecrypt_digest) - 1 + (paramSize))
19
+
17
20
static cf_digest_t create_beecrypt_container (hashFunction * hash );
18
21
19
22
static cf_rv_t _digest_update (cf_digest_t digest , void * data , size_t data_len ) {
20
23
struct _beecrypt_digest * impl = (struct _beecrypt_digest * )digest ;
21
24
/* TODO: check return value */
22
- impl -> hash -> update (impl -> param , data , data_len );
25
+ impl -> hash -> update (( void * ) impl -> param , data , data_len );
23
26
return CF_S_OK ;
24
27
}
25
28
@@ -31,8 +34,6 @@ static cf_rv_t _digest_finish(cf_digest_t digest, void *output, size_t *output_l
31
34
return CF_S_OK ;
32
35
}
33
36
if (!output && !output_len ) {
34
- free (impl -> param );
35
- impl -> param = NULL ;
36
37
free (impl );
37
38
return CF_S_OK ;
38
39
}
@@ -42,9 +43,7 @@ static cf_rv_t _digest_finish(cf_digest_t digest, void *output, size_t *output_l
42
43
}
43
44
* output_len = real_len ;
44
45
/* TODO: check return value */
45
- impl -> hash -> digest (impl -> param , output );
46
- free (impl -> param );
47
- impl -> param = NULL ;
46
+ impl -> hash -> digest ((void * )impl -> param , output );
48
47
free (impl );
49
48
return CF_S_OK ;
50
49
}
@@ -68,18 +67,13 @@ static struct cf_digest_instance_ops beecrypt_digest_instance_ops = {
68
67
};
69
68
70
69
static cf_digest_t create_beecrypt_container (hashFunction * hash ) {
71
- struct _beecrypt_digest * impl = calloc (1 , sizeof (* impl ));
70
+ /* Allocate size for structure + additional param data at end - extra padding in */
71
+ struct _beecrypt_digest * impl = calloc (1 , BEECRYPT_DIGEST_STRUCT_SIZE (hash -> paramsize ));
72
72
if (!impl ) {
73
73
return NULL ;
74
74
}
75
75
impl -> digest .ops = & beecrypt_digest_instance_ops ;
76
76
impl -> hash = hash ;
77
- impl -> param = (hashFunctionParam * )malloc (hash -> paramsize );
78
- if (!impl -> param ) {
79
- free (impl );
80
- impl = NULL ;
81
- return NULL ;
82
- }
83
77
/* TODO: check return value */
84
78
hash -> reset (impl -> param );
85
79
return (cf_digest_t )impl ;
0 commit comments