From patchwork Thu Mar 12 15:33:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4817 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:2755:b0:83c:d90d:321 with SMTP id j21csp627923maq; Thu, 12 Mar 2026 08:33:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUugLWmJvzOwBprzTTFBxiiTQFysDrl0VBzZi3iU3wJBenZVriok1VJsnNIwQjW2Gy1OBaLp2wu0kg=@openvpn.net X-Received: by 2002:a05:600c:8a1a:20b0:483:badb:618b with SMTP id 5b1f17b1804b1-4854b1b1185mr85367175e9.24.1773329630732; Thu, 12 Mar 2026 08:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773329630; cv=none; d=google.com; s=arc-20240605; b=cjIgQoerMyShw/mykClpDHOsccCcdCBcCqkQup+jil4tO3q4KdstD7uh6oKLZaduKH aZ4O7MoCC+Gsf845D5pfyCVOiUJYhijhDcBva0i36ZbjIm0rCeM9rSLAvcP2nOjfrUNF ZzKXRHIKeUFDjybYVHkNs13JLpgcnOnuTAqOBEkTTW7zUrQtQpz7KFYjtMVQQLjktDXK 5KpghxXnGwxMkbYn5O84iB89AM8WoPWf8Ny7C6oma+uw1c/wfxdJ93tX2rheWucJbwwm /GW+x1gdnXRA/8cYZXdl/saKtZvDDr+5EpJ8bA5gzfJ82TwM3zo7Le0FiZly4Sx8lm61 uumg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=L+Xb/JGZnnOP+Ob9Co4/FZi7MmI4wg0idVVpPX8Is8Y=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=YTnoCCktMlsDVWxCQxbqwOi0PvGa9YPSK+fwoX4Og6OF/h4WrrGZsRwd1XbV8Ebr8O h0JOuzEa2dnCWLNow7Tykmn3r+rJDH2Mdl+cjDJp73TiWXjYjsnbQ2esUf1N7wWMMyEc fgKyuR6s1yRphpL2bRkENr7PEeXRsKgfG9mSMtyyoVB8cZkp78GgFIpcN0B5Z6LUzP5a 6dlTQR4fPD15qMzQR4qu2JhLDm6goBgDrgCFnjQZX3d8AzpGohC2UQXT4ES6NyIi66zg bO/+UO9UbnmuM4sm3/m8ngOinn4dc+8xe0sdBddOrriFoBWjFyErzLbL5ko5jxnUWrtW 4UNA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=Z9rdsoXk; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="TFU/vPZx"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=e98eWwZh; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id ffacd0b85a97d-439fe223d42si6461541f8f.191.2026.03.12.08.33.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2026 08:33:50 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=Z9rdsoXk; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="TFU/vPZx"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=e98eWwZh; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=L+Xb/JGZnnOP+Ob9Co4/FZi7MmI4wg0idVVpPX8Is8Y=; b=Z9rdsoXkk54rfh0HfHNWWnrUz3 Ae0dkTOhqpeKoQmROR6r9fsWMWeRLEa+OUJkqm3XaIl0AWnC5zzXixf1Bftac4Juh75BVbtO5klnS KbfpHzLIC5JGJSXeWGTxnNLOQJ2SgFsVQ4IDvGftPI4mx9SZqAcKUJxjG52CO5AJvF0Y=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1w0i2i-0007CI-2A; Thu, 12 Mar 2026 15:33:44 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1w0i2g-0007CC-Pb for openvpn-devel@lists.sourceforge.net; Thu, 12 Mar 2026 15:33:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=fqmpaS+IndtFjn2lncOObtWRAPGuuHhp2TwCP3uIEAg=; b=TFU/vPZxrn7N7VO842GagYAOIh tdRpqLuHYCeGr3TXqWEGvSileavnGzPDsUmR9oe113ccFbnIOll0LnPVk8XcmjcJCPW2MKXFx2H0u UG7HkrYtRn8BwlDSwYbIkWsBebDhhs8R9BP/nRuUNTgt3GCEN62htWvut6VEQp0R3ViY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=fqmpaS+IndtFjn2lncOObtWRAPGuuHhp2TwCP3uIEAg=; b=e98eWwZhhCPv21/W3RbyQGySpi gyyPiyOO6VWqyXagHjPI58HgIY/ttVeT7FVfZKsCWjLhi4/OfArqRr/sr7RE3V8tcAAAft3QwKudt oEqe35vA8bjkKy5IHKW3PljC8MugAF27D1dD995V3Xj5YnYE6/Iyvsn35FKFUfMW+DSg=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1w0i2f-000672-HN for openvpn-devel@lists.sourceforge.net; Thu, 12 Mar 2026 15:33:42 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 62CFXTCq004715 for ; Thu, 12 Mar 2026 16:33:29 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 62CFXT15004714 for openvpn-devel@lists.sourceforge.net; Thu, 12 Mar 2026 16:33:29 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 12 Mar 2026 16:33:23 +0100 Message-ID: <20260312153329.4700-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Arne Schwabe OpenSSL only supports SIPHASH with OpenSSL 3.1 and newer. The source code of siphash is quite small and has very liberal CC0 license, so include it instead of pulling an extra library for it. Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1w0i2f-000672-HN Subject: [Openvpn-devel] [PATCH v9] Add siphash reference implementation X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1859470890544448935?= X-GMAIL-MSGID: =?utf-8?q?1859470890544448935?= From: Arne Schwabe OpenSSL only supports SIPHASH with OpenSSL 3.1 and newer. The source code of siphash is quite small and has very liberal CC0 license, so include it instead of pulling an extra library for it. Change-Id: I1292894fe7f537049a97bee97af4419e5e854a00 Signed-off-by: Arne Schwabe Acked-by: MaxF Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/29 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/29 This mail reflects revision 9 of this Change. Acked-by according to Gerrit (reflected above): MaxF diff --git a/src/openvpn/siphash.h b/src/openvpn/siphash.h new file mode 100644 index 0000000..ef61110 --- /dev/null +++ b/src/openvpn/siphash.h @@ -0,0 +1,29 @@ +/* + * SipHash reference C implementation + * + * Copyright (c) 2012-2021 Jean-Philippe Aumasson + * + * Copyright (c) 2012-2014 Daniel J. Bernstein + * + * To the extent possible under law, the author(s) have dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty. + * + * You should have received a copy of the CC0 Public Domain Dedication along + * with + * this software. If not, see + * . + */ + +#ifndef SIPHASH_H +#define SIPHASH_H + +#include + +/* siphash always uses 128-bit keys */ +#define SIPHASH_KEY_SIZE 16 + +int siphash(const void *in, size_t inlen, const void *k, uint8_t *out, + size_t outlen); + +#endif diff --git a/src/openvpn/siphash_reference.c b/src/openvpn/siphash_reference.c new file mode 100644 index 0000000..b21a86e --- /dev/null +++ b/src/openvpn/siphash_reference.c @@ -0,0 +1,224 @@ +/* + * SipHash reference C implementation + * + * Copyright 2012-2024 JP Aumasson + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +/* Note: the reference implementation is also available under CC0 license + * (dual licensed) we included the MIT license here since it is shorter */ + +#include "siphash.h" +#include +#include +#include + +/* default: SipHash-2-4 */ +#ifndef cROUNDS +#define cROUNDS 2 +#endif +#ifndef dROUNDS +#define dROUNDS 4 +#endif + +#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b)))) + +#define U32TO8_LE(p, v) \ + (p)[0] = (uint8_t)((v)); \ + (p)[1] = (uint8_t)((v) >> 8); \ + (p)[2] = (uint8_t)((v) >> 16); \ + (p)[3] = (uint8_t)((v) >> 24); + +#define U64TO8_LE(p, v) \ + U32TO8_LE((p), (uint32_t)((v))); \ + U32TO8_LE((p) + 4, (uint32_t)((v) >> 32)); + +#define U8TO64_LE(p) \ + (((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) \ + | ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) \ + | ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) \ + | ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56)) + +#define SIPROUND \ + do \ + { \ + v0 += v1; \ + v1 = ROTL(v1, 13); \ + v1 ^= v0; \ + v0 = ROTL(v0, 32); \ + v2 += v3; \ + v3 = ROTL(v3, 16); \ + v3 ^= v2; \ + v0 += v3; \ + v3 = ROTL(v3, 21); \ + v3 ^= v0; \ + v2 += v1; \ + v1 = ROTL(v1, 17); \ + v1 ^= v2; \ + v2 = ROTL(v2, 32); \ + } while (0) + +#ifdef DEBUG_SIPHASH +#include + +#define TRACE \ + do \ + { \ + printf("(%3zu) v0 %016" PRIx64 "\n", inlen, v0); \ + printf("(%3zu) v1 %016" PRIx64 "\n", inlen, v1); \ + printf("(%3zu) v2 %016" PRIx64 "\n", inlen, v2); \ + printf("(%3zu) v3 %016" PRIx64 "\n", inlen, v3); \ + } while (0) +#else /* ifdef DEBUG_SIPHASH */ +#define TRACE +#endif + +/* + * Computes a SipHash value + * in: pointer to input data (read-only) + * inlen: input data length in bytes (any size_t value) + * k: pointer to the key data (read-only), must be 16 bytes + * out: pointer to output data (write-only), outlen bytes must be allocated + * outlen: length of the output in bytes, must be 8 or 16 + */ +int +siphash(const void *in, const size_t inlen, const void *k, uint8_t *out, + const size_t outlen) +{ + const unsigned char *ni = (const unsigned char *)in; + const unsigned char *kk = (const unsigned char *)k; + + assert((outlen == 8) || (outlen == 16)); + uint64_t v0 = UINT64_C(0x736f6d6570736575); + uint64_t v1 = UINT64_C(0x646f72616e646f6d); + uint64_t v2 = UINT64_C(0x6c7967656e657261); + uint64_t v3 = UINT64_C(0x7465646279746573); + uint64_t k0 = U8TO64_LE(kk); + uint64_t k1 = U8TO64_LE(kk + 8); + uint64_t m; + int i; + const unsigned char *end = ni + inlen - (inlen % sizeof(uint64_t)); + const int left = inlen & 7; + uint64_t b = ((uint64_t)inlen) << 56; + v3 ^= k1; + v2 ^= k0; + v1 ^= k1; + v0 ^= k0; + + if (outlen == 16) + { + v1 ^= 0xee; + } + + for (; ni != end; ni += 8) + { + m = U8TO64_LE(ni); + v3 ^= m; + + TRACE; + for (i = 0; i < cROUNDS; ++i) + { + SIPROUND; + } + + v0 ^= m; + } + + switch (left) + { + case 7: + b |= ((uint64_t)ni[6]) << 48; + + /* FALLTHRU */ + case 6: + b |= ((uint64_t)ni[5]) << 40; + + /* FALLTHRU */ + case 5: + b |= ((uint64_t)ni[4]) << 32; + + /* FALLTHRU */ + case 4: + b |= ((uint64_t)ni[3]) << 24; + + /* FALLTHRU */ + case 3: + b |= ((uint64_t)ni[2]) << 16; + + /* FALLTHRU */ + case 2: + b |= ((uint64_t)ni[1]) << 8; + + /* FALLTHRU */ + case 1: + b |= ((uint64_t)ni[0]); + break; + + case 0: + break; + } + + v3 ^= b; + + TRACE; + for (i = 0; i < cROUNDS; ++i) + { + SIPROUND; + } + + v0 ^= b; + + if (outlen == 16) + { + v2 ^= 0xee; + } + else + { + v2 ^= 0xff; + } + + TRACE; + for (i = 0; i < dROUNDS; ++i) + { + SIPROUND; + } + + b = v0 ^ v1 ^ v2 ^ v3; + U64TO8_LE(out, b); + + if (outlen == 8) + { + return 0; + } + + v1 ^= 0xdd; + + TRACE; + for (i = 0; i < dROUNDS; ++i) + { + SIPROUND; + } + + b = v0 ^ v1 ^ v2 ^ v3; + U64TO8_LE(out + 8, b); + + return 0; +}