3
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
|
2 * |
|
3 * LibTomCrypt is a library that provides various cryptographic |
|
4 * algorithms in a highly modular and flexible manner. |
|
5 * |
|
6 * The library is free for all purposes without any express |
|
7 * guarantee it works. |
|
8 * |
|
9 * Tom St Denis, [email protected], http://libtomcrypt.org |
|
10 */ |
|
11 #include "mycrypt.h" |
|
12 |
|
13 int hash_memory(int hash, const unsigned char *data, unsigned long len, unsigned char *dst, unsigned long *outlen) |
|
14 { |
|
15 hash_state md; |
|
16 int err; |
|
17 |
|
18 _ARGCHK(data != NULL); |
|
19 _ARGCHK(dst != NULL); |
|
20 _ARGCHK(outlen != NULL); |
|
21 |
|
22 if ((err = hash_is_valid(hash)) != CRYPT_OK) { |
|
23 return err; |
|
24 } |
|
25 |
|
26 if (*outlen < hash_descriptor[hash].hashsize) { |
|
27 return CRYPT_BUFFER_OVERFLOW; |
|
28 } |
|
29 *outlen = hash_descriptor[hash].hashsize; |
|
30 |
|
31 hash_descriptor[hash].init(&md); |
|
32 hash_descriptor[hash].process(&md, data, len); |
|
33 hash_descriptor[hash].done(&md, dst); |
|
34 return CRYPT_OK; |
|
35 } |