Mercurial > dropbear
comparison hash_memory.c @ 143:5d99163f7e32 libtomcrypt-orig
import of libtomcrypt 0.99
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 19 Dec 2004 11:34:45 +0000 |
parents | 7faae8f46238 |
children |
comparison
equal
deleted
inserted
replaced
15:6362d3854bb4 | 143:5d99163f7e32 |
---|---|
10 */ | 10 */ |
11 #include "mycrypt.h" | 11 #include "mycrypt.h" |
12 | 12 |
13 int hash_memory(int hash, const unsigned char *data, unsigned long len, unsigned char *dst, unsigned long *outlen) | 13 int hash_memory(int hash, const unsigned char *data, unsigned long len, unsigned char *dst, unsigned long *outlen) |
14 { | 14 { |
15 hash_state md; | 15 hash_state *md; |
16 int err; | 16 int err; |
17 | 17 |
18 _ARGCHK(data != NULL); | 18 _ARGCHK(data != NULL); |
19 _ARGCHK(dst != NULL); | 19 _ARGCHK(dst != NULL); |
20 _ARGCHK(outlen != NULL); | 20 _ARGCHK(outlen != NULL); |
24 } | 24 } |
25 | 25 |
26 if (*outlen < hash_descriptor[hash].hashsize) { | 26 if (*outlen < hash_descriptor[hash].hashsize) { |
27 return CRYPT_BUFFER_OVERFLOW; | 27 return CRYPT_BUFFER_OVERFLOW; |
28 } | 28 } |
29 | |
30 md = XMALLOC(sizeof(hash_state)); | |
31 if (md == NULL) { | |
32 return CRYPT_MEM; | |
33 } | |
34 | |
35 if ((err = hash_descriptor[hash].init(md)) != CRYPT_OK) { | |
36 goto __ERR; | |
37 } | |
38 if ((err = hash_descriptor[hash].process(md, data, len)) != CRYPT_OK) { | |
39 goto __ERR; | |
40 } | |
41 err = hash_descriptor[hash].done(md, dst); | |
29 *outlen = hash_descriptor[hash].hashsize; | 42 *outlen = hash_descriptor[hash].hashsize; |
43 __ERR: | |
44 #ifdef CLEAN_STACK | |
45 zeromem(md, sizeof(hash_state)); | |
46 #endif | |
47 XFREE(md); | |
30 | 48 |
31 hash_descriptor[hash].init(&md); | 49 return err; |
32 hash_descriptor[hash].process(&md, data, len); | |
33 hash_descriptor[hash].done(&md, dst); | |
34 return CRYPT_OK; | |
35 } | 50 } |