Received: by 10.223.185.116 with SMTP id b49csp979066wrg; Wed, 14 Feb 2018 09:43:21 -0800 (PST) X-Google-Smtp-Source: AH8x227/E5FNp0astJeQouGn6GrKpLxfDH978VOHzTpPgNcQFs0r+l2Tt0koiaG39MZ8Ymsx3YbS X-Received: by 10.99.150.2 with SMTP id c2mr4627354pge.424.1518630201043; Wed, 14 Feb 2018 09:43:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518630201; cv=none; d=google.com; s=arc-20160816; b=vQJdkTGGeCVWWGUoBqpZ8NgoKNzxOJQv/1fhRql8Y0jD0AbMoO4M6+JRNpatjMclfg B7AxAJb6MZmUCScLukJJkiKlbFEKLipp5HZndoT71y5xElQh1kueRspTRKZolZWtksXC wPjax+c5pUHU78yx8xwSg1oDKKne8VmQdRfOs6a6TodYNhF7e0E/dZnXrb6VTuulc5wr AB/TMPyry/WVza/Ay0xtVSqkkmITAv+QZLbYWS7TldNgCBkYpLvZmlkOH/hAsR4QVHfu V4aY406SkLAGPhyhRBSfWeoomHhCy4PItL+o3XUSRYneHWBw9VoKYNeXVjO1quhe72Mf BnIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature:arc-authentication-results; bh=z98Grxs0qP1fuT5jy/NmuRoDvF13SoTqkh12z/1QVbU=; b=0OAgAfmGRj1K3ifYNYeEGcSZ2J4T4sRmq+Vdso5Zl7nkhec6/dhotbj/HAHfwB5ggL E7Kz5JsYayHAYhhHmWj1MrdpGjy3mWSvGMsXhdfRBeJEg898Pi2UkKkNSDq6FhUfKPLn 8sR4KivKtkiyeq/fh9Z4t635whifi3b5rzKmdSU5UrnQcDl26Au5x2eJmKC5X5qM4HJ3 ZL6mViM16NU+EeOAAIYBIpGqIimyLKhZAxgpyGChSXwSLYlHkQJNw7IOh9ts8EM9cI+Q gAEIQPKuzfm0yFIhkVjg9J74/Mch15cWf8H1CjDdEBQztAFpxZzHrtvKeTeuI/GRsX/A z29w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=H134ZnAE; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=jZ4p/FDO; 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=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1-v6si1625097plb.680.2018.02.14.09.43.06; Wed, 14 Feb 2018 09:43:21 -0800 (PST) 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=@fb.com header.s=facebook header.b=H134ZnAE; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=jZ4p/FDO; 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=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161502AbeBNRlu (ORCPT + 99 others); Wed, 14 Feb 2018 12:41:50 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:53384 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161361AbeBNRlp (ORCPT ); Wed, 14 Feb 2018 12:41:45 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1EHeXSI012277; Wed, 14 Feb 2018 09:41:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=facebook; bh=z98Grxs0qP1fuT5jy/NmuRoDvF13SoTqkh12z/1QVbU=; b=H134ZnAEJ7xesGRavKvOixruK/WnCQv7xVdJHwGPWZq3CfJSpibNCMwVT6LGemdywnJO exdZY3U+3QU+UUwprc1WJzneVfPe1D1kp3qMYyQEeydlIipIrqwxWi4VPIV3tIMzQR9g 2h9kBIxM8EmDgNW7bbSlGa6QlnHLa0hVOIs= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2g4rmq8vr8-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 14 Feb 2018 09:41:26 -0800 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.25) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 14 Feb 2018 12:41:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=z98Grxs0qP1fuT5jy/NmuRoDvF13SoTqkh12z/1QVbU=; b=jZ4p/FDOXMR+tHi1rmIGE4/Nx5M6J3zjGpUEkg3WnVdHGeJkWpnWc22PV8kMZ04jvenILp8A4LWFJv9KoxrBcgfY5jV8GijM16LfCkCkuSah0SwPM5kOt4g+N4lKwgZlDITcNuwCZD7bVJ02LXG85lRV0IOGTRHXmVKDbvyDQQw= Received: from localhost (2620:10d:c090:180::622a) by CY4PR15MB1752.namprd15.prod.outlook.com (10.174.53.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Wed, 14 Feb 2018 17:41:04 +0000 Date: Wed, 14 Feb 2018 09:40:58 -0800 From: Dave Watson To: Herbert Xu , Junaid Shahid , Steffen Klassert , CC: "David S. Miller" , Hannes Frederic Sowa , Tim Chen , Sabrina Dubroca , , Stephan Mueller , Ilya Lesokhin Subject: [PATCH v2 14/14] x86/crypto: aesni: Update aesni-intel_glue to use scatter/gather Message-ID: <20180214174058.GA62239@davejwatson-mba> References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.0 (2016-04-01) X-Originating-IP: [2620:10d:c090:180::622a] X-ClientProxiedBy: BN6PR06CA0007.namprd06.prod.outlook.com (10.175.123.145) To CY4PR15MB1752.namprd15.prod.outlook.com (10.174.53.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: be7f7d12-edb5-46b0-8687-08d573d21f63 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020);SRVR:CY4PR15MB1752; X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1752;3:8Q8EgfPTXSKOan4G8AgrDDjRisbj6e/7yNpUAcnpDL4O3nq4axzgYb/TqAARTrbnd37caN/bhOTsAMTYVSBZIWKVoMvKwf8DGnVU7fctYp8CX+4I34RU4nt3bBewsfko9VYZXK44fmv/swcXH/gMHvLs8bSr2ay3cvB37uMC03gMYB0wDJ3vyfY+LeqlZj0unS9GGqz90DpudzyAa/gjUvvUmAwmOlLmXh9LVEIIMgrq2+1NtBWxv264SP3vHp3L;25:RS8sKCeiCS4Fl1DoZzjwEjMhpCL8ATk+0UEfjB0zR7s1gdsnY72RAH/rbgCMw+B12bDTcK+sS8G/i9gRWtu9BX4n2DWv+6pdAuOvr+sTiFecglocxm6gBjA47G59urE/N8vYYSf16lULnUEfgSthSiZjnnHDPlP8DmCSnhoWMR/802b9Zf7zqF1GNIyvnoGHW8UJFNBK6oyf6xNqRqShjXQwMRpcPwZc8p9DQfPInkJ3vmBHl7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YuAWF0IDJHRLoqmYq9Yc/hn4Jx3w03zFTjrHJm2uKDLKKRpllegKQZUCSAjijIeRiWzSCq+dq0MbrRqWcGLwIP46kahi4Z2uc2YynPQeAF7TJ/KsRjf9uTA4rFeGVr4H7eLaJhjNpFSJuy+TShntS6NRO8JOutccmic7JRYBWL8N8BlQ6clQPFMIEmigDkcfwccaGq8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484)(266576461109395); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(3231101)(11241501184)(944501161)(6041288)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:CY4PR15MB1752;BCL:0;PCL:0;RULEID:;SRVR:CY4PR15MB1752; X-Forefront-PRVS: 0583A86C08 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(7916004)(376002)(39860400002)(39380400002)(396003)(346002)(366004)(199004)(189003)(305945005)(59450400001)(6496006)(52116002)(9686003)(52396003)(83506002)(54906003)(16586007)(58126008)(76176011)(386003)(33896004)(86362001)(16526019)(6486002)(8936002)(316002)(50466002)(97736004)(76506005)(7416002)(110136005)(81166006)(105586002)(53936002)(186003)(68736007)(4326008)(47776003)(1076002)(2950100002)(8676002)(33716001)(6666003)(81156014)(106356001)(2906002)(25786009)(23726003)(33656002)(15650500001)(5660300001)(6116002)(478600001)(7736002)(18370500001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR15MB1752;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR15MB1752;23:f5VwGq6kMeGNBn1HJRNDkigTgSt0sE8fmGNRg+BIU?= =?us-ascii?Q?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24:sSteVed0s3ljaqB/5FJ4cNVWQv1Mo0u7K6jvZER0gJQBp6lB4RlHvFT9Zeh/xH23hP20NocSVRHhUvrt5QcOXT7/fF1taDmD3cCKDZ/Zj3M=;7:JemAm4QrybYxBIDMLw7krvkGGsQMusIAclJFaIWEu0Ndv4ogMrRkrEYJrGS2SbdbNnwxalKZbMRYtre7u8GAlaKYyt0i/o61yOU98DEIE61D4RAiJqUTI9LE2ui+CQ0cUB3ToahnQ2NGtT+FZ1NiZC5dBkm82JYHJdzUJxPRAUowzFnmadGyogqknZ7xMfbLqXlzv29ZqA3FBp2w30tNunQQyFl7y6OQm5f3r4uv8vltyDGqin9dMehRfBMvLRPF SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1752;20:FJJpBEIrJqaO1Gmm8toLAYBLfzMfWUBloKNGohGA0rAGvBDYJsxd52hvztnyIUlgphE4qR58KSDR1KGFlfS/6p3ywVTA1rNT9/6d/OFwcTInK3EpZZw0oR1ouqqNd1amNL0f8NEHPdCz9pzrXwI51ydnOlz05Ss0ubkNT5dkbnw= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2018 17:41:04.6610 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be7f7d12-edb5-46b0-8687-08d573d21f63 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1752 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-14_07:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add gcmaes_crypt_by_sg routine, that will do scatter/gather by sg. Either src or dst may contain multiple buffers, so iterate over both at the same time if they are different. If the input is the same as the output, iterate only over one. Currently both the AAD and TAG must be linear, so copy them out with scatterlist_map_and_copy. If first buffer contains the entire AAD, we can optimize and not copy. Since the AAD can be any size, if copied it must be on the heap. TAG can be on the stack since it is always < 16 bytes. Only the SSE routines are updated so far, so leave the previous gcmaes_en/decrypt routines, and branch to the sg ones if the keysize is inappropriate for avx, or we are SSE only. Signed-off-by: Dave Watson --- arch/x86/crypto/aesni-intel_glue.c | 133 +++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c index de986f9..acbe7e8 100644 --- a/arch/x86/crypto/aesni-intel_glue.c +++ b/arch/x86/crypto/aesni-intel_glue.c @@ -791,6 +791,127 @@ static int generic_gcmaes_set_authsize(struct crypto_aead *tfm, return 0; } +static int gcmaes_crypt_by_sg(bool enc, struct aead_request *req, + unsigned int assoclen, u8 *hash_subkey, + u8 *iv, void *aes_ctx) +{ + struct crypto_aead *tfm = crypto_aead_reqtfm(req); + unsigned long auth_tag_len = crypto_aead_authsize(tfm); + struct gcm_context_data data AESNI_ALIGN_ATTR; + struct scatter_walk dst_sg_walk = {}; + unsigned long left = req->cryptlen; + unsigned long len, srclen, dstlen; + struct scatter_walk assoc_sg_walk; + struct scatter_walk src_sg_walk; + struct scatterlist src_start[2]; + struct scatterlist dst_start[2]; + struct scatterlist *src_sg; + struct scatterlist *dst_sg; + u8 *src, *dst, *assoc; + u8 *assocmem = NULL; + u8 authTag[16]; + + if (!enc) + left -= auth_tag_len; + + /* Linearize assoc, if not already linear */ + if (req->src->length >= assoclen && req->src->length && + (!PageHighMem(sg_page(req->src)) || + req->src->offset + req->src->length < PAGE_SIZE)) { + scatterwalk_start(&assoc_sg_walk, req->src); + assoc = scatterwalk_map(&assoc_sg_walk); + } else { + /* assoc can be any length, so must be on heap */ + assocmem = kmalloc(assoclen, GFP_ATOMIC); + if (unlikely(!assocmem)) + return -ENOMEM; + assoc = assocmem; + + scatterwalk_map_and_copy(assoc, req->src, 0, assoclen, 0); + } + + src_sg = scatterwalk_ffwd(src_start, req->src, req->assoclen); + scatterwalk_start(&src_sg_walk, src_sg); + if (req->src != req->dst) { + dst_sg = scatterwalk_ffwd(dst_start, req->dst, req->assoclen); + scatterwalk_start(&dst_sg_walk, dst_sg); + } + + kernel_fpu_begin(); + aesni_gcm_init(aes_ctx, &data, iv, + hash_subkey, assoc, assoclen); + if (req->src != req->dst) { + while (left) { + src = scatterwalk_map(&src_sg_walk); + dst = scatterwalk_map(&dst_sg_walk); + srclen = scatterwalk_clamp(&src_sg_walk, left); + dstlen = scatterwalk_clamp(&dst_sg_walk, left); + len = min(srclen, dstlen); + if (len) { + if (enc) + aesni_gcm_enc_update(aes_ctx, &data, + dst, src, len); + else + aesni_gcm_dec_update(aes_ctx, &data, + dst, src, len); + } + left -= len; + + scatterwalk_unmap(src); + scatterwalk_unmap(dst); + scatterwalk_advance(&src_sg_walk, len); + scatterwalk_advance(&dst_sg_walk, len); + scatterwalk_done(&src_sg_walk, 0, left); + scatterwalk_done(&dst_sg_walk, 1, left); + } + } else { + while (left) { + dst = src = scatterwalk_map(&src_sg_walk); + len = scatterwalk_clamp(&src_sg_walk, left); + if (len) { + if (enc) + aesni_gcm_enc_update(aes_ctx, &data, + src, src, len); + else + aesni_gcm_dec_update(aes_ctx, &data, + src, src, len); + } + left -= len; + scatterwalk_unmap(src); + scatterwalk_advance(&src_sg_walk, len); + scatterwalk_done(&src_sg_walk, 1, left); + } + } + aesni_gcm_finalize(aes_ctx, &data, authTag, auth_tag_len); + kernel_fpu_end(); + + if (!assocmem) + scatterwalk_unmap(assoc); + else + kfree(assocmem); + + if (!enc) { + u8 authTagMsg[16]; + + /* Copy out original authTag */ + scatterwalk_map_and_copy(authTagMsg, req->src, + req->assoclen + req->cryptlen - + auth_tag_len, + auth_tag_len, 0); + + /* Compare generated tag with passed in tag. */ + return crypto_memneq(authTagMsg, authTag, auth_tag_len) ? + -EBADMSG : 0; + } + + /* Copy in the authTag */ + scatterwalk_map_and_copy(authTag, req->dst, + req->assoclen + req->cryptlen, + auth_tag_len, 1); + + return 0; +} + static int gcmaes_encrypt(struct aead_request *req, unsigned int assoclen, u8 *hash_subkey, u8 *iv, void *aes_ctx) { @@ -802,6 +923,12 @@ static int gcmaes_encrypt(struct aead_request *req, unsigned int assoclen, struct scatter_walk dst_sg_walk = {}; struct gcm_context_data data AESNI_ALIGN_ATTR; + if (((struct crypto_aes_ctx *)aes_ctx)->key_length != AES_KEYSIZE_128 || + aesni_gcm_enc_tfm == aesni_gcm_enc || + req->cryptlen < AVX_GEN2_OPTSIZE) { + return gcmaes_crypt_by_sg(true, req, assoclen, hash_subkey, iv, + aes_ctx); + } if (sg_is_last(req->src) && (!PageHighMem(sg_page(req->src)) || req->src->offset + req->src->length <= PAGE_SIZE) && @@ -868,6 +995,12 @@ static int gcmaes_decrypt(struct aead_request *req, unsigned int assoclen, struct gcm_context_data data AESNI_ALIGN_ATTR; int retval = 0; + if (((struct crypto_aes_ctx *)aes_ctx)->key_length != AES_KEYSIZE_128 || + aesni_gcm_enc_tfm == aesni_gcm_enc || + req->cryptlen < AVX_GEN2_OPTSIZE) { + return gcmaes_crypt_by_sg(false, req, assoclen, hash_subkey, iv, + aes_ctx); + } tempCipherLen = (unsigned long)(req->cryptlen - auth_tag_len); if (sg_is_last(req->src) && -- 2.9.5