Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common/lib/libc/hash/sha1 Improve portability and clarity by...
details: https://anonhg.NetBSD.org/src/rev/80802863347a
branches: trunk
changeset: 748840:80802863347a
user: joerg <joerg%NetBSD.org@localhost>
date: Fri Nov 06 20:31:17 2009 +0000
description:
Improve portability and clarity by using uint8_t for the byte data
and expanding u_int to not depend on the !POSIX types.
diffstat:
common/lib/libc/hash/sha1/sha1.c | 30 +++++++++++++++---------------
1 files changed, 15 insertions(+), 15 deletions(-)
diffs (92 lines):
diff -r 2fe98e20b6a0 -r 80802863347a common/lib/libc/hash/sha1/sha1.c
--- a/common/lib/libc/hash/sha1/sha1.c Fri Nov 06 20:20:56 2009 +0000
+++ b/common/lib/libc/hash/sha1/sha1.c Fri Nov 06 20:31:17 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sha1.c,v 1.5 2009/08/21 09:40:51 skrll Exp $ */
+/* $NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $ */
/* $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */
/*
@@ -20,14 +20,14 @@
#include <sys/cdefs.h>
#if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: sha1.c,v 1.5 2009/08/21 09:40:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $");
#include <lib/libkern/libkern.h>
#else
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: sha1.c,v 1.5 2009/08/21 09:40:51 skrll Exp $");
+__RCSID("$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -81,8 +81,8 @@
#endif
typedef union {
- u_char c[64];
- u_int l[16];
+ uint8_t c[64];
+ uint32_t l[16];
} CHAR64LONG16;
/* old sparc64 gcc could not compile this */
@@ -147,7 +147,7 @@
/*
* Hash a single 512-bit block. This is the core of the algorithm.
*/
-void SHA1Transform(uint32_t state[5], const u_char buffer[64])
+void SHA1Transform(uint32_t state[5], const uint8_t buffer[64])
{
uint32_t a, b, c, d, e;
CHAR64LONG16 *block;
@@ -235,9 +235,9 @@
/*
* Run your data through this.
*/
-void SHA1Update(SHA1_CTX *context, const u_char *data, u_int len)
+void SHA1Update(SHA1_CTX *context, const uint8_t *data, unsigned int len)
{
- u_int i, j;
+ unsigned int i, j;
_DIAGASSERT(context != 0);
_DIAGASSERT(data != 0);
@@ -262,26 +262,26 @@
/*
* Add padding and return the message digest.
*/
-void SHA1Final(u_char digest[20], SHA1_CTX *context)
+void SHA1Final(uint8_t digest[20], SHA1_CTX *context)
{
- u_int i;
- u_char finalcount[8];
+ unsigned int i;
+ uint8_t finalcount[8];
_DIAGASSERT(digest != 0);
_DIAGASSERT(context != 0);
for (i = 0; i < 8; i++) {
- finalcount[i] = (u_char)((context->count[(i >= 4 ? 0 : 1)]
+ finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
- SHA1Update(context, (const u_char *)"\200", 1);
+ SHA1Update(context, (const uint8_t *)"\200", 1);
while ((context->count[0] & 504) != 448)
- SHA1Update(context, (const u_char *)"\0", 1);
+ SHA1Update(context, (const uint8_t *)"\0", 1);
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
if (digest) {
for (i = 0; i < 20; i++)
- digest[i] = (u_char)
+ digest[i] = (uint8_t)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
}
Home |
Main Index |
Thread Index |
Old Index