From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 116DFC433EF for ; Fri, 3 Sep 2021 00:55:47 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8822C6108B for ; Fri, 3 Sep 2021 00:55:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8822C6108B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3A53C83535; Fri, 3 Sep 2021 02:55:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PB9lSUwG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6B2E583506; Fri, 3 Sep 2021 02:54:40 +0200 (CEST) Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) (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 B83F383511 for ; Fri, 3 Sep 2021 02:54:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-ot1-x330.google.com with SMTP id m7-20020a9d4c87000000b0051875f56b95so4799745otf.6 for ; Thu, 02 Sep 2021 17:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XTrkweMJ7/XMrPnkjS1CV/STQ8b0D0NM3RE2F9v4ZVc=; b=PB9lSUwGnQBSlvvSzEO3i+y3Zqk/urTJluXDFc57BHcstsImCmTONgYa49/k2sAf0n 4sCY6QLE1Hsc6s4cP4darGv2CADKh/p4iICJUacic/Rb1wDe9qM/C3ts9uouCJOQiy26 at1LarYiuo/tbnuERftJ+9GUWNqJCUNXghiGeDmLAUY2/WPVgpVOof3T9ItUjJb6fZ1n 9lLspVSR0Jvt2y8I2M3kwaIitkg2COYIjwvZNXiWXw9pybm9zRnA7M+E7qk6Vu49jluc Xih80iNkePWycVLsdKnic7ILNgbI8kcOkx2BOcfPn7f4kggZiv7/pAWp62jFQXBCnhFW idBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XTrkweMJ7/XMrPnkjS1CV/STQ8b0D0NM3RE2F9v4ZVc=; b=IVQHf0/U7voLOpSsyuHePCUTWG16mlaeZ9AjVyH4q1eW7lhJ4v5im7/le7LfK5UYod dwijYjR0ZwpWck+euwH/BHIo1QM8qAZhJzwhDeAqj94NIYM04vzEecHYt1o6Vx/r8UDu fVDFhsSdBkydytbk2tNClH7PZSd1dSkS7134qtKuicI/BzqHvsQ+g611DIhjqu3MjH89 0gJzB1dO2c3bTbZTWPzTKJu9MYkdoBknWbmb75OCkkeiZR2wgTeKWiF/3VmJK+cEiWyn NASLScT57RZ/Bijl4ZNmTwVkzp652iF7IWluu63AvSF0YusUENRKMkpi1B6RVrpb/VzU nK5g== X-Gm-Message-State: AOAM532/DxGIyibJIcZRuP0aKATDodr3SxqnaZCwEKaes8XlREuvQ8zj 9rIciqGMBCNt/UYvx4fNYu5pxP+Q+Wk= X-Google-Smtp-Source: ABdhPJxRzT3LlQ8DhNBb0Elgt9c5Eba+3mkh7A9eWkSPfPRdn3GP3YZKUaQ12lfaiD5/nTs/v1ssXA== X-Received: by 2002:a05:6830:91:: with SMTP id a17mr813723oto.189.1630630469331; Thu, 02 Sep 2021 17:54:29 -0700 (PDT) Received: from nuclearis3.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id 186sm708396ood.39.2021.09.02.17.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 17:54:28 -0700 (PDT) From: Alexandru Gagniuc To: trini@konsulko.com, u-boot@lists.denx.de Cc: sjg@chromium.org, Alexandru Gagniuc Subject: [PATCH v2 4/6] common: Move MD5 hash to hash_algo[] array. Date: Thu, 2 Sep 2021 19:54:20 -0500 Message-Id: <20210903005422.1336362-5-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210903005422.1336362-1-mr.nuke.me@gmail.com> References: <20210903005422.1336362-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 MD5 is being called directly in some places, but it is not available via hash_lookup_algo("md5"). This is inconsistent with other hasing routines. To resolve this, add an "md5" entry to hash_algos[]. The #ifdef clause looks funnier than those for other entries. This is because both MD5 and SPL_MD5 configs exist, whereas the other hashes do not have "SPL_" entries. The long term plan is to get rid of the ifdefs, so those should not be expected to survive much longer. The md5 entry does not have .hash_init/update/finish members. That's okay because hash_progressive_lookup_algo() will catch that, and return -EPROTONOSUPPORT, while hash_lookup_algo() will return the correct pointer. Signed-off-by: Alexandru Gagniuc --- common/hash.c | 13 +++++++++++++ include/image.h | 1 + include/u-boot/md5.h | 6 ++++-- lib/md5.c | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/common/hash.c b/common/hash.c index dca23635ab..4587d78301 100644 --- a/common/hash.c +++ b/common/hash.c @@ -207,12 +207,25 @@ static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf, return 0; } +#ifdef USE_HOSTCC +# define I_WANT_MD5 1 +#else +# define I_WANT_MD5 IS_ENABLED(MD5) +#endif /* * These are the hash algorithms we support. If we have hardware acceleration * is enable we will use that, otherwise a software version of the algorithm. * Note that algorithm names must be in lower case. */ static struct hash_algo hash_algo[] = { +#if I_WANT_MD5 + { + .name = "md5", + .digest_size = MD5_SUM_LEN, + .chunk_size = CHUNKSZ_MD5, + .hash_func_ws = md5_wd, + }, +#endif #ifdef CONFIG_SHA1 { .name = "sha1", diff --git a/include/image.h b/include/image.h index 489b220eba..e4b9cd0df2 100644 --- a/include/image.h +++ b/include/image.h @@ -31,6 +31,7 @@ struct fdt_region; #define IMAGE_ENABLE_OF_LIBFDT 1 #define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */ #define CONFIG_FIT_RSASSA_PSS 1 +#define CONFIG_MD5 #define CONFIG_SHA1 #define CONFIG_SHA256 #define CONFIG_SHA384 diff --git a/include/u-boot/md5.h b/include/u-boot/md5.h index e09c16a6e3..6d48592aa6 100644 --- a/include/u-boot/md5.h +++ b/include/u-boot/md5.h @@ -8,6 +8,8 @@ #include "compiler.h" +#define MD5_SUM_LEN 16 + struct MD5Context { __u32 buf[4]; __u32 bits[2]; @@ -28,7 +30,7 @@ void md5 (unsigned char *input, int len, unsigned char output[16]); * 'output' must have enough space to hold 16 bytes. If 'chunk' Trigger the * watchdog every 'chunk_sz' bytes of input processed. */ -void md5_wd (unsigned char *input, int len, unsigned char output[16], - unsigned int chunk_sz); +void md5_wd(const unsigned char *input, unsigned int len, + unsigned char output[16], unsigned int chunk_sz); #endif /* _MD5_H */ diff --git a/lib/md5.c b/lib/md5.c index 2ae4a06319..e2ba622ea4 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -284,12 +284,12 @@ md5 (unsigned char *input, int len, unsigned char output[16]) * watchdog every 'chunk_sz' bytes of input processed. */ void -md5_wd (unsigned char *input, int len, unsigned char output[16], +md5_wd(const unsigned char *input, unsigned int len, unsigned char output[16], unsigned int chunk_sz) { struct MD5Context context; #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - unsigned char *end, *curr; + const unsigned char *end, *curr; int chunk; #endif -- 2.31.1