From patchwork Fri Feb 3 19:25:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9555017 X-Patchwork-Delegate: johannes@sipsolutions.net 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 9C273602B7 for ; Fri, 3 Feb 2017 19:26:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 978BD26861 for ; Fri, 3 Feb 2017 19:26:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B5432815E; Fri, 3 Feb 2017 19:26:26 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 002B126861 for ; Fri, 3 Feb 2017 19:26:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752067AbdBCT0Y (ORCPT ); Fri, 3 Feb 2017 14:26:24 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:34231 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752012AbdBCT0W (ORCPT ); Fri, 3 Feb 2017 14:26:22 -0500 Received: by mail-wm0-f50.google.com with SMTP id 196so17449733wmm.1 for ; Fri, 03 Feb 2017 11:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ia1C1UW3GLYLySXjo0I9+iug7I/2Ok3GLTpLxDLzGBk=; b=FSHE85g0GZx+R7lgmkM33AdQ1wdbJ+81TVQGOLUN9mD23JpEkUUowxht8RFcLUIN35 lFRKKsyOcY8qe4odhLTFwBJC5kJQpVcgoqDJTd3i37PgWRYaHQJaQmUomkZ1JL4sBB2z e2hLxFDpbFLlloxMTrHdVnlLmMFX+YBblSYwI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ia1C1UW3GLYLySXjo0I9+iug7I/2Ok3GLTpLxDLzGBk=; b=uHiF2SwVDiHehuI1g28WAqw7456ttZgZdmMcz10HH356TPDDKP/dUjIwpxn+5tOtR9 8yrwhZCKuNbQkm09S7QN2BfI9oAHXRbMb9ueSdqNtM1E45sRGAFZW9lo0SZa82KvMP9Q 5xd8NgNQaBJTM12XjKqwSITo2g1MrJdahi+eD2mIij/S+S8kyBsvcdfLGRpg7LNHDVfy mXqctFsYFdIfCl78DiTlj0fna166HZ7rVS+P6+SAC9fY81xYfiMYgGZncRd0IPVchyVB 6ED9rq3cfTfLVEWmYJVlKhOcDPFrnxUXSjK6FeIV+g+e6SUhht2rX1VliATJGglzDZ2L 0dww== X-Gm-Message-State: AMke39mWshhEDaIP3FGlts0u36YC/vXMACYxzHZsUU0vBvu72vTd3yu8G+Q2DcQJxIHdEE+K X-Received: by 10.28.45.213 with SMTP id t204mr2781606wmt.113.1486149980942; Fri, 03 Feb 2017 11:26:20 -0800 (PST) Received: from localhost.localdomain ([197.130.95.80]) by smtp.gmail.com with ESMTPSA id 17sm46598030wru.16.2017.02.03.11.26.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Feb 2017 11:26:20 -0800 (PST) From: Ard Biesheuvel To: johannes@sipsolutions.net, linux-wireless@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org, jouni@qca.qualcomm.com, Ard Biesheuvel Subject: [RFC PATCH 1/2] mac80211: fils_aead: clone shared CMAC functions into private version Date: Fri, 3 Feb 2017 19:25:54 +0000 Message-Id: <1486149955-11825-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486149955-11825-1-git-send-email-ard.biesheuvel@linaro.org> References: <1486149955-11825-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before reworking the AES CMAC mac80211 code, clone the routines that it shares with the FILS AEAD driver into its own source file, and remove the external declaration from aes_cmac.h. This will allow us to carry over one user at a time from the open coded CMAC code to the crypto API. Signed-off-by: Ard Biesheuvel --- net/mac80211/aes_cmac.h | 4 -- net/mac80211/fils_aead.c | 68 ++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/net/mac80211/aes_cmac.h b/net/mac80211/aes_cmac.h index c827e1d5de8b..3702041f44fd 100644 --- a/net/mac80211/aes_cmac.h +++ b/net/mac80211/aes_cmac.h @@ -11,10 +11,6 @@ #include -void gf_mulx(u8 *pad); -void aes_cmac_vector(struct crypto_cipher *tfm, size_t num_elem, - const u8 *addr[], const size_t *len, u8 *mac, - size_t mac_len); struct crypto_cipher *ieee80211_aes_cmac_key_setup(const u8 key[], size_t key_len); void ieee80211_aes_cmac(struct crypto_cipher *tfm, const u8 *aad, diff --git a/net/mac80211/fils_aead.c b/net/mac80211/fils_aead.c index ecfdd97758a3..ec493e68957c 100644 --- a/net/mac80211/fils_aead.c +++ b/net/mac80211/fils_aead.c @@ -15,6 +15,74 @@ #include "aes_cmac.h" #include "fils_aead.h" +static void gf_mulx(u8 *pad) +{ + int i, carry; + + carry = pad[0] & 0x80; + for (i = 0; i < AES_BLOCK_SIZE - 1; i++) + pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7); + pad[AES_BLOCK_SIZE - 1] <<= 1; + if (carry) + pad[AES_BLOCK_SIZE - 1] ^= 0x87; +} + +static void aes_cmac_vector(struct crypto_cipher *tfm, size_t num_elem, + const u8 *addr[], const size_t *len, u8 *mac, + size_t mac_len) +{ + u8 cbc[AES_BLOCK_SIZE], pad[AES_BLOCK_SIZE]; + const u8 *pos, *end; + size_t i, e, left, total_len; + + memset(cbc, 0, AES_BLOCK_SIZE); + + total_len = 0; + for (e = 0; e < num_elem; e++) + total_len += len[e]; + left = total_len; + + e = 0; + pos = addr[0]; + end = pos + len[0]; + + while (left >= AES_BLOCK_SIZE) { + for (i = 0; i < AES_BLOCK_SIZE; i++) { + cbc[i] ^= *pos++; + if (pos >= end) { + e++; + pos = addr[e]; + end = pos + len[e]; + } + } + if (left > AES_BLOCK_SIZE) + crypto_cipher_encrypt_one(tfm, cbc, cbc); + left -= AES_BLOCK_SIZE; + } + + memset(pad, 0, AES_BLOCK_SIZE); + crypto_cipher_encrypt_one(tfm, pad, pad); + gf_mulx(pad); + + if (left || total_len == 0) { + for (i = 0; i < left; i++) { + cbc[i] ^= *pos++; + if (pos >= end) { + e++; + pos = addr[e]; + end = pos + len[e]; + } + } + cbc[left] ^= 0x80; + gf_mulx(pad); + } + + for (i = 0; i < AES_BLOCK_SIZE; i++) + pad[i] ^= cbc[i]; + crypto_cipher_encrypt_one(tfm, pad, pad); + memcpy(mac, pad, mac_len); +} + static int aes_s2v(struct crypto_cipher *tfm, size_t num_elem, const u8 *addr[], size_t len[], u8 *v) {