On Sat, Dec 21, 2013 at 10:40:15PM -0500, Ted Unangst wrote:
> The sha2 family of init functions check for a null context. This is
> useless. For comparison, the md5 and sha1 init functions don't.
>
> I also point out that all the HashFinal functions check for a null
> digest and don't do anything in that case. This seems stupid to
> me, I think such programs should crash. I didn't change anything
> yet because they are at least all consistent. Thoughts?
>
I think you're right, this diff makes sense, programs that pass
a NULL context should crash instead of silently returning...
> Index: sha2.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/hash/sha2.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 sha2.c
> --- sha2.c 15 Apr 2013 15:54:17 -0000 1.14
> +++ sha2.c 22 Dec 2013 03:34:23 -0000
> @@ -287,8 +287,6 @@ const static u_int64_t sha512_initial_ha
> void
> SHA224Init(SHA2_CTX *context)
> {
> - if (context == NULL)
> - return;
> memcpy(context->state.st32, sha224_initial_hash_value,
> sizeof(sha224_initial_hash_value));
> memset(context->buffer, 0, sizeof(context->buffer));
> @@ -324,8 +322,6 @@ SHA224Final(u_int8_t digest[SHA224_DIGES
> void
> SHA256Init(SHA2_CTX *context)
> {
> - if (context == NULL)
> - return;
> memcpy(context->state.st32, sha256_initial_hash_value,
> sizeof(sha256_initial_hash_value));
> memset(context->buffer, 0, sizeof(context->buffer));
> @@ -605,8 +601,6 @@ SHA256Final(u_int8_t digest[SHA256_DIGES
> void
> SHA512Init(SHA2_CTX *context)
> {
> - if (context == NULL)
> - return;
> memcpy(context->state.st64, sha512_initial_hash_value,
> sizeof(sha512_initial_hash_value));
> memset(context->buffer, 0, sizeof(context->buffer));
> @@ -886,8 +880,6 @@ SHA512Final(u_int8_t digest[SHA512_DIGES
> void
> SHA384Init(SHA2_CTX *context)
> {
> - if (context == NULL)
> - return;
> memcpy(context->state.st64, sha384_initial_hash_value,
> sizeof(sha384_initial_hash_value));
> memset(context->buffer, 0, sizeof(context->buffer));
>
--
Gilles Chehade
https://www.poolp.org @poolpOrg