From patchwork Wed Feb 17 03:20:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 383791 Delivered-To: patch@linaro.org Received: by 2002:a02:c80e:0:0:0:0:0 with SMTP id p14csp2465424jao; Tue, 16 Feb 2021 19:21:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoVOIFZr783IqGyH3fhRWMsPqYde16zpAvKAP0ZOZIaciUc/X59J8G/KLWsYQEs5RKYvPj X-Received: by 2002:a05:6402:2210:: with SMTP id cq16mr24155263edb.148.1613532076988; Tue, 16 Feb 2021 19:21:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613532076; cv=none; d=google.com; s=arc-20160816; b=bJukEaL3UTwCKDX1BXfx18CYRp5+UeRkbXV758K1PrgruKx+K6hsdmNo36Osb4xmOA RCNTQy8NzssaEsgeAWrma2orOIZoHCpzFApJCyAIMZAz6vt8avbuaHXZPSWI8Rr9S4AX 8bxRE66v3Y+L1IS3EP2eu+HtbNowu46e5h85orVNdLEwVZ3eFCqmT/eWCdGB0FY3BaEx NM76kHV6bdUWU5uGPcJvnhB3aXujwvm0RzNp1YRkGv4RR4b+y3EInEAuui4gnDTkeUMm ydRPP0wgRVYDu5TVG6cGxsV+gHdXH9RbThsfNoJJcEnlJ1ys6CJ7vltTQQq0p7mxikGw PqLg== 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=Nt+c5PIBe19tTBuT1+cPItaJUQS7rWhkaUuDGNQ/lYY=; b=Q04mH/J61YNsJ34cDnIdT/sKm2bqY5l1vPTnSdb5QjxUmO/+O7uKQGWlrDCWm3oxrX Tqy8SyRT2VnjZWlOArUjOYYya2pswnXqEaZ/Cp0wDsm/wX9ApcHzSoz/Q40PORPFV0ni x8eJDxlvJY7c7sXDpowyxTN9sz/Fgbaz57pF8NwJQzOurHDjfEpBG5Bb6mRkdbymc4Zm QDIounTakmRaTVRacy7dViuuzbD64IgS7lFkx7NQFV7JZnRQ/uBotRdtODq3xyW8f94U IMwnjw+g3G8Hdt3Mg9b1FZ1LZayo6hMsaQxxgcOwCiYgS2VQX3XbskaEOMUxtuhxukQt q6pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=lK7flpkC; 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 g2si386182edn.428.2021.02.16.19.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 19:21:16 -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=lK7flpkC; 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 22FA28286B; Wed, 17 Feb 2021 04:21:12 +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="lK7flpkC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 954F58285E; Wed, 17 Feb 2021 04:21:04 +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-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 6A8568284D for ; Wed, 17 Feb 2021 04:20:59 +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-x62b.google.com with SMTP id ba1so6698099plb.1 for ; Tue, 16 Feb 2021 19:20:59 -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=Nt+c5PIBe19tTBuT1+cPItaJUQS7rWhkaUuDGNQ/lYY=; b=lK7flpkCK7OXH/Gt4l9Vv/M9dMjfIBHQeHEmywAqCz8Yx33+lXkr1EcXSZNiDdd6Wc fCJaUiubG/yb3Bv0Ji2dZuuZqeJD6CtyY3Zm/SvW4adr9fyCgz8N0IUjq16LLJc4FkvD lp63f7yttJbPxjXFbPZ9KHUGzGheEUOIFICvz9lh8PJymn/aKzAW8rD7RxquvG/ZwJOP pqH5i+bUbBIFFmHm+Ble0Yf2yyfy5m6654iMNnl6KOhOwdyWk0qT2Y27ztcYVGqh7W20 Mer6sqLgQ6/VIAfcdtnLMwD0xL1+RGLR4wYvgdJdihy74MuVyC01Ig9QNxEa0zyzxmgL kgoA== 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=Nt+c5PIBe19tTBuT1+cPItaJUQS7rWhkaUuDGNQ/lYY=; b=bItC9YuZOfJT8DhISs5azEzTaFF1312OBW4A4o55IwHVrtRdNRMtfCKWQTL6Q2tCi0 +6RVrJ9VjV6+nVdrrNdc2rm4/rhmk8b5QB54sRlSNTdZzEcJ960iqViKvuXlFMk4fB3W nCx3zRHi9B+JSSu6sAFxwYqW6F3UaG+44xS8iu7hyytgTUxeGRz76dTNWPUOzRGPZDDA SyS35a5cL+MRuSCJl1RT9p7Jk7H6GOUlDNmGwufI4ZgWXopvC9L31lCFpzsJDcITEz9L jdG1dya2/w7c0dNL7j/QtZpS84otAI5w45FnyDv/aR2DA3+xWtP3H11UEkvyeB/hivqX P5aA== X-Gm-Message-State: AOAM530aYzGV6zQ80dOC6/jIcwlv3eiHztBvsHDv+JVR65HNOrJWUU5Z om0zOqOpQP9Fu+NMB+Ho32o= X-Received: by 2002:a17:90a:5417:: with SMTP id z23mr7035726pjh.111.1613532058010; Tue, 16 Feb 2021 19:20:58 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id 4sm336466pjc.23.2021.02.16.19.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 19:20:57 -0800 (PST) From: Joel Stanley To: Simon Glass , u-boot@lists.denx.de Cc: Andrew Jeffery Subject: [PATCH 1/3] hw_sha: Fix coding style errors Date: Wed, 17 Feb 2021 13:50:40 +1030 Message-Id: <20210217032042.425512-2-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 Checkpatch complains about: ERROR: "foo * bar" should be "foo *bar" and CHECK: Alignment should match open parenthesis Signed-off-by: Joel Stanley --- include/hw_sha.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.30.0 diff --git a/include/hw_sha.h b/include/hw_sha.h index 991e496a3cb2..15b1a1c79836 100644 --- a/include/hw_sha.h +++ b/include/hw_sha.h @@ -18,8 +18,8 @@ * should allocate at least 32 bytes at pOut in advance. * @param chunk_size chunk size for sha256 */ -void hw_sha256(const uchar * in_addr, uint buflen, - uchar * out_addr, uint chunk_size); +void hw_sha256(const uchar *in_addr, uint buflen, uchar *out_addr, + uint chunk_size); /** * Computes hash value of input pbuf using h/w acceleration @@ -31,8 +31,8 @@ void hw_sha256(const uchar * in_addr, uint buflen, * should allocate at least 32 bytes at pOut in advance. * @param chunk_size chunk_size for sha1 */ -void hw_sha1(const uchar * in_addr, uint buflen, - uchar * out_addr, uint chunk_size); +void hw_sha1(const uchar *in_addr, uint buflen, uchar *out_addr, + uint chunk_size); /* * Create the context for sha progressive hashing using h/w acceleration @@ -56,7 +56,7 @@ int hw_sha_init(struct hash_algo *algo, void **ctxp); * @return 0 if ok, -ve on error */ int hw_sha_update(struct hash_algo *algo, void *ctx, const void *buf, - unsigned int size, int is_last); + unsigned int size, int is_last); /* * Copy sha hash result at destination location @@ -70,6 +70,6 @@ int hw_sha_update(struct hash_algo *algo, void *ctx, const void *buf, * @return 0 if ok, -ve on error */ int hw_sha_finish(struct hash_algo *algo, void *ctx, void *dest_buf, - int size); + int size); #endif From patchwork Wed Feb 17 03:20:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 383792 Delivered-To: patch@linaro.org Received: by 2002:a02:c80e:0:0:0:0:0 with SMTP id p14csp2465506jao; Tue, 16 Feb 2021 19:21:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfBBQ4pbOYPlZxxeLvWNENpcapk/MasUgwVmypJOIZvbJZYkDVXb9eJ0so3rdzdd2xpAXm X-Received: by 2002:a17:906:d8ca:: with SMTP id re10mr23815349ejb.18.1613532087597; Tue, 16 Feb 2021 19:21:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613532087; cv=none; d=google.com; s=arc-20160816; b=rXvID3zcJRaCobYp3so+eYqIbeFS0kOeVdxiYJdpE0dzho9ubNMsZbYs9LWeFkjaFZ M2mAbQ7nsB18Suefgt5omGUH2SHWGUMe6hZqCU11A2QD3grxqp2KazaZ3AaBoSGp5ceB +PLRevs0wBDPJaucrw44eVqp53TZdNWJnDl14qoYePr7pqXPvgffme6mTC/8xphOYhGa asBt+XMy+9DCyp3JftzPo0TSQjTEWJ2AjsTKTasGioCKMr2Qq/WSA/U4P7CPqeSQXVxM CDjbSxHIk/GP6fh0rH6TgvxyF0wOR2eZfEy8HaKwkN+PbPXjTNuLeZvVe2x75FE9DtdD cETg== 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=uQ1Qfyv9pknmZqh9Ds3JNf+TBCud1AUBGJwmM9emHpk=; b=CjftDExNCrb9yCMyErV+Eh/oM7DIG1DEg/2VCm0XpiChZHfWAZX0Mar8H1JQ5i8okQ 6TK0NSFLTTT714cK3pkRIHQzahjVGQ2GVcJfjkqb+6AEqMACF6aFZWRPg/Ax95gL1kox vF/WNha2uxrTeAN7bkkK8fJQKz5+CCxZ28K5KIxsz/8pBahOdtq8KbPHvj2KGq5zNxXL IMmPSbhpt3dmTbJKdwc384o2fFVxPGkCBvcDd2mC5X1oOlU5EU0b8sxZbgdZ+93HhAf0 mDoXRk5bBnTNpBdV03pmiK797PWtjJE/adA2KsYKkcO20sTAdvMwGgXILyLsDkRvRlwo LITw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="ODAqAN/B"; 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 n19si658426ejb.295.2021.02.16.19.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 19:21:27 -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="ODAqAN/B"; 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 644A38287C; Wed, 17 Feb 2021 04:21:14 +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="ODAqAN/B"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4055A82867; Wed, 17 Feb 2021 04:21:07 +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-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (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 C46488285D for ; Wed, 17 Feb 2021 04:21:02 +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-pg1-x52c.google.com with SMTP id n10so7604687pgl.10 for ; Tue, 16 Feb 2021 19:21:02 -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=uQ1Qfyv9pknmZqh9Ds3JNf+TBCud1AUBGJwmM9emHpk=; b=ODAqAN/Bdid6DgJHL8mzKI36WlkQbf4Fe5XYD4DRQw/q34gGcGm6HuzDaP62DmQy36 8cr8kFUUWskRsGFdaMIOziGf6HEVFd/llMaIvjbvubJenudi1mV7mEWjwA2sUeajZZCl cKr9eFxMT3ueoxjq45uSe/4Z1ckyUKslweAcfJRJnebXmhrW3t6JsIr+8r6y0sj4XSfI kB3GJtPlZSBETYXiTUB5iQEkKefHLZ1Kt0aUW01pxfXVs/CnxHSK5JBI89sdba7eFL3v UjKDDCYqIXhyxhpNGBBbqw9O5R/1jgr9vpVnE4YAOqgzuz/8zApCDgbTMMM4VwFKseQQ 5fIQ== 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=uQ1Qfyv9pknmZqh9Ds3JNf+TBCud1AUBGJwmM9emHpk=; b=HJSpXChaRruRfT/wTTzyYAzhZJBy7UOFlJ/Oks9wgkR3/IrIUHTju1m1aJNci56odI O1da5qOU7bxrCMNev/k7YIy+SI76Zl7tx++7QA5iwEeDvySOEsD3tz2tJZ72PxK4gd1D ZpmbvZR64SN+yNEfYCd11WuCaWgUpBMtXuKIiWze4+7kLIfuJnVA9lNLGJk9r62xhVtn afnExAd4K3k78pwhqtnnXJCZtwVuV3lMknk8uM1tQDpNcoOYb8HjGRugjotiRiyeYuGX /vuY1IpSwRJ5qynqdyWsH/byFKdT88ZyGaDTPKdW1/tMaP6jXEvqJwef5iyDh/fst4Pe uurw== X-Gm-Message-State: AOAM532uBDkA/R3sL8d4J4v/BWqzG+aqz+yv16xm7S2ZvXQgRKoQBj5b UfbDIDblH9bc3h+7IwcItY/96k8DKkg= X-Received: by 2002:a05:6a00:1353:b029:1c5:8a8d:7ee6 with SMTP id k19-20020a056a001353b02901c58a8d7ee6mr21967957pfu.13.1613532061252; Tue, 16 Feb 2021 19:21:01 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id 4sm336466pjc.23.2021.02.16.19.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 19:21:00 -0800 (PST) From: Joel Stanley To: Simon Glass , u-boot@lists.denx.de Cc: Andrew Jeffery Subject: [PATCH 2/3] fit: Use hash.c to call SHA code Date: Wed, 17 Feb 2021 13:50:41 +1030 Message-Id: <20210217032042.425512-3-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 Currently the FIT hashing will call directly into the SHA algorithms to get a hash. This moves the fit code to use hash_lookup_algo, giving a common entrypoint into the hashing code and removing the duplicated algorithm look up. It also allows the use of hardware acceleration if configured. Signed-off-by: Joel Stanley --- common/image-fit.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) -- 2.30.0 diff --git a/common/image-fit.c b/common/image-fit.c index 28b3d2b19111..3451cdecc95b 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1210,37 +1210,19 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) * 0, on success * -1, when algo is unsupported */ -int calculate_hash(const void *data, int data_len, const char *algo, +int calculate_hash(const void *data, int data_len, const char *algo_name, uint8_t *value, int *value_len) { - if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) { - *((uint32_t *)value) = crc32_wd(0, data, data_len, - CHUNKSZ_CRC32); - *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value)); - *value_len = 4; - } else if (IMAGE_ENABLE_SHA1 && strcmp(algo, "sha1") == 0) { - sha1_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA1); - *value_len = 20; - } else if (IMAGE_ENABLE_SHA256 && strcmp(algo, "sha256") == 0) { - sha256_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA256); - *value_len = SHA256_SUM_LEN; - } else if (IMAGE_ENABLE_SHA384 && strcmp(algo, "sha384") == 0) { - sha384_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA384); - *value_len = SHA384_SUM_LEN; - } else if (IMAGE_ENABLE_SHA512 && strcmp(algo, "sha512") == 0) { - sha512_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA512); - *value_len = SHA512_SUM_LEN; - } else if (IMAGE_ENABLE_MD5 && strcmp(algo, "md5") == 0) { - md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5); - *value_len = 16; - } else { + struct hash_algo *algo; + + if (hash_lookup_algo(algo_name, &algo)) { debug("Unsupported hash alogrithm\n"); return -1; } + + algo->hash_func_ws(data, data_len, value, algo->chunk_size); + *value_len = algo->digest_size; + return 0; } 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"