Mercurial > dropbear
diff libtomcrypt/src/hashes/helper/hash_filehandle.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children | 1ff2a1034c52 |
line wrap: on
line diff
--- a/libtomcrypt/src/hashes/helper/hash_filehandle.c Thu Feb 08 23:11:40 2018 +0800 +++ b/libtomcrypt/src/hashes/helper/hash_filehandle.c Fri Feb 09 21:44:05 2018 +0800 @@ -5,11 +5,10 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, [email protected], http://libtom.org */ #include "tomcrypt.h" +#ifndef LTC_NO_FILE /** @file hash_filehandle.c Hash open files, Tom St Denis @@ -25,12 +24,8 @@ */ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen) { -#ifdef LTC_NO_FILE - (void)hash; (void)in; (void)out; (void)outlen; - return CRYPT_NOP; -#else hash_state md; - unsigned char buf[512]; + unsigned char *buf; size_t x; int err; @@ -38,35 +33,42 @@ LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(in != NULL); + if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) { + return CRYPT_MEM; + } + if ((err = hash_is_valid(hash)) != CRYPT_OK) { - return err; + goto LBL_ERR; } if (*outlen < hash_descriptor[hash].hashsize) { *outlen = hash_descriptor[hash].hashsize; - return CRYPT_BUFFER_OVERFLOW; + err = CRYPT_BUFFER_OVERFLOW; + goto LBL_ERR; } if ((err = hash_descriptor[hash].init(&md)) != CRYPT_OK) { - return err; + goto LBL_ERR; } + do { + x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in); + if ((err = hash_descriptor[hash].process(&md, buf, (unsigned long)x)) != CRYPT_OK) { + goto LBL_CLEANBUF; + } + } while (x == LTC_FILE_READ_BUFSIZE); + if ((err = hash_descriptor[hash].done(&md, out)) == CRYPT_OK) { *outlen = hash_descriptor[hash].hashsize; - do { - x = fread(buf, 1, sizeof(buf), in); - if ((err = hash_descriptor[hash].process(&md, buf, x)) != CRYPT_OK) { - return err; } - } while (x == sizeof(buf)); - err = hash_descriptor[hash].done(&md, out); -#ifdef LTC_CLEAN_STACK - zeromem(buf, sizeof(buf)); -#endif +LBL_CLEANBUF: + zeromem(buf, LTC_FILE_READ_BUFSIZE); +LBL_ERR: + XFREE(buf); return err; -#endif } +#endif /* #ifndef LTC_NO_FILE */ -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */