Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4099502imm; Mon, 17 Sep 2018 08:11:09 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb6VkamSUJsr5DgAeD8fS/K+7DqqAJcobJ5mZ+QoXT5RMSoCzxPwkwuMDuB9GwWjJpmNaCT X-Received: by 2002:a62:59d5:: with SMTP id k82-v6mr26165589pfj.143.1537197069199; Mon, 17 Sep 2018 08:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537197069; cv=none; d=google.com; s=arc-20160816; b=jNK82VVBDq1VSVaK5hd0yxynq5r5EEIq9w2T2qsOK12jgNM4k8uj35iaj23ARM/GP0 PLmNLnKhxlgh2Qx7qp7Rk7yLZ9QLbPfKpyFJ8RtP4iRw732nApTkIXdOcVkBwLxq6YKK d4us9nVFQ8XnFL87cwtdsQ31cW+qRBWa6UN2iGEalk3oicKv2ZYOo86blx82Nuhs8qdK cA1WTd9H8hy2NZ6hCeVKl5o7iXBy2iuymNHsjMKGFPC7nzPuwbk+R9SlY5pFV1+gGuHU 31lPOPJbK2590fdZ5HI7KdZEZi93D4woYmAkXuXO2wpX5yyuOj24MVg30F6dbiBI+3Hx xWfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id :in-reply-to:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=lsWZ0ancngmtxX1n3Fse+Ouak7Qymqi/CgLF9OkT1/Q=; b=Fybl4cNiESqtDxsvqHgRjO8gidn6COn/1qgcq9HQF3+5FCccxlz0weyHG8gDKikXqZ ylbL1aMue974EkOray/MSt5DNZv6pK9H6bkCn0w42MkM3SqgKId2FHuBEPGNDFjSzqtE jcKEHVe90StV9OzGObRJdHHjpyEGyD+lPtEGwS8o+xggnCrEr1IlXP3Y23dGEVZn7byK TxsmxWMXM2r8iYumelO8JEFHLjUE2XUbK0JVFJnqpY3zIXRARhBxAhh6g1qj/wiGuQX3 U+9On1t78zpriqS8HOhBVlvvyUMniH3X/cERg7IA44Qa3pXyztLCVDZAPaS4CVciTLyt GNbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=AAQ5uCWk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18-v6si14996044pgi.132.2018.09.17.08.10.30; Mon, 17 Sep 2018 08:11:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=AAQ5uCWk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729338AbeIQUh7 (ORCPT + 99 others); Mon, 17 Sep 2018 16:37:59 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:59201 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729326AbeIQUh6 (ORCPT ); Mon, 17 Sep 2018 16:37:58 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180917151012euoutp02dd8820f51d37f0514ba0dface302f8ef~VOInxVWj71481614816euoutp02K for ; Mon, 17 Sep 2018 15:10:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180917151012euoutp02dd8820f51d37f0514ba0dface302f8ef~VOInxVWj71481614816euoutp02K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1537197012; bh=lsWZ0ancngmtxX1n3Fse+Ouak7Qymqi/CgLF9OkT1/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AAQ5uCWk00cG85kVqA0GLLQFJ6+lEBV6fR2p1Sk0emekRc2nXmNE9wrn9CdbWkxaq JDcW/VFbjYKTAvlJsXhGI6Sa45DazC8x/eK89TteWKn0yrks1zXgA7AW0o06fbMEg6 xJYiPgAuRegnHLPxsXUbXR4QgG6+3f6aA6cw3ne4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180917151012eucas1p115f7426d579c26f975eec3268d531fdd~VOInKw63A2050920509eucas1p1v; Mon, 17 Sep 2018 15:10:12 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id A9.7C.04441.3D3CF9B5; Mon, 17 Sep 2018 16:10:11 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20180917151011eucas1p274a1407a02081b49aa03da85cc9aec4c~VOImIjh2C1107511075eucas1p2w; Mon, 17 Sep 2018 15:10:11 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20180917151010eusmtrp1a5559102b1fa7f04b069f28e58da658f~VOIl2FFqs3069130691eusmtrp1u; Mon, 17 Sep 2018 15:10:10 +0000 (GMT) X-AuditID: cbfec7f2-5e3ff70000001159-13-5b9fc3d339aa Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 35.48.04284.2D3CF9B5; Mon, 17 Sep 2018 16:10:10 +0100 (BST) Received: from AMDC2034.DIGITAL.local (unknown [106.120.51.41]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20180917151010eusmtip221a9e59f473c61164032fe2517f11788~VOIlbOU-F2369023690eusmtip2l; Mon, 17 Sep 2018 15:10:10 +0000 (GMT) From: Christoph Manszewski To: linux-crypto@vger.kernel.org Cc: Christoph Manszewski , Krzysztof Kozlowski , Vladimir Zapolskiy , Kamil Konieczny , Herbert Xu , "David S. Miller" , linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartlomiej Zolnierkiewicz Subject: [PATCH v2 4/4] crypto: s5p-sss: Add aes-ctr support Date: Mon, 17 Sep 2018 17:09:30 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537196970-5987-1-git-send-email-c.manszewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAKsWRmVeSWpSXmKPExsWy7djPc7qXD8+PNrjeaG2xccZ6Vovju5cy Wsw538Ji0f1KxqJv339Gi/PnN7Bb3L/3k8ni8q45bBYzzu9jsvj/q5nZgctjy8qbTB7bDqh6 bFrVyebxb+EUFo+D7/YwefRtWcXo8XmTXAB7FJdNSmpOZllqkb5dAlfGxbmzWArWqFQ0Ny1g amC8INvFyMkhIWAi8erXY/YuRi4OIYEVjBKLpi5hA0kICXxhlJjVyAKR+MwocWnrbWaYjntL PjBDJJYzSkw93MUO1/FrqiWIzSZgKnH77iegSRwcIgIKEvO+6oCEmQVamCV+reYEsYUFbCRu tr9kBLFZBFQlPp95zA4xX07i5rlOsF2cAh4S7//Mgop3s0v8fykOYvMKlEl8bWmCirtIPHp9 nQXCFpZ4dXwLVFxG4vTkHrAHJASaGSVufbnGCuFMYJQ4uLoLqsNaYtONV0wghzILaEqs36UP EXaUWNXUwQoSlhDgk7jxVhDifj6JSdumM0OEeSU62oQgqtUkXm/Zwgaz9sXnr4wQtofElSNH oUE1m1Fi7Y5NjBMY5WchLFvAyLiKUTy1tDg3PbXYMC+1XK84Mbe4NC9dLzk/dxMjMJ2c/nf8 0w7G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W4L3ku19ipnnG3gGd/wDOfKrayWwLyjz5p8v1f rDrNTubdugk6f9dzcusvUTs83crhzUT3rUosxRmJhlrMRcWJANSOd1eGAgAA Message-Id: <20180917151011eucas1p274a1407a02081b49aa03da85cc9aec4c~VOImIjh2C1107511075eucas1p2w@eucas1p2.samsung.com> X-CMS-MailID: 20180917151011eucas1p274a1407a02081b49aa03da85cc9aec4c X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20180917151011eucas1p274a1407a02081b49aa03da85cc9aec4c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180917151011eucas1p274a1407a02081b49aa03da85cc9aec4c References: <1537196970-5987-1-git-send-email-c.manszewski@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for aes counter(ctr) block cipher mode of operation for Exynos Hardware. In contrast to ecb and cbc modes, aes-ctr allows encyption/decryption for request sizes not being a multiple of 16(bytes). Hardware requires block sizes being a multiple of 16(bytes). In order to achieve this, copy request source and destination memory, and align it's size to 16. That way hardware processes additional bytes, that are omitted when copying the result back to its original destination. Tested on Odroid-U3 with Exynos 4412 CPU, kernel 4.19-rc2 with crypto run-time self test testmgr. Signed-off-by: Christoph Manszewski Reviewed-by: Krzysztof Kozlowski --- drivers/crypto/s5p-sss.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index ba8f2e2ea88f..0064be0e3941 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -1813,7 +1813,7 @@ static struct ahash_alg algs_sha1_md5_sha256[] = { }; static void s5p_set_aes(struct s5p_aes_dev *dev, - const u8 *key, const u8 *iv, + const u8 *key, const u8 *iv, const u8 *ctr, unsigned int keylen) { void __iomem *keystart; @@ -1821,6 +1821,9 @@ static void s5p_set_aes(struct s5p_aes_dev *dev, if (iv) memcpy_toio(dev->aes_ioaddr + SSS_REG_AES_IV_DATA(0), iv, 0x10); + if (ctr) + memcpy_toio(dev->aes_ioaddr + SSS_REG_AES_CNT_DATA(0), ctr, 0x10); + if (keylen == AES_KEYSIZE_256) keystart = dev->aes_ioaddr + SSS_REG_AES_KEY_DATA(0); else if (keylen == AES_KEYSIZE_192) @@ -1902,8 +1905,9 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) u32 aes_control; unsigned long flags; int err; - u8 *iv; + u8 *iv, *ctr; + /* This sets bit [13:12] to 00, which selects 128-bit counter */ aes_control = SSS_AES_KEY_CHANGE_MODE; if (mode & FLAGS_AES_DECRYPT) aes_control |= SSS_AES_MODE_DECRYPT; @@ -1911,11 +1915,14 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) { aes_control |= SSS_AES_CHAIN_MODE_CBC; iv = req->info; + ctr = NULL; } else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) { aes_control |= SSS_AES_CHAIN_MODE_CTR; - iv = req->info; + iv = NULL; + ctr = req->info; } else { iv = NULL; /* AES_ECB */ + ctr = NULL; } if (dev->ctx->keylen == AES_KEYSIZE_192) @@ -1947,7 +1954,7 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) goto outdata_error; SSS_AES_WRITE(dev, AES_CONTROL, aes_control); - s5p_set_aes(dev, dev->ctx->aes_key, iv, dev->ctx->keylen); + s5p_set_aes(dev, dev->ctx->aes_key, iv, ctr, dev->ctx->keylen); s5p_set_dma_indata(dev, dev->sg_src); s5p_set_dma_outdata(dev, dev->sg_dst); @@ -2025,7 +2032,8 @@ static int s5p_aes_crypt(struct ablkcipher_request *req, unsigned long mode) struct s5p_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm); struct s5p_aes_dev *dev = ctx->dev; - if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE)) { + if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE) && + ((mode & FLAGS_AES_MODE_MASK) != FLAGS_AES_CTR)) { dev_err(dev->dev, "request size is not exact amount of AES blocks\n"); return -EINVAL; } @@ -2072,6 +2080,11 @@ static int s5p_aes_cbc_decrypt(struct ablkcipher_request *req) return s5p_aes_crypt(req, FLAGS_AES_DECRYPT | FLAGS_AES_CBC); } +static int s5p_aes_ctr_crypt(struct ablkcipher_request *req) +{ + return s5p_aes_crypt(req, FLAGS_AES_CTR); +} + static int s5p_aes_cra_init(struct crypto_tfm *tfm) { struct s5p_aes_ctx *ctx = crypto_tfm_ctx(tfm); @@ -2126,6 +2139,28 @@ static struct crypto_alg algs[] = { .decrypt = s5p_aes_cbc_decrypt, } }, + { + .cra_name = "ctr(aes)", + .cra_driver_name = "ctr-aes-s5p", + .cra_priority = 100, + .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | + CRYPTO_ALG_ASYNC | + CRYPTO_ALG_KERN_DRIVER_ONLY, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct s5p_aes_ctx), + .cra_alignmask = 0x0f, + .cra_type = &crypto_ablkcipher_type, + .cra_module = THIS_MODULE, + .cra_init = s5p_aes_cra_init, + .cra_u.ablkcipher = { + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .ivsize = AES_BLOCK_SIZE, + .setkey = s5p_aes_setkey, + .encrypt = s5p_aes_ctr_crypt, + .decrypt = s5p_aes_ctr_crypt, + } + }, }; static int s5p_aes_probe(struct platform_device *pdev) -- 2.7.4