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; }