aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark O'Donovan <shiftee@posteo.net>2024-07-11 17:50:31 +0000
committerWarner Losh <imp@FreeBSD.org>2024-07-29 20:44:27 +0000
commit882a725bdfc71b9fc3b70cbcc230327528f3635e (patch)
tree65cdceec460ab6a48d2e5286a7584576bb0aa30d /sys
parent0244e0a177a68fc8ff7e8a58fa7a9553956232ec (diff)
Diffstat (limited to 'sys')
-rw-r--r--sys/crypto/siphash/siphash.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/sys/crypto/siphash/siphash.c b/sys/crypto/siphash/siphash.c
index 92c87d71d391..89b2b18149ef 100644
--- a/sys/crypto/siphash/siphash.c
+++ b/sys/crypto/siphash/siphash.c
@@ -92,16 +92,21 @@ SipBuf(SIPHASH_CTX *ctx, const uint8_t **src, size_t len, int final)
{
size_t x = 0;
- KASSERT((!final && len > 0) || (final && len == 0),
- ("%s: invalid parameters", __func__));
+ /* handle hashing 0 length buffer - needed for test vectors */
+ if (len == 0 && final == 0)
+ return (0);
- if (!final) {
+ if (final) {
+ KASSERT(len == 0, ("%s: invalid len param", __func__));
+ ctx->buf.b8[7] = (uint8_t)ctx->bytes;
+ } else {
+ KASSERT((len > 0) && src && *src,
+ ("%s: invalid parameters", __func__));
x = MIN(len, sizeof(ctx->buf.b64) - ctx->buflen);
bcopy(*src, &ctx->buf.b8[ctx->buflen], x);
ctx->buflen += x;
*src += x;
- } else
- ctx->buf.b8[7] = (uint8_t)ctx->bytes;
+ }
if (ctx->buflen == 8 || final) {
ctx->v[3] ^= le64toh(ctx->buf.b64);