From patchwork Wed Feb 17 03:20:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 383793 Delivered-To: patch@linaro.org Received: by 2002:a02:c80e:0:0:0:0:0 with SMTP id p14csp2465579jao; Tue, 16 Feb 2021 19:21:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXN8KyU4sm+LDkys20qjWyA77tyWO+o8SvBhhEmnrO8o3qHFHUWCA0UkBbIyghB1Qe8cKp X-Received: by 2002:a17:907:9483:: with SMTP id dm3mr23646839ejc.120.1613532098094; Tue, 16 Feb 2021 19:21:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613532098; cv=none; d=google.com; s=arc-20160816; b=anAZUwEL/eMAaE3zRLzAmcWQpe8I2QNEArt+4Qn2mSjVeJDOmECwxKDmoA0HNfVsFu nfpKojCagsFa+JSOs36mBVqXcrFDgRoQyYMxv4T3aPJQPSIrRzFZV/BZ5slmjZy506KU HnrYm6X0xUq6J+06vxgxMrOzWHZk84JldR7suCvTJo28vz3FPccf4qBIQ6vI1dR6nhaZ sPlYjNCZopX6CGAut4AdivpmiRvzcWZs11/IaJHVdzYjxGM3lc2DCsEzXlhH3DI1pdyE SKiaajlGG7bMWZrfl3SP1DqJn66jC93g4tpvfwWfnjc+x7IvwHARHevPBCY+KEkhqcGX xKFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zWa3H79sxtVUMhZLLOWf5+5gdO6nh0TLpCh2SAEvMis=; b=HvnTaveo9fV/+yDVoCt1GFbJ4lT66CD6IPf/R71MTdO1+67SQsoPbJv27OlZPa4LWg wgJwtEN3/tqURHbhRYzGtT/j2hy9sekCeFxiQO0XuA9KtUtI+SHbacMkeKtGnaAwOfkC Yz1B6Hc7xcPbjW/ch7LeWu2yTluwaxbdyE5TO9U+a8txHvcOIIRCkzxXMtUcu2FJEjM9 E/qyFrUA4RzwDPUwBqs2NlccIuxGOelFEJ3w6b8jL28q0MPpZwPLGpsafS8Q2ZXh+bti UoQFOKsSKIea9rB0gHpz1rEiKuwYP6GtxltushGRg/iBFhZpj50cIO7Si5348M02cTpm eBXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=E3PCQou2; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id oz19si729092ejb.179.2021.02.16.19.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 19:21:38 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=E3PCQou2; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 438E082872; Wed, 17 Feb 2021 04:21:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="E3PCQou2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 264CC8284D; Wed, 17 Feb 2021 04:21:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_SBL_CSS,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F24988284D for ; Wed, 17 Feb 2021 04:21:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joel.stan@gmail.com Received: by mail-pl1-x635.google.com with SMTP id u11so6661609plg.13 for ; Tue, 16 Feb 2021 19:21:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zWa3H79sxtVUMhZLLOWf5+5gdO6nh0TLpCh2SAEvMis=; b=E3PCQou2QanRiPDdqVj7lKon1ZhChtXphSH6tFpHN/48qNHox7APIFP9o2jkWS8R6e p4IpNQ1vrC2i2j3bfnzyW7QQfe8aGI42aJiR3Xp7Fw5B+f6EWZ6T8Z0TJyKwmsOkLn3X O9xY7yBv3dBQMVlDRXYkSrPMGkFXnxrvPYkJQBszUeQCc1Upven/QPTgNYymser5xZxS 8wW8PNNJuBQkIOGlt3eWIy8Qj5o9rJdGmQ41tGXPtQV+tEIimKg/ibwBNbnCquSsVZdh UQwFL9eKiBbTrqnhp7PuB+OxBVZHAY/dRDahpuzDIKUYPQBNbaSFo0dpqjiJ1qCkxDcT 2opw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=zWa3H79sxtVUMhZLLOWf5+5gdO6nh0TLpCh2SAEvMis=; b=bAGgixE9wuqb07MxjoOYVirdz2OmlPbu04CM6OC+aLDIUvXBG34METRuCroo5LS2sa fTW9OBGMRHhrlTaLfopX+u6B6POGiakMBoD9LX2rT3wqmrZ5JldLkSSkQRx8zfQk2TI7 zNoqEeJ9EID71x4RiNTjNW+RVvZROBqzhAUAe2G7E9SJJxt4M3AbnywfBEmvaxjFrhI4 MLVJYGeT33tlyUWBY8blFk2j+XprKR5RBPGUJfCjkJ2EVDfgIlTd7oSYyk4VW0ersdET /xnhEGel/DtgCIRKg3lEI/puS/qi1nGlCppexvJc9PnRauH9TMV+Klq0zOQoIzQ+uF8C UAlQ== X-Gm-Message-State: AOAM530ERSN+wI+vAWhYKA8yk/tMaCtHZqqk4C1L2srRF5FMrEGvdJkh Y79e/g9O6oLLaClZLf30Bu0= X-Received: by 2002:a17:90b:1910:: with SMTP id mp16mr7167615pjb.0.1613532064496; Tue, 16 Feb 2021 19:21:04 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id 4sm336466pjc.23.2021.02.16.19.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 19:21:03 -0800 (PST) From: Joel Stanley To: Simon Glass , u-boot@lists.denx.de Cc: Andrew Jeffery Subject: [PATCH 3/3] hash: Allow for SHA512 hardware implementations Date: Wed, 17 Feb 2021 13:50:42 +1030 Message-Id: <20210217032042.425512-4-joel@jms.id.au> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210217032042.425512-1-joel@jms.id.au> References: <20210217032042.425512-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Similar to support for SHA1 and SHA256, allow the use of hardware hashing engine by enabling the algorithm and setting CONFIG_SHA_HW_ACCEL / CONFIG_SHA_PROG_HW_ACCEL. Signed-off-by: Joel Stanley --- common/hash.c | 24 ++++++++++++++++++++++-- include/hw_sha.h | 26 ++++++++++++++++++++++++++ lib/Kconfig | 15 +++++++-------- 3 files changed, 55 insertions(+), 10 deletions(-) -- 2.30.0 diff --git a/common/hash.c b/common/hash.c index fc64002f736a..10dff7ddb0e7 100644 --- a/common/hash.c +++ b/common/hash.c @@ -97,7 +97,7 @@ static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void } #endif -#if defined(CONFIG_SHA384) +#if defined(CONFIG_SHA384) && !defined(CONFIG_SHA_PROG_HW_ACCEL) static int hash_init_sha384(struct hash_algo *algo, void **ctxp) { sha512_context *ctx = malloc(sizeof(sha512_context)); @@ -125,7 +125,7 @@ static int hash_finish_sha384(struct hash_algo *algo, void *ctx, void } #endif -#if defined(CONFIG_SHA512) +#if defined(CONFIG_SHA512) && !defined(CONFIG_SHA_PROG_HW_ACCEL) static int hash_init_sha512(struct hash_algo *algo, void **ctxp) { sha512_context *ctx = malloc(sizeof(sha512_context)); @@ -260,10 +260,20 @@ static struct hash_algo hash_algo[] = { .name = "sha384", .digest_size = SHA384_SUM_LEN, .chunk_size = CHUNKSZ_SHA384, +#ifdef CONFIG_SHA_HW_ACCEL + .hash_func_ws = hw_sha384, +#else .hash_func_ws = sha384_csum_wd, +#endif +#ifdef CONFIG_SHA_PROG_HW_ACCEL + .hash_init = hw_sha_init, + .hash_update = hw_sha_update, + .hash_finish = hw_sha_finish, +#else .hash_init = hash_init_sha384, .hash_update = hash_update_sha384, .hash_finish = hash_finish_sha384, +#endif }, #endif #ifdef CONFIG_SHA512 @@ -271,10 +281,20 @@ static struct hash_algo hash_algo[] = { .name = "sha512", .digest_size = SHA512_SUM_LEN, .chunk_size = CHUNKSZ_SHA512, +#ifdef CONFIG_SHA_HW_ACCEL + .hash_func_ws = hw_sha512, +#else .hash_func_ws = sha512_csum_wd, +#endif +#ifdef CONFIG_SHA_PROG_HW_ACCEL + .hash_init = hw_sha_init, + .hash_update = hw_sha_update, + .hash_finish = hw_sha_finish, +#else .hash_init = hash_init_sha512, .hash_update = hash_update_sha512, .hash_finish = hash_finish_sha512, +#endif }, #endif { diff --git a/include/hw_sha.h b/include/hw_sha.h index 15b1a1c79836..d4f3471c4308 100644 --- a/include/hw_sha.h +++ b/include/hw_sha.h @@ -8,6 +8,32 @@ #define __HW_SHA_H #include +/** + * Computes hash value of input pbuf using h/w acceleration + * + * @param in_addr A pointer to the input buffer + * @param bufleni Byte length of input buffer + * @param out_addr A pointer to the output buffer. When complete + * 64 bytes are copied to pout[0]...pout[63]. Thus, a user + * should allocate at least 64 bytes at pOut in advance. + * @param chunk_size chunk size for sha512 + */ +void hw_sha512(const uchar *in_addr, uint buflen, uchar *out_addr, + uint chunk_size); + +/** + * Computes hash value of input pbuf using h/w acceleration + * + * @param in_addr A pointer to the input buffer + * @param bufleni Byte length of input buffer + * @param out_addr A pointer to the output buffer. When complete + * 48 bytes are copied to pout[0]...pout[47]. Thus, a user + * should allocate at least 48 bytes at pOut in advance. + * @param chunk_size chunk size for sha384 + */ +void hw_sha384(const uchar *in_addr, uint buflen, uchar *out_addr, + uint chunk_size); + /** * Computes hash value of input pbuf using h/w acceleration * diff --git a/lib/Kconfig b/lib/Kconfig index b35a71ac368b..0d753eedeced 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -389,19 +389,18 @@ config SHA384 config SHA_HW_ACCEL bool "Enable hashing using hardware" help - This option enables hardware acceleration - for SHA1/SHA256 hashing. - This affects the 'hash' command and also the - hash_lookup_algo() function. + This option enables hardware acceleration for SHA hashing. + This affects the 'hash' command and also the hash_lookup_algo() + function. config SHA_PROG_HW_ACCEL bool "Enable Progressive hashing support using hardware" depends on SHA_HW_ACCEL help - This option enables hardware-acceleration for - SHA1/SHA256 progressive hashing. - Data can be streamed in a block at a time and the hashing - is performed in hardware. + This option enables hardware-acceleration for SHA progressive + hashing. + Data can be streamed in a block at a time and the hashing is + performed in hardware. config MD5 bool "Support MD5 algorithm"