From patchwork Tue Mar 28 19:56:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan.Wanner@microchip.com X-Patchwork-Id: 76245 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2480356vqo; Tue, 28 Mar 2023 13:17:38 -0700 (PDT) X-Google-Smtp-Source: AKy350ZFhYYuaJ2oeuxmH7g7LrVaFfKVZKrQnjIx7mxnyn2ZtYHgb0d5IiETEMXeQEmyvujsA78F X-Received: by 2002:a17:907:784e:b0:92f:ccf3:f0ce with SMTP id lb14-20020a170907784e00b0092fccf3f0cemr18886714ejc.45.1680034658616; Tue, 28 Mar 2023 13:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680034658; cv=none; d=google.com; s=arc-20160816; b=vsk8ha6px+4hZmFUcjriLHLJjeOUIfM2lMW4f9E5c6e7X+C21UCA5s1r37aVuVcglQ RRz2eu5ppcgWGxAZxs00Df0Kg+1NxzbFtk3VYbb7cxCkilro7atRFgO6W9/Z28ggM5WE RCUFkYlFWJVwVko6oinPPo9PdIl8NeqMQIrR7JI6IzyFdjonaPFd6+niP6MBH9H55TMD Bs2x2ns9WJ7R8YGnXCHrHY7c7G1pzJe8S8w3U1+mVVWcPkJlyhnfrmq8TlxZrm1otfbC RtbW9QBmlZqno4Pjzr9dzFkbF1p+65XVhHUHpLOcQtjPpXPYBysC9krWCd17lGZ0Mwwt 6tWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ry8aqtNMV/mfzpkLijiN9tetKDcS3PgQ2j360CkuI/0=; b=Lu6SMSXwFLI1gjPCwQXbt0WB/j4+61km85q+ZWHlxz3ZAPsm9SuxZLiIB2k6EQnqii FjRr3NUYbPbW7nW1VmhgsQbsxynRN5jf40Ihzp8o4k6VUKIdyvqYmgNeUeUBm3mCcEhp ygy8UGWHZ93NWJ8TsrpGCqukcjt5vyuLOwGVib+6GYhnrd8XBYP8wPbOxXII8FecrnYZ TMv8KxdQSJAdnmqqr1Y9RmLkUWcKKu9yAeqeNnCbSzobPP7t4LY2QFgvIwDm+qFHYOD8 WXoqv25IjQ1EGWb7vDUooL00PnhwkGUArXRVY2g7XrxKhFfjcrPuWcxnSqcjxsrI9qZQ 4Oug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=xuwHJTJY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb8-20020a1709071c8800b008cf5d345700si31574487ejc.864.2023.03.28.13.16.51; Tue, 28 Mar 2023 13:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=xuwHJTJY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229716AbjC1T41 (ORCPT + 99 others); Tue, 28 Mar 2023 15:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjC1T4Y (ORCPT ); Tue, 28 Mar 2023 15:56:24 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEF631FC3; Tue, 28 Mar 2023 12:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1680033384; x=1711569384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/F2de+iehabZIds7kVXZap20zLfbkzaLODGMMhLmfRE=; b=xuwHJTJYpPguYJxbHLSi94HWnROhsO5q9xrqSn/k8D3tK0rG22mT4Pjq 1v+H0HlzonlMuGJvBm/cxuoIFoVnGbI1MegWO6lq+eIqnvw1bEMrVoWpj aSHY/Cd+GExi/t93BuVicEYpznvW9RKdX/ThnH4QaH6h3zCXHBc7vMpnM 08xe94Vb/PN4Mn2O32cw3jz0N23vqrWyabaYYFY51f6lyQJ+nFtPFjlaD 4+HMvwV6Bp65MIXX77poDXwaVFRPDrpd+jC52Z2gvmr3nZ3W8zyoYnj3D Sw1JOByFOiD1UQqvbfdUfRmatbAW/quxbJq07mLtdC5yUkqyoGmgF6zJA Q==; X-IronPort-AV: E=Sophos;i="5.98,297,1673938800"; d="scan'208";a="206741354" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 28 Mar 2023 12:56:22 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 28 Mar 2023 12:56:21 -0700 Received: from ryan-Precision-3630-Tower.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Tue, 28 Mar 2023 12:56:21 -0700 From: To: , , , , CC: , , , Ryan Wanner Subject: [PATCH 1/4] crypto: atmel-sha: Add zero length message digest support for hmac Date: Tue, 28 Mar 2023 12:56:26 -0700 Message-ID: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761644022041787485?= X-GMAIL-MSGID: =?utf-8?q?1761644022041787485?= From: Ryan Wanner Add softare padding to hmac-sha digest for zero length messages. Using the atmel_sha_fill_padding() to fill the buffer with a padded empty message with a length of the block size. Create a temporary scatter list from the padded buffer to pass into the data processing functions. Signed-off-by: Ryan Wanner --- drivers/crypto/atmel-sha.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c index 00be792e605c..b42e3a0b8cb5 100644 --- a/drivers/crypto/atmel-sha.c +++ b/drivers/crypto/atmel-sha.c @@ -1948,14 +1948,32 @@ static int atmel_sha_hmac_digest2(struct atmel_sha_dev *dd) struct atmel_sha_reqctx *ctx = ahash_request_ctx(req); struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct atmel_sha_hmac_ctx *hmac = crypto_ahash_ctx(tfm); + struct scatterlist *sgbuf; size_t hs = ctx->hash_size; size_t i, num_words = hs / sizeof(u32); bool use_dma = false; u32 mr; /* Special case for empty message. */ - if (!req->nbytes) - return atmel_sha_complete(dd, -EINVAL); // TODO: + if (!req->nbytes) { + req->nbytes = 0; + ctx->bufcnt = 0; + ctx->digcnt[0] = 0; + ctx->digcnt[1] = 0; + switch (ctx->flags & SHA_FLAGS_ALGO_MASK) { + case SHA_FLAGS_SHA1: + case SHA_FLAGS_SHA224: + case SHA_FLAGS_SHA256: + atmel_sha_fill_padding(ctx, 64); + break; + + case SHA_FLAGS_SHA384: + case SHA_FLAGS_SHA512: + atmel_sha_fill_padding(ctx, 128); + break; + } + sg_init_one(&dd->tmp, ctx->buffer, ctx->bufcnt); + } /* Check DMA threshold and alignment. */ if (req->nbytes > ATMEL_SHA_DMA_THRESHOLD && @@ -1985,12 +2003,20 @@ static int atmel_sha_hmac_digest2(struct atmel_sha_dev *dd) atmel_sha_write(dd, SHA_CR, SHA_CR_FIRST); + /* Special case for empty message. */ + if (!req->nbytes) { + sgbuf = &dd->tmp; + req->nbytes = ctx->bufcnt; + } else { + sgbuf = req->src; + } + /* Process data. */ if (use_dma) - return atmel_sha_dma_start(dd, req->src, req->nbytes, + return atmel_sha_dma_start(dd, sgbuf, req->nbytes, atmel_sha_hmac_final_done); - return atmel_sha_cpu_start(dd, req->src, req->nbytes, false, true, + return atmel_sha_cpu_start(dd, sgbuf, req->nbytes, false, true, atmel_sha_hmac_final_done); }