From patchwork Tue Jul 20 08:55:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 12387859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EC8DC07E9B for ; Tue, 20 Jul 2021 08:59:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A89E61209 for ; Tue, 20 Jul 2021 08:59:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A89E61209 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9swpxFFF/wIp/nt9rvfClmPBXSIpftm0XRAWMFumeE4=; b=tO5kXHkUZ7ZcHa 4dZ//YXqlB7CK+6RB1yW4twThiKMVCD9MXlbt6TlgIbZr2FH/MSc7Y0pmeEpsFSHjv/27H+7VPv0q SKkqXQNCFP3mb8o5Y9lHk0wONUfZiUz446NfgUt8ERkdnx81T1NX+WXP4fmcSr38wAFWtWekhA4gM 7NOX8WDUBuHZ4RmoeMFLs7HWyzZ9rVxcPZcWCwON7N+t2QqohqLs9uvD8kyKICbOCx00vXUAejvL2 SRNwSOt+WQNbS6+8wgLY+L9vCLjI+28ImGiCzN1UFq5UUw1wwoTMbfKkXGASHiE+7kR1esJmhM0Q0 LnT3KpT4NMiL0MNa5Zeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5lZ1-00CJPo-Nh; Tue, 20 Jul 2021 08:57:19 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5lXi-00CIvs-BT for linux-arm-kernel@lists.infradead.org; Tue, 20 Jul 2021 08:55:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1626771357; x=1658307357; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BvECuVH1S6mHb7Y7yYH9mswdt55NYUYyII8/lZa041E=; b=GkFnpz6rOBWPG/DriV9vqP08qixDI7k9UAjCRpuZvNbUkJfYmE4+GhD3 EZkxOahvUBVi3/dSVVgX6J/cKxC7raXM95qn5DR3SosQJGGK0cWgv2CWv b6XJ2JnNOYZEBq9E0KDfEuvaEmBnhzq6nq2uz8lFJfqnZ7aPVMQfAf5/4 ZFlMoIj0Wwyz5PmcPGcEqeqZVFbUV9JUWO8Jp7qiczbcIqPQEI+U0JdUl 7VifV5gpuqhW8A55CVDAws75UzAPE1wzTYLTi4C3EeyCwaIsrOUFHRXer CyG0772UqiAskBCRQq4NnQD5o3LzRzdzZXlWFPm/XTE3gwh1tLXvKllXf Q==; IronPort-SDR: 8HrygmC+GMzUNr9H5XSw0CcQemSNAtSniSVFEhLaCJ9XhykYNjLDHr4mZLCRYkJhThV/LmTJZq Nczcz9ZpC3U8u91byBu74+MlhRmhFB75tOGV3qBS326gm1uwwCEBC4kBUwch5HT91Wevyn13jJ py4dcS80bUzgWrW3Q0iXQu0lHl5OC2ln1TxFzxsrW4kbqqfbudh5n7hGneqiu6PQlNo2x1shBh Ya3McoMA7Sj7axSt4o1fKrnPpr2/YyxNR8SBKumQ14Umc7JNksXiQvNKPsi8TbJ9+gKZp5xd7i aFWvdYGuM3gAD0581eSxX716 X-IronPort-AV: E=Sophos;i="5.84,254,1620716400"; d="scan'208";a="122687332" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2021 01:55:56 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 20 Jul 2021 01:55:46 -0700 Received: from ROB-ULT-M18064N.mchp-main.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Tue, 20 Jul 2021 01:55:44 -0700 From: Tudor Ambarus To: Subject: [PATCH 3/9] crypto: atmel-aes: Add blocksize constraint for ECB and CBC modes Date: Tue, 20 Jul 2021 11:55:29 +0300 Message-ID: <20210720085535.141486-4-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210720085535.141486-1-tudor.ambarus@microchip.com> References: <20210720085535.141486-1-tudor.ambarus@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210720_015558_487128_AD3E181F X-CRM114-Status: GOOD ( 10.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexandre.belloni@bootlin.com, Tudor Ambarus , linux-kernel@vger.kernel.org, ludovic.desroches@microchip.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org NIST 800-38A requires for the ECB and CBC modes that the total number of bits in the plaintext to be a multiple of the block cipher. Signed-off-by: Tudor Ambarus --- drivers/crypto/atmel-aes.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c index b1d286004295..9c6d80d1d7a0 100644 --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -1089,6 +1089,11 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode) struct atmel_aes_base_ctx *ctx = crypto_skcipher_ctx(skcipher); struct atmel_aes_reqctx *rctx; struct atmel_aes_dev *dd; + u32 opmode = mode & AES_FLAGS_OPMODE_MASK; + + if ((opmode == AES_FLAGS_ECB || opmode == AES_FLAGS_CBC) && + !IS_ALIGNED(req->cryptlen, crypto_skcipher_blocksize(skcipher))) + return -EINVAL; switch (mode & AES_FLAGS_OPMODE_MASK) { case AES_FLAGS_CFB8: @@ -1120,7 +1125,7 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode) rctx = skcipher_request_ctx(req); rctx->mode = mode; - if ((mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_ECB && + if (opmode != AES_FLAGS_ECB && !(mode & AES_FLAGS_ENCRYPT) && req->src == req->dst) { unsigned int ivsize = crypto_skcipher_ivsize(skcipher);