Browse Source

In the Final function, move the context zeroing into the digest != NULL

scope so that passing a NULL digest is equivalent to the Pad function
(like it used to be).  Fixes skey w/ sha1 as noticed by David Krause.
OPENBSD_3_6
millert 20 years ago
parent
commit
638ec6cc63
5 changed files with 17 additions and 21 deletions
  1. +3
    -3
      src/lib/libc/hash/md4.c
  2. +3
    -3
      src/lib/libc/hash/md5.c
  3. +4
    -4
      src/lib/libc/hash/rmd160.c
  4. +3
    -3
      src/lib/libc/hash/sha1.c
  5. +4
    -8
      src/lib/libc/hash/sha2.c

+ 3
- 3
src/lib/libc/hash/md4.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: md4.c,v 1.5 2004/05/03 18:07:07 millert Exp $ */
/* $OpenBSD: md4.c,v 1.6 2004/05/28 15:10:27 millert Exp $ */
/*
* This code implements the MD4 message-digest algorithm.
@ -19,7 +19,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$OpenBSD: md4.c,v 1.5 2004/05/03 18:07:07 millert Exp $";
static const char rcsid[] = "$OpenBSD: md4.c,v 1.6 2004/05/28 15:10:27 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -134,8 +134,8 @@ MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx)
if (digest != NULL) {
for (i = 0; i < 4; i++)
PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
memset(ctx, 0, sizeof(*ctx));
}
memset(ctx, 0, sizeof(*ctx)); /* in case it's sensitive */
}


+ 3
- 3
src/lib/libc/hash/md5.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: md5.c,v 1.6 2004/05/03 18:07:07 millert Exp $ */
/* $OpenBSD: md5.c,v 1.7 2004/05/28 15:10:27 millert Exp $ */
/*
* This code implements the MD5 message-digest algorithm.
@ -18,7 +18,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$OpenBSD: md5.c,v 1.6 2004/05/03 18:07:07 millert Exp $";
static const char rcsid[] = "$OpenBSD: md5.c,v 1.7 2004/05/28 15:10:27 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -133,8 +133,8 @@ MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
if (digest != NULL) {
for (i = 0; i < 4; i++)
PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
memset(ctx, 0, sizeof(*ctx));
}
memset(ctx, 0, sizeof(*ctx)); /* in case it's sensitive */
}


+ 4
- 4
src/lib/libc/hash/rmd160.c View File

@ -32,7 +32,7 @@
#include <rmd160.h>
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: rmd160.c,v 1.16 2004/05/03 18:07:07 millert Exp $";
static char rcsid[] = "$OpenBSD: rmd160.c,v 1.17 2004/05/28 15:10:27 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#define PUT_64BIT_LE(cp, value) do { \
@ -155,11 +155,11 @@ RMD160Final(u_int8_t digest[RMD160_DIGEST_LENGTH], RMD160_CTX *ctx)
int i;
RMD160Pad(ctx);
if (digest != NULL)
if (digest != NULL) {
for (i = 0; i < 5; i++)
PUT_32BIT_LE(digest + i*4, ctx->state[i]);
memset(ctx, 0, sizeof (*ctx));
memset(ctx, 0, sizeof (*ctx));
}
}
void


+ 3
- 3
src/lib/libc/hash/sha1.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sha1.c,v 1.18 2004/05/05 17:09:46 millert Exp $ */
/* $OpenBSD: sha1.c,v 1.19 2004/05/28 15:10:27 millert Exp $ */
/*
* SHA-1 in C
@ -15,7 +15,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$OpenBSD: sha1.c,v 1.18 2004/05/05 17:09:46 millert Exp $";
static const char rcsid[] = "$OpenBSD: sha1.c,v 1.19 2004/05/28 15:10:27 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@ -173,6 +173,6 @@ SHA1Final(u_int8_t digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
digest[i] = (u_int8_t)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
memset(context, 0, sizeof(*context));
}
memset(context, 0, sizeof(*context));
}

+ 4
- 8
src/lib/libc/hash/sha2.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sha2.c,v 1.9 2004/05/07 14:34:40 millert Exp $ */
/* $OpenBSD: sha2.c,v 1.10 2004/05/28 15:10:27 millert Exp $ */
/*
* FILE: sha2.c
@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$OpenBSD: sha2.c,v 1.9 2004/05/07 14:34:40 millert Exp $";
static const char rcsid[] = "$OpenBSD: sha2.c,v 1.10 2004/05/28 15:10:27 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -549,10 +549,8 @@ SHA256_Final(u_int8_t digest[SHA256_DIGEST_LENGTH], SHA256_CTX *context)
#else
memcpy(digest, context->state, SHA256_DIGEST_LENGTH);
#endif
memset(context, 0, sizeof(*context));
}
/* Zero out state data */
memset(context, 0, sizeof(*context));
}
@ -832,10 +830,8 @@ SHA512_Final(u_int8_t digest[SHA512_DIGEST_LENGTH], SHA512_CTX *context)
#else
memcpy(digest, context->state, SHA512_DIGEST_LENGTH);
#endif
memset(context, 0, sizeof(*context));
}
/* Zero out state data */
memset(context, 0, sizeof(*context));
}


Loading…
Cancel
Save