From nobody Mon Jul 29 20:47:49 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WXr5y0RBtz5Rxyl; Mon, 29 Jul 2024 20:47:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WXr5x4QGMz4lxm; Mon, 29 Jul 2024 20:47:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722286069; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Q+tI8TSCZ+0WZBTXrD3KnbZliqk6X1XMt+ieFNgYldo=; b=qGosc5jJQHbobLoPSuCxrzbg0Dm511DajwdE6hB0L2B65XSPzTG0b0XXVbeRIti1f1k0W+ /vXDtl9L6CFXKcm7luXnX+8pNfri8tuMAG6fZRgKaGY+ykU31OA6kQUhYKWMZgZN6coK5N GXhsHmrQ87XDTo64T5CkDR79y8L19lje/AJXswxp/igJDcr/K7KcOdFe24FMzlos3uyxnJ PuQPodqSTiyrJIfZFt7Nkp1chehAAGidpf33nqEdDPMqhUWL0LYFBQttAMV+iZXZvfcocv +eEpvF0kzVqn44rR1k2eEwO4nR3lzUOHZ7o+3m3FNl4ZGs9ZiL+6mD7NcMDyCQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722286069; a=rsa-sha256; cv=none; b=KOn47Cm4m0qFayekXZqBaPpuCOzp11E2inLD41OJUS8RaTHzkpcMN+HNLDFkSWwCoKqyz9 ankaXqg41PHqheEvrJ5a6LIv+TMTFjuPujhejYlrwjgxMFuToxHZoUL+5o0v5oMeHEokPh 0UhPQKFAmAg24hnDj0liI9s2P0ppNvzt2uxXFE7hEFZp9xBq3nXcHMpGDPbpDhuWiQJmdB pQfvSeGTTQHa4x+2DwfxzkdhsKUqSPy/8CzFaXIiVflEufbPMYX2+2pKjosPlNi6BwrGGP p4j9HU3zaWncZ87Scbcpp0NgV09nj8Cs4/VYod59s86IXQbBMoSH/JpCg5bu/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722286069; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Q+tI8TSCZ+0WZBTXrD3KnbZliqk6X1XMt+ieFNgYldo=; b=VR6n3L9KCXspGsucNNGWU/OcbISgXiHAN5oNRCUqJJeoarNFCsRF3eMlkHnlAfs/tC/2uA zp+NTC8pG5Xz2JiPJva3jewwAYWGCdpq3ee/jwmOiImtnJtA/1N0yjsQF4rBMJAMhwUWyc 6qIFogyCQzrqTXwwmmrkte1SHtMGLbXCTk4sfdwH7MrGREywg6R7EU5bdDPMQcuLo66Se8 xjQ42zTBZf+WYw/ikKBQ9ELdgKCOQMmiqBsl0oRtpsG9FcShPxTVic7FjWj6ga+3Bjzn6a V4nWyooR0yVXnwwfWW5jDCFItC/nybQUlCX8n2hb4qJjcSHJUpPX2P2oiD+XAg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WXr5x3v9Hzq3p; Mon, 29 Jul 2024 20:47:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46TKlnI0030103; Mon, 29 Jul 2024 20:47:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46TKlnQZ030100; Mon, 29 Jul 2024 20:47:49 GMT (envelope-from git) Date: Mon, 29 Jul 2024 20:47:49 GMT Message-Id: <202407292047.46TKlnQZ030100@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 882a725bdfc7 - main - siphash: allow zero values for final & len in SipBuf() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 882a725bdfc71b9fc3b70cbcc230327528f3635e Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=882a725bdfc71b9fc3b70cbcc230327528f3635e commit 882a725bdfc71b9fc3b70cbcc230327528f3635e Author: Mark O'Donovan AuthorDate: 2024-07-11 17:50:31 +0000 Commit: Warner Losh CommitDate: 2024-07-29 20:44:27 +0000 siphash: allow zero values for final & len in SipBuf() Currently the assert checks for XOR of final and len. This assert fails when running the unit tests in siphash_test.c. We need to allow the case where both values are zero. Signed-off-by: Mark O'Donovan Reviewed by: imp, cperciva Pull Request: https://github.com/freebsd/freebsd-src/pull/1324 --- sys/crypto/siphash/siphash.c | 15 ++++++++++----- 1 file 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);