summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-05-28 15:10:28 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-05-28 15:10:28 +0000
commit17d2c85d9d3efc20e6eff3b12f905ed70ba24983 (patch)
tree99becf88119a703a8b275748133ee7fcde045163 /lib
parentc2888a975d59102b19a3bfe63b7e9ac0f50fe419 (diff)
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/hash/md4.c6
-rw-r--r--lib/libc/hash/md5.c6
-rw-r--r--lib/libc/hash/rmd160.c8
-rw-r--r--lib/libc/hash/sha1.c6
-rw-r--r--lib/libc/hash/sha2.c12
5 files changed, 17 insertions, 21 deletions
diff --git a/lib/libc/hash/md4.c b/lib/libc/hash/md4.c
index a1006dbf7cb..0979ae348a5 100644
--- a/lib/libc/hash/md4.c
+++ b/lib/libc/hash/md4.c
@@ -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 */
}
diff --git a/lib/libc/hash/md5.c b/lib/libc/hash/md5.c
index 85e71d81824..a1ff135e3cf 100644
--- a/lib/libc/hash/md5.c
+++ b/lib/libc/hash/md5.c
@@ -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 */
}
diff --git a/lib/libc/hash/rmd160.c b/lib/libc/hash/rmd160.c
index bea97614841..4fb64cd19aa 100644
--- a/lib/libc/hash/rmd160.c
+++ b/lib/libc/hash/rmd160.c
@@ -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
diff --git a/lib/libc/hash/sha1.c b/lib/libc/hash/sha1.c
index bb901ff4df7..968c2b322f8 100644
--- a/lib/libc/hash/sha1.c
+++ b/lib/libc/hash/sha1.c
@@ -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));
}
diff --git a/lib/libc/hash/sha2.c b/lib/libc/hash/sha2.c
index cd95d68064d..c99ed4d6a02 100644
--- a/lib/libc/hash/sha2.c
+++ b/lib/libc/hash/sha2.c
@@ -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));
}