Received: by 10.223.185.116 with SMTP id b49csp1137374wrg; Wed, 14 Feb 2018 12:11:55 -0800 (PST) X-Google-Smtp-Source: AH8x227nwIjBhVAbGSWSh0STgbbQAOSMGU+B3viLy7l7GakW1PxsvU07BlePPAV2mDc1Panq6Hyz X-Received: by 2002:a17:902:8349:: with SMTP id z9-v6mr204635pln.164.1518639115397; Wed, 14 Feb 2018 12:11:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518639115; cv=none; d=google.com; s=arc-20160816; b=XAwgy23gRgAd+opAPhRfL3GG1I1gkxfL7I3EA2GJ8C2BIyMDYfkOrTIUGEQn0q7IUT ApVVdgFlM7f67k/NcD794ejNZqR1XW7GyjpTXoJWG37BQWDb65Jf64GSfMejL9Z0yCtO 3+y9s/SewfwSBrDaGaYDUWPzXbA3oS2L+nGsnVM7Sz90VuXbptFbfUWUrqltMk+AUdUQ FPNcnp5cPExKcDamN42n2HnJ28VX05WxBmgQSqrG7zAxHyPzkg9KD5TJTdS8E9P8F/rl kQ+I5QqBsSTd2lpH5SfCMXx693UuzbDpCE5hgOh7j+6652O0hSXjd6SGJeGwQhaJ6U7X dJNg== 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=dUHeKxNeAwdy4IKlu/l6rm0kXXAg/0qUHSjDNAIGgfY=; b=ARu6HZvgFZ5u35AI+rgopuIA/sLmgiCEue72aswN5LQte3EGLzfXKkq9AcOA6G4daj yFbOf8244vh1XQDpPrJpQZcWR03Oq5+DLjQlmf5wGbGphM1lXaHGQUjz0VPsDqGviOzb u3vqmEQ27k+a2ZYXDoFGznpD0+tJGcuHP5eOdBD4Aoy2Pnu8A4clwLhTlhl+aRGBdrog zWsNh2dQinA0RcPISWqCWQUeLYBCyTBFP+o/fzUYbFZ48hMf0tXrmoqXAY3D2JyhogBy j4BaEKbT0XOetkYQb1uQTChJsoNuex+mveWgQWjL/RppAhmnVlg0rYVhutVBBBOj+hGH aJqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=E6PjKcIo; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=b2zZzsrG; 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 h8si1775439pgr.716.2018.02.14.12.11.40; Wed, 14 Feb 2018 12:11:55 -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=E6PjKcIo; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=b2zZzsrG; 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 S1161461AbeBNRk7 (ORCPT + 99 others); Wed, 14 Feb 2018 12:40:59 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:34188 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161423AbeBNRky (ORCPT ); Wed, 14 Feb 2018 12:40:54 -0500 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1EHdsUJ029770; Wed, 14 Feb 2018 09:40:37 -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=dUHeKxNeAwdy4IKlu/l6rm0kXXAg/0qUHSjDNAIGgfY=; b=E6PjKcIoAgLJ91wCDBKSCe548lyfMDqJKhhQw01RCWxIjCLP/avCtkQ6tfgfIVccGicr lwzDzMUrS00Xe9ozBn7+qo7GfFb5EVwCE0t8QLljOUhMb2FyjdZxes+eJOFhrMt9zLh5 xfaK6O6rNLu0s3p2fpsrJcyrCOBOi1PEQDg= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2g4qkdhhws-4 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 14 Feb 2018 09:40:37 -0800 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.26) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 14 Feb 2018 12:40:28 -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=dUHeKxNeAwdy4IKlu/l6rm0kXXAg/0qUHSjDNAIGgfY=; b=b2zZzsrG0+K0xT8ucEVw7+zLhZK/NJuEeuWgwSusnX0mecLTWdbO3zMd/Nv1/gupZibb1Yw5hEgVPeoFuMJkUTtfQQdi7nzIJiIMiBvc0Y6BrJRgyqZ4pUXOOj75bh3FrXPewNEcEpmU3FMA8p+ZwPIRqUcqMqOJADTPX4CBFH0= Received: from localhost (2620:10d:c090:180::622a) by BN6PR15MB1746.namprd15.prod.outlook.com (10.174.238.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Wed, 14 Feb 2018 17:40:25 +0000 Date: Wed, 14 Feb 2018 09:40:19 -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 11/14] x86/crypto: aesni: Introduce partial block macro Message-ID: <20180214174019.GA62159@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: CY4PR20CA0015.namprd20.prod.outlook.com (10.173.116.153) To BN6PR15MB1746.namprd15.prod.outlook.com (10.174.238.136) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b97d5976-6c54-43f7-3ce7-08d573d20811 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:BN6PR15MB1746; X-Microsoft-Exchange-Diagnostics: 1;BN6PR15MB1746;3:nV2hY7/jDTsyNvnooWMphc5b9jkZ2lt9Ni2Q9kioYptl6DbxphwDmJkaRx5LTi0yXbvqxpwMxE1DCGuWcjPS1/23vkzZF/VeQJoL767IfX8T8d6S9lpJ9SROSh4ZNbIEz9fKuJDnrKxAkAd1w5vj11Lt88WNGWPWb/0HT7YPlhZdhsT0YTOq7KIugyAGPDCvO4NQLa1ThlUnM414NNZT9pp3RRV+QkKj6BxGeLRbeuLNM9rrMojoGP5NfUkf4x0z;25:70uElRsLvDD/0oHeeGXxktU5tMvv97IA1hPoHrlEW1zg3QS6qr1CDlJLjrk8Ackxp6OmL3/Xvk+mBE4WahTkizXUUxycKmg8BvdBanCaq0v46D/2FasSGjKa7oTecl9r6Cc8gN/hk9UNL2D35fZfycZNfj6o9vgTuA87vjSI76Uha+G3J8thPW3p6BC77e5WJlh+eX7mDgc2dnyrXEcQZnmN89nvT7vf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xBxBVVwMi5r2jVfbKNsF4UohsTziydZTdZKgEC1Kvq2aVqzQtRZDZWE2f2Ms8O2+2TfCUO0YJHH0lBylTwv8tx1+nRIBYP8Gyhm5SSTuD60qqA/O2cyAvusBN8Ceq4NSY3FYeBanBlZuJS0S4Ix2OwwUf2sPiKuq4bcX2OYldlim/2KTAH5UoScT1mFL3LFywoH1e1P/oY1ygnIJIIRHOa4RjUhXo= 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)(3002001)(3231101)(11241501184)(944501161)(93006095)(93001095)(6041288)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:BN6PR15MB1746;BCL:0;PCL:0;RULEID:;SRVR:BN6PR15MB1746; X-Forefront-PRVS: 0583A86C08 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(7916004)(346002)(366004)(396003)(39380400002)(376002)(39860400002)(199004)(189003)(33716001)(83506002)(7736002)(6496006)(97736004)(52396003)(52116002)(53936002)(2950100002)(33656002)(54906003)(16586007)(76506005)(110136005)(316002)(6486002)(58126008)(386003)(8936002)(25786009)(81156014)(2906002)(8676002)(23726003)(9686003)(76176011)(478600001)(81166006)(6116002)(105586002)(59450400001)(7416002)(6666003)(68736007)(106356001)(50466002)(4326008)(305945005)(16526019)(47776003)(1076002)(86362001)(186003)(5660300001)(33896004)(18370500001);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR15MB1746;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;BN6PR15MB1746;23:1Q/2AjPzfumvS+i7X6CzHITDErFhrUN/z0on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2Hhy3gHLxX0L9I7feHLw4BJ8eeam6vWaxtlCPxUpbcQNrCxS55kvFITDc2mE9PO6/LE9wG83JCht1wmYCIIR32e6GpNj48goQBCjh9f3U9c=;7:ZCPChwyR+jximb9e/UAYdCYVPCLZAzXYYIse0OIWIBsEFLwWtoxoVzkviV5FEikBrVHWLuG5/QVX/4TiYByFAXu5lkdAQuLWLLrynbGJrWTGYeTUe0DXmyaB5TOefmMtObs5uA2Rxm4y1FZv9YihrscdhuLY4Cux3Eflhv4KpXQW5HBtbTkmiSjr0pftsVJGAPl11ey0etMfYA4SD5tt1bhFZn9YO3N277ZwXhGgZzLTPq4aKNtqPpzJt/WttwUz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR15MB1746;20:xmh1NiqlJPb3T7zAuyhZ4ymU+t7gsmVzFQjIfG0D9iOo4fsnlVDZX3do+Gz22GmCnY8E6Tjrv9yU1PJXDsOdLOVznjzPoQ16sFINm9fEmR8/I9loZzOvMz+u249SpMWZF5cFiRhlUQDqbTpxSVdAYkP6s+I013wG1Yy2XWqZDhA= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2018 17:40:25.6123 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b97d5976-6c54-43f7-3ce7-08d573d20811 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR15MB1746 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 Before this diff, multiple calls to GCM_ENC_DEC will succeed, but only if all calls are a multiple of 16 bytes. Handle partial blocks at the start of GCM_ENC_DEC, and update aadhash as appropriate. The data offset %r11 is also updated after the partial block. Signed-off-by: Dave Watson --- arch/x86/crypto/aesni-intel_asm.S | 151 +++++++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-) diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S index 3ada06b..398bd2237f 100644 --- a/arch/x86/crypto/aesni-intel_asm.S +++ b/arch/x86/crypto/aesni-intel_asm.S @@ -284,7 +284,13 @@ ALL_F: .octa 0xffffffffffffffffffffffffffffffff movdqu AadHash(%arg2), %xmm8 movdqu HashKey(%arg2), %xmm13 add %arg5, InLen(%arg2) + + xor %r11, %r11 # initialise the data pointer offset as zero + PARTIAL_BLOCK %arg3 %arg4 %arg5 %r11 %xmm8 \operation + + sub %r11, %arg5 # sub partial block data used mov %arg5, %r13 # save the number of bytes + and $-16, %r13 # %r13 = %r13 - (%r13 mod 16) mov %r13, %r12 # Encrypt/Decrypt first few blocks @@ -605,6 +611,150 @@ _get_AAD_done\@: movdqu \TMP6, AadHash(%arg2) .endm +# PARTIAL_BLOCK: Handles encryption/decryption and the tag partial blocks +# between update calls. +# Requires the input data be at least 1 byte long due to READ_PARTIAL_BLOCK +# Outputs encrypted bytes, and updates hash and partial info in gcm_data_context +# Clobbers rax, r10, r12, r13, xmm0-6, xmm9-13 +.macro PARTIAL_BLOCK CYPH_PLAIN_OUT PLAIN_CYPH_IN PLAIN_CYPH_LEN DATA_OFFSET \ + AAD_HASH operation + mov PBlockLen(%arg2), %r13 + cmp $0, %r13 + je _partial_block_done_\@ # Leave Macro if no partial blocks + # Read in input data without over reading + cmp $16, \PLAIN_CYPH_LEN + jl _fewer_than_16_bytes_\@ + movups (\PLAIN_CYPH_IN), %xmm1 # If more than 16 bytes, just fill xmm + jmp _data_read_\@ + +_fewer_than_16_bytes_\@: + lea (\PLAIN_CYPH_IN, \DATA_OFFSET, 1), %r10 + mov \PLAIN_CYPH_LEN, %r12 + READ_PARTIAL_BLOCK %r10 %r12 %xmm0 %xmm1 + + mov PBlockLen(%arg2), %r13 + +_data_read_\@: # Finished reading in data + + movdqu PBlockEncKey(%arg2), %xmm9 + movdqu HashKey(%arg2), %xmm13 + + lea SHIFT_MASK(%rip), %r12 + + # adjust the shuffle mask pointer to be able to shift r13 bytes + # r16-r13 is the number of bytes in plaintext mod 16) + add %r13, %r12 + movdqu (%r12), %xmm2 # get the appropriate shuffle mask + PSHUFB_XMM %xmm2, %xmm9 # shift right r13 bytes + +.ifc \operation, dec + movdqa %xmm1, %xmm3 + pxor %xmm1, %xmm9 # Cyphertext XOR E(K, Yn) + + mov \PLAIN_CYPH_LEN, %r10 + add %r13, %r10 + # Set r10 to be the amount of data left in CYPH_PLAIN_IN after filling + sub $16, %r10 + # Determine if if partial block is not being filled and + # shift mask accordingly + jge _no_extra_mask_1_\@ + sub %r10, %r12 +_no_extra_mask_1_\@: + + movdqu ALL_F-SHIFT_MASK(%r12), %xmm1 + # get the appropriate mask to mask out bottom r13 bytes of xmm9 + pand %xmm1, %xmm9 # mask out bottom r13 bytes of xmm9 + + pand %xmm1, %xmm3 + movdqa SHUF_MASK(%rip), %xmm10 + PSHUFB_XMM %xmm10, %xmm3 + PSHUFB_XMM %xmm2, %xmm3 + pxor %xmm3, \AAD_HASH + + cmp $0, %r10 + jl _partial_incomplete_1_\@ + + # GHASH computation for the last <16 Byte block + GHASH_MUL \AAD_HASH, %xmm13, %xmm0, %xmm10, %xmm11, %xmm5, %xmm6 + xor %rax,%rax + + mov %rax, PBlockLen(%arg2) + jmp _dec_done_\@ +_partial_incomplete_1_\@: + add \PLAIN_CYPH_LEN, PBlockLen(%arg2) +_dec_done_\@: + movdqu \AAD_HASH, AadHash(%arg2) +.else + pxor %xmm1, %xmm9 # Plaintext XOR E(K, Yn) + + mov \PLAIN_CYPH_LEN, %r10 + add %r13, %r10 + # Set r10 to be the amount of data left in CYPH_PLAIN_IN after filling + sub $16, %r10 + # Determine if if partial block is not being filled and + # shift mask accordingly + jge _no_extra_mask_2_\@ + sub %r10, %r12 +_no_extra_mask_2_\@: + + movdqu ALL_F-SHIFT_MASK(%r12), %xmm1 + # get the appropriate mask to mask out bottom r13 bytes of xmm9 + pand %xmm1, %xmm9 + + movdqa SHUF_MASK(%rip), %xmm1 + PSHUFB_XMM %xmm1, %xmm9 + PSHUFB_XMM %xmm2, %xmm9 + pxor %xmm9, \AAD_HASH + + cmp $0, %r10 + jl _partial_incomplete_2_\@ + + # GHASH computation for the last <16 Byte block + GHASH_MUL \AAD_HASH, %xmm13, %xmm0, %xmm10, %xmm11, %xmm5, %xmm6 + xor %rax,%rax + + mov %rax, PBlockLen(%arg2) + jmp _encode_done_\@ +_partial_incomplete_2_\@: + add \PLAIN_CYPH_LEN, PBlockLen(%arg2) +_encode_done_\@: + movdqu \AAD_HASH, AadHash(%arg2) + + movdqa SHUF_MASK(%rip), %xmm10 + # shuffle xmm9 back to output as ciphertext + PSHUFB_XMM %xmm10, %xmm9 + PSHUFB_XMM %xmm2, %xmm9 +.endif + # output encrypted Bytes + cmp $0, %r10 + jl _partial_fill_\@ + mov %r13, %r12 + mov $16, %r13 + # Set r13 to be the number of bytes to write out + sub %r12, %r13 + jmp _count_set_\@ +_partial_fill_\@: + mov \PLAIN_CYPH_LEN, %r13 +_count_set_\@: + movdqa %xmm9, %xmm0 + MOVQ_R64_XMM %xmm0, %rax + cmp $8, %r13 + jle _less_than_8_bytes_left_\@ + + mov %rax, (\CYPH_PLAIN_OUT, \DATA_OFFSET, 1) + add $8, \DATA_OFFSET + psrldq $8, %xmm0 + MOVQ_R64_XMM %xmm0, %rax + sub $8, %r13 +_less_than_8_bytes_left_\@: + movb %al, (\CYPH_PLAIN_OUT, \DATA_OFFSET, 1) + add $1, \DATA_OFFSET + shr $8, %rax + sub $1, %r13 + jne _less_than_8_bytes_left_\@ +_partial_block_done_\@: +.endm # PARTIAL_BLOCK + /* * if a = number of total plaintext bytes * b = floor(a/16) @@ -623,7 +773,6 @@ _get_AAD_done\@: movdqu AadHash(%arg2), %xmm\i # XMM0 = Y0 - xor %r11, %r11 # initialise the data pointer offset as zero # start AES for num_initial_blocks blocks movdqu CurCount(%arg2), \XMM0 # XMM0 = Y0 -- 2.9.5