1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
13 @file hash_filehandle.c
14 Hash open files, Tom St Denis
18 Hash data from an open file handle.
19 @param hash The index of the hash you want to use
20 @param in The FILE* handle of the file you want to hash
21 @param out [out] The destination of the digest
22 @param outlen [in/out] The max size and resulting size of the digest
23 @result CRYPT_OK if successful
25 int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen)
32 LTC_ARGCHK(out != NULL);
33 LTC_ARGCHK(outlen != NULL);
34 LTC_ARGCHK(in != NULL);
36 if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
40 if ((err = hash_is_valid(hash)) != CRYPT_OK) {
44 if (*outlen < hash_descriptor[hash].hashsize) {
45 *outlen = hash_descriptor[hash].hashsize;
46 err = CRYPT_BUFFER_OVERFLOW;
49 if ((err = hash_descriptor[hash].init(&md)) != CRYPT_OK) {
54 x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
55 if ((err = hash_descriptor[hash].process(&md, buf, (unsigned long)x)) != CRYPT_OK) {
58 } while (x == LTC_FILE_READ_BUFSIZE);
59 if ((err = hash_descriptor[hash].done(&md, out)) == CRYPT_OK) {
60 *outlen = hash_descriptor[hash].hashsize;
64 zeromem(buf, LTC_FILE_READ_BUFSIZE);
69 #endif /* #ifndef LTC_NO_FILE */
72 /* ref: $Format:%D$ */
73 /* git commit: $Format:%H$ */
74 /* commit time: $Format:%ai$ */