summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2015-02-20 11:51:03 +0000
committertedu <tedu@openbsd.org>2015-02-20 11:51:03 +0000
commitb8a0470688ccdd7ea69464e85fa4016e7795d244 (patch)
treea4549beb89f8135e48a57b6878caf6878adf6837
parentfix a memory leak in the error case found by Maxime Villard's Brainy (diff)
downloadwireguard-openbsd-b8a0470688ccdd7ea69464e85fa4016e7795d244.tar.xz
wireguard-openbsd-b8a0470688ccdd7ea69464e85fa4016e7795d244.zip
Use standard spelling for types, and rename local variable from "free".
No actual change, but makes it easier to reuse the code elsewhere. Suggested by Andre Smagin
-rw-r--r--include/siphash.h16
-rw-r--r--lib/libc/hash/siphash.c34
-rw-r--r--sys/crypto/siphash.c34
-rw-r--r--sys/crypto/siphash.h16
4 files changed, 50 insertions, 50 deletions
diff --git a/include/siphash.h b/include/siphash.h
index a661d1dd3af..7a5990c9395 100644
--- a/include/siphash.h
+++ b/include/siphash.h
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: siphash.h,v 1.2 2014/12/20 05:43:26 guenther Exp $
+ * $OpenBSD: siphash.h,v 1.3 2015/02/20 11:51:03 tedu Exp $
*/
/*
@@ -52,21 +52,21 @@
#define SIPHASH_DIGEST_LENGTH 8
typedef struct _SIPHASH_CTX {
- u_int64_t v[4];
- u_int8_t buf[SIPHASH_BLOCK_LENGTH];
- u_int32_t bytes;
+ uint64_t v[4];
+ uint8_t buf[SIPHASH_BLOCK_LENGTH];
+ uint32_t bytes;
} SIPHASH_CTX;
typedef struct {
- u_int64_t k0;
- u_int64_t k1;
+ uint64_t k0;
+ uint64_t k1;
} SIPHASH_KEY;
void SipHash_Init(SIPHASH_CTX *, const SIPHASH_KEY *);
void SipHash_Update(SIPHASH_CTX *, int, int, const void *, size_t);
-u_int64_t SipHash_End(SIPHASH_CTX *, int, int);
+uint64_t SipHash_End(SIPHASH_CTX *, int, int);
void SipHash_Final(void *, SIPHASH_CTX *, int, int);
-u_int64_t SipHash(const SIPHASH_KEY *, int, int, const void *, size_t);
+uint64_t SipHash(const SIPHASH_KEY *, int, int, const void *, size_t);
#define SipHash24_Init(_c, _k) SipHash_Init((_c), (_k))
#define SipHash24_Update(_c, _p, _l) SipHash_Update((_c), 2, 4, (_p), (_l))
diff --git a/lib/libc/hash/siphash.c b/lib/libc/hash/siphash.c
index 11ed73c6bea..1e1b9077a34 100644
--- a/lib/libc/hash/siphash.c
+++ b/lib/libc/hash/siphash.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: siphash.c,v 1.3 2015/02/07 05:40:59 dlg Exp $ */
+/* $OpenBSD: siphash.c,v 1.4 2015/02/20 11:51:03 tedu Exp $ */
/*-
* Copyright (c) 2013 Andre Oppermann <andre@FreeBSD.org>
@@ -72,8 +72,8 @@ SipHash_Init(SIPHASH_CTX *ctx, const SIPHASH_KEY *key)
void
SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, const void *src, size_t len)
{
- const u_int8_t *ptr = src;
- size_t free, used;
+ const uint8_t *ptr = src;
+ size_t left, used;
if (len == 0)
return;
@@ -82,13 +82,13 @@ SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, const void *src, size_t len)
ctx->bytes += len;
if (used > 0) {
- free = sizeof(ctx->buf) - used;
+ left = sizeof(ctx->buf) - used;
- if (len >= free) {
- memcpy(&ctx->buf[used], ptr, free);
+ if (len >= left) {
+ memcpy(&ctx->buf[used], ptr, left);
SipHash_CRounds(ctx, rc);
- len -= free;
- ptr += free;
+ len -= left;
+ ptr += left;
} else {
memcpy(&ctx->buf[used], ptr, len);
return;
@@ -109,22 +109,22 @@ SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, const void *src, size_t len)
void
SipHash_Final(void *dst, SIPHASH_CTX *ctx, int rc, int rf)
{
- u_int64_t r;
+ uint64_t r;
r = SipHash_End(ctx, rc, rf);
- *(u_int64_t *)dst = htole64(r);
+ *(uint64_t *)dst = htole64(r);
}
-u_int64_t
+uint64_t
SipHash_End(SIPHASH_CTX *ctx, int rc, int rf)
{
- u_int64_t r;
- size_t free, used;
+ uint64_t r;
+ size_t left, used;
used = ctx->bytes % sizeof(ctx->buf);
- free = sizeof(ctx->buf) - used;
- memset(&ctx->buf[used], 0, free - 1);
+ left = sizeof(ctx->buf) - used;
+ memset(&ctx->buf[used], 0, left - 1);
ctx->buf[7] = ctx->bytes;
SipHash_CRounds(ctx, rc);
@@ -136,7 +136,7 @@ SipHash_End(SIPHASH_CTX *ctx, int rc, int rf)
return (r);
}
-u_int64_t
+uint64_t
SipHash(const SIPHASH_KEY *key, int rc, int rf, const void *src, size_t len)
{
SIPHASH_CTX ctx;
@@ -175,7 +175,7 @@ SipHash_Rounds(SIPHASH_CTX *ctx, int rounds)
static void
SipHash_CRounds(SIPHASH_CTX *ctx, int rounds)
{
- u_int64_t m = letoh64(*(u_int64_t *)ctx->buf);
+ uint64_t m = le64toh(*(uint64_t *)ctx->buf);
ctx->v[3] ^= m;
SipHash_Rounds(ctx, rounds);
diff --git a/sys/crypto/siphash.c b/sys/crypto/siphash.c
index 0af97a0662b..478543096a0 100644
--- a/sys/crypto/siphash.c
+++ b/sys/crypto/siphash.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: siphash.c,v 1.2 2015/02/07 05:45:06 dlg Exp $ */
+/* $OpenBSD: siphash.c,v 1.3 2015/02/20 11:51:03 tedu Exp $ */
/*-
* Copyright (c) 2013 Andre Oppermann <andre@FreeBSD.org>
@@ -71,8 +71,8 @@ SipHash_Init(SIPHASH_CTX *ctx, const SIPHASH_KEY *key)
void
SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, const void *src, size_t len)
{
- const u_int8_t *ptr = src;
- size_t free, used;
+ const uint8_t *ptr = src;
+ size_t left, used;
if (len == 0)
return;
@@ -81,13 +81,13 @@ SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, const void *src, size_t len)
ctx->bytes += len;
if (used > 0) {
- free = sizeof(ctx->buf) - used;
+ left = sizeof(ctx->buf) - used;
- if (len >= free) {
- memcpy(&ctx->buf[used], ptr, free);
+ if (len >= left) {
+ memcpy(&ctx->buf[used], ptr, left);
SipHash_CRounds(ctx, rc);
- len -= free;
- ptr += free;
+ len -= left;
+ ptr += left;
} else {
memcpy(&ctx->buf[used], ptr, len);
return;
@@ -108,22 +108,22 @@ SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, const void *src, size_t len)
void
SipHash_Final(void *dst, SIPHASH_CTX *ctx, int rc, int rf)
{
- u_int64_t r;
+ uint64_t r;
r = SipHash_End(ctx, rc, rf);
- htolem64((u_int64_t *)dst, r);
+ htolem64((uint64_t *)dst, r);
}
-u_int64_t
+uint64_t
SipHash_End(SIPHASH_CTX *ctx, int rc, int rf)
{
- u_int64_t r;
- size_t free, used;
+ uint64_t r;
+ size_t left, used;
used = ctx->bytes % sizeof(ctx->buf);
- free = sizeof(ctx->buf) - used;
- memset(&ctx->buf[used], 0, free - 1);
+ left = sizeof(ctx->buf) - used;
+ memset(&ctx->buf[used], 0, left - 1);
ctx->buf[7] = ctx->bytes;
SipHash_CRounds(ctx, rc);
@@ -135,7 +135,7 @@ SipHash_End(SIPHASH_CTX *ctx, int rc, int rf)
return (r);
}
-u_int64_t
+uint64_t
SipHash(const SIPHASH_KEY *key, int rc, int rf, const void *src, size_t len)
{
SIPHASH_CTX ctx;
@@ -174,7 +174,7 @@ SipHash_Rounds(SIPHASH_CTX *ctx, int rounds)
static void
SipHash_CRounds(SIPHASH_CTX *ctx, int rounds)
{
- u_int64_t m = lemtoh64((u_int64_t *)ctx->buf);
+ uint64_t m = lemtoh64((uint64_t *)ctx->buf);
ctx->v[3] ^= m;
SipHash_Rounds(ctx, rounds);
diff --git a/sys/crypto/siphash.h b/sys/crypto/siphash.h
index 3783ceb4e3e..fa12be2cc6a 100644
--- a/sys/crypto/siphash.h
+++ b/sys/crypto/siphash.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: siphash.h,v 1.4 2015/01/04 09:07:44 miod Exp $ */
+/* $OpenBSD: siphash.h,v 1.5 2015/02/20 11:51:03 tedu Exp $ */
/*-
* Copyright (c) 2013 Andre Oppermann <andre@FreeBSD.org>
* All rights reserved.
@@ -53,23 +53,23 @@
#define SIPHASH_DIGEST_LENGTH 8
typedef struct _SIPHASH_CTX {
- u_int64_t v[4];
- u_int8_t buf[SIPHASH_BLOCK_LENGTH];
- u_int32_t bytes;
+ uint64_t v[4];
+ uint8_t buf[SIPHASH_BLOCK_LENGTH];
+ uint32_t bytes;
} SIPHASH_CTX;
typedef struct {
- u_int64_t k0;
- u_int64_t k1;
+ uint64_t k0;
+ uint64_t k1;
} SIPHASH_KEY;
void SipHash_Init(SIPHASH_CTX *, const SIPHASH_KEY *);
void SipHash_Update(SIPHASH_CTX *, int, int, const void *, size_t)
__bounded((__buffer__, 4, 5));
-u_int64_t SipHash_End(SIPHASH_CTX *, int, int);
+uint64_t SipHash_End(SIPHASH_CTX *, int, int);
void SipHash_Final(void *, SIPHASH_CTX *, int, int)
__bounded((__minbytes__, 1, SIPHASH_DIGEST_LENGTH));
-u_int64_t SipHash(const SIPHASH_KEY *, int, int, const void *, size_t)
+uint64_t SipHash(const SIPHASH_KEY *, int, int, const void *, size_t)
__bounded((__buffer__, 4, 5));
#define SipHash24_Init(_c, _k) SipHash_Init((_c), (_k))