From patchwork Wed Dec 14 00:16:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 9473493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B73456021C for ; Wed, 14 Dec 2016 00:17:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9ADE286C9 for ; Wed, 14 Dec 2016 00:17:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E274286CC; Wed, 14 Dec 2016 00:17:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id D8095286C9 for ; Wed, 14 Dec 2016 00:17:27 +0000 (UTC) Received: (qmail 18301 invoked by uid 550); 14 Dec 2016 00:17:24 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 17993 invoked from network); 14 Dec 2016 00:17:20 -0000 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=nM97 WCR0sQnYg/d5krkjMrkZhks=; b=AxV5XGqj8gjovHgVTdG4SD02Is6LIwxGmbg9 7MOYQ3u6JJOog8pHTT76j/8WGLBSF/VsiN4t3uvPZ7ZCUeMuZNRo521/wn8VEIwA GquGo7zhX8Ke2vvjaxQ5447gJ7qZPdxc4O+eMKuse6xV73FAX42Os1vYFFpKDMc/ rKYju+VQUx1xWCPQoIAIryBfqcDPYVrw5zOSX569RBTbX79nku7ScXZX18EAEFr+ nDwh3to0jGTPV5FVh4A7r67h6sy7k33+vAxS5vq7EgR0ac10fStqO4ZlWLQOST6X ysZBt/Su23pmBzSbAi/MxYgJaSH0FcuiE5bU8UzE8VBiwWx23g== From: "Jason A. Donenfeld" To: Netdev , David Miller , Linus Torvalds , "kernel-hardening@lists.openwall.com" , LKML , George Spelvin , Scott Bauer , Andi Kleen , Andy Lutomirski , Greg KH , Eric Biggers Cc: "Jason A. Donenfeld" Date: Wed, 14 Dec 2016 01:16:55 +0100 Message-Id: <20161214001656.19388-2-Jason@zx2c4.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161214001656.19388-1-Jason@zx2c4.com> References: <20161214001656.19388-1-Jason@zx2c4.com> Subject: [kernel-hardening] [PATCH 2/3] siphash: add convenience functions for jhash converts X-Virus-Scanned: ClamAV using ClamSMTP Many jhash users currently rely on the Nwords functions. In order to make transitions to siphash fit something people already know about, we provide analog functions here. This also winds up being nice for the networking stack, where hashing 32-bit fields is common. Signed-off-by: Jason A. Donenfeld --- include/linux/siphash.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/include/linux/siphash.h b/include/linux/siphash.h index 6623b3090645..1391054c4c29 100644 --- a/include/linux/siphash.h +++ b/include/linux/siphash.h @@ -17,4 +17,37 @@ enum siphash_lengths { u64 siphash24(const u8 *data, size_t len, const u8 key[SIPHASH24_KEY_LEN]); +static inline u64 siphash24_1word(const u32 a, const u8 key[SIPHASH24_KEY_LEN]) +{ + return siphash24((u8 *)&a, sizeof(a), key); +} + +static inline u64 siphash24_2words(const u32 a, const u32 b, const u8 key[SIPHASH24_KEY_LEN]) +{ + const struct { + u32 a; + u32 b; + } __packed combined = { + .a = a, + .b = b + }; + + return siphash24((const u8 *)&combined, sizeof(combined), key); +} + +static inline u64 siphash24_3words(const u32 a, const u32 b, const u32 c, const u8 key[SIPHASH24_KEY_LEN]) +{ + const struct { + u32 a; + u32 b; + u32 c; + } __packed combined = { + .a = a, + .b = b, + .c = c + }; + + return siphash24((const u8 *)&combined, sizeof(combined), key); +} + #endif /* _LINUX_SIPHASH_H */