From patchwork Fri Jan 5 19:09:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10146987 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 E0BE760134 for ; Fri, 5 Jan 2018 19:11:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 504E523B24 for ; Fri, 5 Jan 2018 19:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4409B27F4B; Fri, 5 Jan 2018 19:11:29 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 D613823B24 for ; Fri, 5 Jan 2018 19:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752514AbeAETL1 (ORCPT ); Fri, 5 Jan 2018 14:11:27 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:40190 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752231AbeAETLZ (ORCPT ); Fri, 5 Jan 2018 14:11:25 -0500 Received: by mail-io0-f195.google.com with SMTP id v30so6773201iov.7 for ; Fri, 05 Jan 2018 11:11:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GJDnqo7zkdqUq04sv2M2zhyR7pJef7ydu1yZMT63a1o=; b=oJ6JUPDeNlR93Vuoda+bUVHVoPRsTDevMUwRpGBT4/2g0PZn+8Q5YeedPvVUPAHU4V DsQvzF+9TnlqeBbi39jSncB07dMISEOIZ9MvB7twaKMDaqQvDOLJ2qDRCXJQ5Y0OHjXp EvdPqNZu847NW0hPjqiYCz3xDEYoDTUS1Pb212od/JEX+UiukXPQTi7bvpZ2arjgBOZo yj2Oq3D1IuFxcz4mMybV63rDVaqlR+/ys5lAHtICegcCuPZKsbYjTD7K4MYvBm/af//9 7v3JabReRFptMYQhkfpqWPm5lZsjQH4/l2qbC8ssNsvmh6j+rmmVet2n5xxMF+W+Zt+R t9Xg== 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=GJDnqo7zkdqUq04sv2M2zhyR7pJef7ydu1yZMT63a1o=; b=gqMOdT9yC306O0eKErrAy5qFKBKgD/9KSpyQicGRYlv8YoJbzWoskdKesUVlAtRc2D 3hpyHrR1X76KjzToxiOxKJ0Rv/vmlDH6+X4ZCgfdnrcsTHzo7gQwdfTrzaxthYsf0ANy knAEGhzaAbN6+aT11AhDcnD59Lqy0d+m/241kVA9/A7t+IE1d0vMf0Cs5aX1rIm8CBP5 KddrtxLUNAW28bqGz/TH7o3et7P2LLhTp6gcSc/Mq7UQCdHjr9OKFYY0chU1Fix7YI/z tL0nFTP2XhaDcuh7i4zgNjg/+xoOPAEFX0vBLek8dvMRCvWR0c1BTrHRtsF+SvlwTfvm jPHg== X-Gm-Message-State: AKwxytebDZbtXHgb30pYiwps0kqb9ZYzmkD04ZC518qR5VQ+ZEYJ3Ax5 07uFTevkeMNzhjcLMyQ8HRgM6s1f X-Google-Smtp-Source: ACJfBosM++iI10PWavPUMX9K53Usy1tapgJkSVPvXw47bxW07ywOpVzKzynPSwWNHvehS1ReYuFijw== X-Received: by 10.107.12.36 with SMTP id w36mr4367568ioi.291.1515179484784; Fri, 05 Jan 2018 11:11:24 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.175.88]) by smtp.gmail.com with ESMTPSA id o67sm4012506ioe.10.2018.01.05.11.11.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Jan 2018 11:11:24 -0800 (PST) From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: Herbert Xu , "David S . Miller" , Eric Biggers Subject: [PATCH v2 2/3] crypto: salsa20 - export generic helpers Date: Fri, 5 Jan 2018 11:09:58 -0800 Message-Id: <20180105190959.89682-3-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.0.rc0.223.g4a4ac83678-goog In-Reply-To: <20180105190959.89682-1-ebiggers3@gmail.com> References: <20180105190959.89682-1-ebiggers3@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Export the Salsa20 constants, transform context, and initialization functions so that they can be reused by the x86 implementation. Signed-off-by: Eric Biggers --- crypto/salsa20_generic.c | 20 +++++++------------- include/crypto/salsa20.h | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 include/crypto/salsa20.h diff --git a/crypto/salsa20_generic.c b/crypto/salsa20_generic.c index 8c77bc78a09f..5074006a56c3 100644 --- a/crypto/salsa20_generic.c +++ b/crypto/salsa20_generic.c @@ -21,17 +21,9 @@ #include #include +#include #include -#define SALSA20_IV_SIZE 8 -#define SALSA20_MIN_KEY_SIZE 16 -#define SALSA20_MAX_KEY_SIZE 32 -#define SALSA20_BLOCK_SIZE 64 - -struct salsa20_ctx { - u32 initial_state[16]; -}; - static void salsa20_block(u32 *state, __le32 *stream) { u32 x[16]; @@ -101,15 +93,16 @@ static void salsa20_docrypt(u32 *state, u8 *dst, const u8 *src, } } -static void salsa20_init(u32 *state, const struct salsa20_ctx *ctx, +void crypto_salsa20_init(u32 *state, const struct salsa20_ctx *ctx, const u8 *iv) { memcpy(state, ctx->initial_state, sizeof(ctx->initial_state)); state[6] = get_unaligned_le32(iv + 0); state[7] = get_unaligned_le32(iv + 4); } +EXPORT_SYMBOL_GPL(crypto_salsa20_init); -static int salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key, +int crypto_salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keysize) { static const char sigma[16] = "expand 32-byte k"; @@ -150,6 +143,7 @@ static int salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key, return 0; } +EXPORT_SYMBOL_GPL(crypto_salsa20_setkey); static int salsa20_crypt(struct skcipher_request *req) { @@ -161,7 +155,7 @@ static int salsa20_crypt(struct skcipher_request *req) err = skcipher_walk_virt(&walk, req, true); - salsa20_init(state, ctx, walk.iv); + crypto_salsa20_init(state, ctx, walk.iv); while (walk.nbytes > 0) { unsigned int nbytes = walk.nbytes; @@ -189,7 +183,7 @@ static struct skcipher_alg alg = { .max_keysize = SALSA20_MAX_KEY_SIZE, .ivsize = SALSA20_IV_SIZE, .chunksize = SALSA20_BLOCK_SIZE, - .setkey = salsa20_setkey, + .setkey = crypto_salsa20_setkey, .encrypt = salsa20_crypt, .decrypt = salsa20_crypt, }; diff --git a/include/crypto/salsa20.h b/include/crypto/salsa20.h new file mode 100644 index 000000000000..19ed48aefc86 --- /dev/null +++ b/include/crypto/salsa20.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Common values for the Salsa20 algorithm + */ + +#ifndef _CRYPTO_SALSA20_H +#define _CRYPTO_SALSA20_H + +#include + +#define SALSA20_IV_SIZE 8 +#define SALSA20_MIN_KEY_SIZE 16 +#define SALSA20_MAX_KEY_SIZE 32 +#define SALSA20_BLOCK_SIZE 64 + +struct crypto_skcipher; + +struct salsa20_ctx { + u32 initial_state[16]; +}; + +void crypto_salsa20_init(u32 *state, const struct salsa20_ctx *ctx, + const u8 *iv); +int crypto_salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key, + unsigned int keysize); + +#endif /* _CRYPTO_SALSA20_H */