From patchwork Tue Sep 14 20:53:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Gagniuc X-Patchwork-Id: 1528136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=doKfLqWB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H8Fv73bzRz9sQt for ; Wed, 15 Sep 2021 06:53:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B0DB2805DF; Tue, 14 Sep 2021 22:53:43 +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="doKfLqWB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DC0DD80C8A; Tue, 14 Sep 2021 22:53:40 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (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 4A931805DF for ; Tue, 14 Sep 2021 22:53:37 +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-x331.google.com with SMTP id i3-20020a056830210300b0051af5666070so438134otc.4 for ; Tue, 14 Sep 2021 13:53:37 -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:mime-version :content-transfer-encoding; bh=FQRzcvVAtlwIKYwQgbi+w5Y+e7z9tD8cheEcgFo2Cxk=; b=doKfLqWBUkC8axUvNGCzXJcjLEu0mAwGAGWQtc/o8v+I8N4kOvjVvsg+7AAAHhuGli PSaqK8grVbMIqUMWBs2Ef/9DEk5h5SUeQr3tQ4vjIEjgP3G2WQc3zhEllm+TPv2vaZXR Z4y+AmvAXbsxCUzVhl0Z2KkDsjz1T62UMKVH3zHqZXMUo+TJ+d2OmYlUSMi/gMYFF5BK w+Y66F6F6QOyzcG2E0QpMvd7nQo1DkXe/CUKUY11yTCOEYnbRr8rMUfJlDe8+uYiDkk4 uyNUQGUFKHrilvmhDLPiTKB+rbZiLO48UHwabeUBevYaXKadWoA5drJ2Wsfpazc2QNaD h+kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FQRzcvVAtlwIKYwQgbi+w5Y+e7z9tD8cheEcgFo2Cxk=; b=HQ9pF12XLZ460CBcZ1OxjDFeTH1hq+qNkl+HgyZaJKVrIfQTeb1EnrovxquW6QjO3t RjTR4ulhmy6jfyBDa9DvO+1sgrRcEc5HxsM84ew/PS/Z2XJq76zANGKw1HdE2I8djipl bTNL7AkiDhE9FBb5yxxb5I+1fgjoOKQeb3ERdOgbIZBcTjm+buaWYY+FkCposbbI8Gyv Ar9oyJ7wAkK2U5tN1uLv02YYUK1K0Wikl5LTGAUEWWkIYi+bzPu18zo5Xna9cR2sfhsn 6y4H1AL21NHpgJEVGqmnFAD9AQcVWqqDvKCBqkRAgFhRNKqNh8Ss2zX5TYME98uwINy0 YRIg== X-Gm-Message-State: AOAM532qE/T6QALEnmwKNVV+Yvkj1suPf2eNKqlMvNmAbWTUA5FKpdlB vGK3Q1M6lv3HBZsrkuP+LIIoR4vlieg= X-Google-Smtp-Source: ABdhPJyP6T5RVZHjaZTNzHInDvSaBEGJmPWuJAQ5IA+y2BCkoLUTix5ACFB3BPOIO1saTIJu6JtcDQ== X-Received: by 2002:a05:6830:1559:: with SMTP id l25mr15988580otp.343.1631652815541; Tue, 14 Sep 2021 13:53:35 -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 u15sm2951632oon.35.2021.09.14.13.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 13:53:34 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de Cc: Alexandru Gagniuc , trini@konsulko.com, marex@denx.de Subject: [PATCH] image: Avoid erroneous double byte-swap in CRC value Date: Tue, 14 Sep 2021 15:53:33 -0500 Message-Id: <20210914205333.3519115-1-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 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.103.2 at phobos.denx.de X-Virus-Status: Clean The hash algorithm selection was streamlined in commit 92055e138f28 ("image: Drop if/elseif hash selection in calculate_hash()"). Said commit kept the call to cpu_to_uimage() to convert the CRC to big endian format. This would have been correct when calling crc32_wd(). However, the ->hash_func_ws member of crc32 points to crc32_wd_buf(), which already converts the CRC to big endian. On a little endian host, doing both conversions results in a little-endian CRC. This is incorrect. To remedy this, simply drop the call to cpu_to_uimage(), thus only doing the byte-order conversion once. Fixes: 92055e138f28 ("image: Drop if/elseif hash selection in calculate_hash()") Tested-by: Tom Rini Signed-off-by: Alexandru Gagniuc --- common/image-fit.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 92d9141bcd..f02d437539 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1193,12 +1193,6 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) return 0; } -static void crc32_uimage_fixup(void *value) -{ - /* TODO: In C, this type punning is undefined behavior: */ - *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value)); -} - /** * calculate_hash - calculate and return hash for provided input data * @data: pointer to the input data @@ -1232,9 +1226,6 @@ int calculate_hash(const void *data, int data_len, const char *name, algo->hash_func_ws(data, data_len, value, algo->chunk_size); *value_len = algo->digest_size; - if (!strcmp(name, "crc32")) - crc32_uimage_fixup(value); - return 0; }