From patchwork Tue Jul 20 06:38:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiaWei Wang X-Patchwork-Id: 481494 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4838633jao; Mon, 19 Jul 2021 23:41:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXcKzzs++hNooB0aUKOOeYiM2BUevUb/MtiTt7fnQ6zWX8UoV/I7UG8Ejo3XqdfthMPc9Y X-Received: by 2002:aa7:da13:: with SMTP id r19mr39251013eds.252.1626763262042; Mon, 19 Jul 2021 23:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626763262; cv=none; d=google.com; s=arc-20160816; b=YsRvspQfUmQvkLqtPLApdDa08XYAa6V0R4Sunlp5l/LsfKxwPnCoFzgl+0Ho334oPn aC+Nq+QF20ReCcDVj27BPMvrTwuVw6hyYH/7OKO6tGAl7qNzXwLF73crx7x+pZOXpZOm BxFSI01QuYdQyAj1/FJZJWzzElC0F90nqUzspeGyEjCh99+Jy+lR/xVWZ/6arDUx/gnb fiYMJn4+68pj8Q+wsKQA3A/EALnoVb/qYWeh9jJV1trXkyCiHh+QFU9D7C28+rJUNEvk z6q4hTTiM1OcQdM81Le+hIv4E/RC3jrbLarZmaQRdJmxllhbiKd2IBSHEU0LqbnkH4RY NOmg== 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:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=ARthw3mW/dMnAPs+OytOHSZiC158rh2+OeOPaQkzkIQ=; b=tkhVjLfLYlOQAkCRvoX4ZoKlvDHIb+fTo9mgfMjjSiM4t8taZ8imk9aIOjcMcWPjy+ pGwSblw0JMPzyXSvIrDMAaEyduYGkrR5QrIWOFlai5VELcDnAl3D0HkYzaJ7hUHWTaPZ n0Uz3XqObOwOXuebGAWt+QtYijgdc13bI2uC4Rd/+PFs+HgZTLJqYzqhL81nLM2yr51f R2JbXYzHJWCyDMZBRbTM2nkXdKEaR3bltAhw4M5qX9WcWNGWs22xh8vC28M3/oPrqIyZ SmBC7MzeQo5/mxoHMYTNSa14lTlZxs1nh5M8UIv6t1BgpX9NZYvhgCA+CkzaoePXvunz yTFQ== ARC-Authentication-Results: i=1; mx.google.com; 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 u13si14249636ejz.673.2021.07.19.23.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 23:41:02 -0700 (PDT) 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; 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 264F282C67; Tue, 20 Jul 2021 08:40:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 481F58262E; Tue, 20 Jul 2021 08:39:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from twspam01.aspeedtech.com (twspam01.aspeedtech.com [211.20.114.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3A6B9829E4 for ; Tue, 20 Jul 2021 08:39:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=chiawei_wang@aspeedtech.com Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 16K6M68U039588; Tue, 20 Jul 2021 14:22:07 +0800 (GMT-8) (envelope-from chiawei_wang@aspeedtech.com) Received: from ChiaWeiWang-PC.aspeed.com (192.168.2.66) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 20 Jul 2021 14:38:32 +0800 From: Chia-Wei Wang To: , , , CC: , Subject: [PATCH v3 06/14] common: fit: Use hash.c to call CRC/SHA function Date: Tue, 20 Jul 2021 14:38:31 +0800 Message-ID: <20210720063839.1518-7-chiawei_wang@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210720063839.1518-1-chiawei_wang@aspeedtech.com> References: <20210720063839.1518-1-chiawei_wang@aspeedtech.com> MIME-Version: 1.0 X-Originating-IP: [192.168.2.66] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 16K6M68U039588 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.103.2 at phobos.denx.de X-Virus-Status: Clean From: Joel Stanley Currently the FIT verification calls directly into SW implemented functions to get a CRC/SHA/MD5 hash. This patch removes duplcated algorithm lookup and use hash_lookup_algo to get the hashing function with HW accelearation supported if configured. The MD5 direct call remains as it is not included in the hash lookup table of hash.c. Signed-off-by: Joel Stanley Signed-off-by: Chia-Wei Wang --- common/image-fit.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) -- 2.17.1 diff --git a/common/image-fit.c b/common/image-fit.c index 0c5a05948d..e52ff47bc3 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1196,7 +1196,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) * calculate_hash - calculate and return hash for provided input data * @data: pointer to the input data * @data_len: data length - * @algo: requested hash algorithm + * @algo_name: requested hash algorithm * @value: pointer to the char, will hold hash value data (caller must * allocate enough free space) * value_len: length of the calculated hash @@ -1210,37 +1210,22 @@ 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, - uint8_t *value, int *value_len) +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) { + struct hash_algo *algo; + + if (IMAGE_ENABLE_MD5 && strcmp(algo_name, "md5") == 0) { md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5); *value_len = 16; + } else if (hash_lookup_algo(algo_name, &algo) == 0) { + algo->hash_func_ws(data, data_len, value, algo->chunk_size); + *value_len = algo->digest_size; } else { debug("Unsupported hash alogrithm\n"); return -1; } + return 0; }