* [PATCH] image: Avoid erroneous double byte-swap in CRC value
@ 2021-09-14 20:53 Alexandru Gagniuc
2021-09-14 22:44 ` Tom Rini
0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Gagniuc @ 2021-09-14 20:53 UTC (permalink / raw)
To: u-boot; +Cc: Alexandru Gagniuc, trini, marex
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 <trini@konsulko.com>
Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
---
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;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] image: Avoid erroneous double byte-swap in CRC value
2021-09-14 20:53 [PATCH] image: Avoid erroneous double byte-swap in CRC value Alexandru Gagniuc
@ 2021-09-14 22:44 ` Tom Rini
0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2021-09-14 22:44 UTC (permalink / raw)
To: Alexandru Gagniuc; +Cc: u-boot, marex
[-- Attachment #1: Type: text/plain, Size: 948 bytes --]
On Tue, Sep 14, 2021 at 03:53:33PM -0500, Alexandru Gagniuc wrote:
> 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 <trini@konsulko.com>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Applied to u-boot/master, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-14 22:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 20:53 [PATCH] image: Avoid erroneous double byte-swap in CRC value Alexandru Gagniuc
2021-09-14 22:44 ` Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.