Add xxhash hashing support
PATCH 1/1 Add xxhash hashing support
From: Dmitry Dunaev <[email protected]>
--- common/image-fit.c | 7 ++ include/image.h | 12 +++ include/u-boot/xxhash.h | 143 ++++++++++++++++++++++++++ lib/Kconfig | 8 ++ lib/Makefile | 1 + lib/xxhash.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/Makefile | 2 + 7 files changed, 438 insertions(+) create mode 100644 include/u-boot/xxhash.h create mode 100644 lib/xxhash.c
common/image-fit.c +7 -0
@@ -29,6 +29,7 @@ DECLARE_GLOBAL_DATA_PTR;#include <u-boot/md5.h> #include <u-boot/sha1.h> #include <u-boot/sha256.h> +#include <u-boot/xxhash.h> /*****************************************************************************/ /* New uImage format routines */
@@ -1013,6 +1014,12 @@ int calculate_hash(const void *data, int data_len, const char *algo, }else if (IMAGE_ENABLE_MD5 &&strcmp (algo,"md5" ) ==0 ) {md5_wd ((unsigned char *)data, data_len, value,CHUNKSZ_MD5 ); *value_len =16 ; + }else if (IMAGE_ENABLE_XXHASH &&strcmp (algo,"xxh32" ) ==0 ) { + *((uint32_t *)value) =xxh32_wd (data, data_len,0 ,CHUNKSZ_XXH ); + *value_len =4 ; + }else if (IMAGE_ENABLE_XXHASH &&strcmp (algo,"xxh64" ) ==0 ) { + *((uint64_t *)value) =xxh64_wd (data, data_len,0 ,CHUNKSZ_XXH ); + *value_len =8 ; }else {debug ("Unsupported hash alogrithm\n" );return -1 ;
include/image.h +12 -0
@@ -65,11 +65,15 @@ struct lmb;# ifdef CONFIG_SPL_SHA1_SUPPORT # define IMAGE_ENABLE_SHA1 1# endif +# ifdef CONFIG_SPL_XXHASH_SUPPORT +# define IMAGE_ENABLE_XXHASH 1 +# endif # else # define CONFIG_CRC32 /* FIT images need CRC32 support */ # define IMAGE_ENABLE_CRC32 1# define IMAGE_ENABLE_MD5 1# define IMAGE_ENABLE_SHA1 1 +# define IMAGE_ENABLE_XXHASH 1# endif #ifndef IMAGE_ENABLE_CRC32
@@ -84,6 +88,10 @@ struct lmb;#define IMAGE_ENABLE_SHA1 0#endif +#ifndef IMAGE_ENABLE_XXHASH +#define IMAGE_ENABLE_XXHASH 0 +#endif +#if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT ) || \ defined(CONFIG_SPL_SHA256_SUPPORT )#define IMAGE_ENABLE_SHA256 1
@@ -419,6 +427,10 @@ extern bootm_headers_t images;#define CHUNKSZ_SHA1 (64 * 1024)#endif +#ifndef CHUNKSZ_XXH +#define CHUNKSZ_XXH (64 * 1024) +#endif +#define uimage_to_cpu (x) be32_to_cpu(x)#define cpu_to_uimage (x) cpu_to_be32(x)
include/u-boot/xxhash.h new file +143 -0
143 lines not on this page · raw message
lib/Kconfig +8 -0
@@ -156,6 +156,14 @@ config SHA_PROG_HW_ACCEL Data can be streamed in a block at a time and the hashing is performed in hardware. +config XXHASH + bool "Enable XXHASH support" + help + This option enables support of hashing using XXHASH algorithm. + The hash is calculated in software. + The SHA256 algorithm produces a 32-bit (4-byte) for xxh32 or + 64-bit (8-byte) for xxh64 hash value(digest). + config MD5 bool
lib/Makefile +1 -0
@@ -48,6 +48,7 @@ endif obj-$(CONFIG_RSA) += rsa/ obj-$(CONFIG_SHA1) += sha1.o obj-$(CONFIG_SHA256) += sha256.o +obj-$(CONFIG_XXHASH) += xxhash.o obj-$(CONFIG_$(SPL_)ZLIB) += zlib/ obj-$(CONFIG_$(SPL_)GZIP) += gunzip.o
lib/xxhash.c new file +265 -0
265 lines not on this page · raw message
tools/Makefile +2 -0
@@ -105,6 +105,7 @@ dumpimage-mkimage-objs := aisimage.o \ socfpgaimage.o \ lib/sha1.o \ lib/sha256.o \ + lib/xxhash.o \ common/hash.o \ ublimage.o \ zynqimage.o \
@@ -200,6 +201,7 @@ HOSTCFLAGS_crc8.o := -pedantic HOSTCFLAGS_md5.o := -pedantic HOSTCFLAGS_sha1.o := -pedantic HOSTCFLAGS_sha256.o := -pedantic +HOSTCFLAGS_xxhash.o := -pedantic quiet_cmd_wrap = WRAP $@ cmd_wrap = echo "\#include <../$(patsubst $(obj)/%,%,$@)>" >$@
Signature · 1 line
2.7.4
PATCH 1/1 Add xxhash hashing support
Quoted 1 line · dunaev at tecon.ru
From: Dmitry Dunaev <[email protected]>
Please add some comments about why we're adding this support and where it's used.
[snip]
Quoted 8 lines
common/image-fit.c | 7 ++ include/image.h | 12 +++ include/u-boot/xxhash.h | 143 ++++++++++++++++++++++++++ lib/Kconfig | 8 ++ lib/Makefile | 1 + lib/xxhash.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/Makefile | 2 + 7 files changed, 438 insertions(+)
Please enable this for sandbox, where it should build cleanly and without warnings. If you can add a test for it under test/py/tests/ that would be even better.
Quoted 11 lines
include/u-boot/xxhash.h new file +5
-0@@ -0,0 +1,143 @@ +/* +* xxHash - Extremely Fast Hash algorithm +* Copyright (C) 2012-2016, Yann Collet. +* +* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
[snip]
lib/xxhash.c line 5
Quoted 11 lines
lib/xxhash.c new file +5
-0@@ -0,0 +1,265 @@ +/* +* xxHash - Extremely Fast Hash algorithm +* Copyright (C) 2012-2016, Yann Collet. +* +* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
SPDX tag only please.
Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180305/4b46fb51/attachment.sig>
PATCH 1/1 Add xxhash hashing support
In reply to dunaev at tecon.ruDear Dmitry,
Quoted 3 lines · In message <[email protected]> you wrote:
From: Dmitry Dunaev <[email protected]>
---
It would be appropriate to provide an explantion of what you are doing here and why, which advantages it brings, what it costs (in terms of code size), etc.
In short: please provide a proper commit message.
Quoted 9 lines
+/*
+ * xxHash - Extremely Fast Hash algorithm
+ * Copyright (C) 2012-2016, Yann Collet.
+ *
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
....
Quoted 5 lines
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation. This program is dual-licensed; you may select
+ * either version 2 of the GNU General Public License ("GPL") or BSD license
+ * ("BSD").
Please use SPDX License Tags and remove the license text.
Quoted 21 lines
+ * Notice extracted from xxHash homepage:
+ *
+ * xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
+ * It also successfully passes all tests from the SMHasher suite.
+ *
+ * Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2
+ * Duo @3GHz)
+ *+ * Name Speed Q.Score Author + * xxHash 5.4 GB/s 10 + * CrapWow 3.2 GB/s 2 Andrew + * MumurHash 3a 2.7 GB/s 10 Austin Appleby + * SpookyHash 2.0 GB/s 10 Bob Jenkins + * SBox 1.4 GB/s 9 Bret Mulvey + * Lookup3 1.2 GB/s 9 Bob Jenkins + * SuperFastHash 1.2 GB/s 1 Paul Hsieh + * CityHash64 1.05 GB/s 10 Pike & Alakuijala + * FNV 0.55 GB/s 5 Fowler, Noll, Vo + * CRC32 0.43 GB/s 9 + * MD5-32 0.33 GB/s 10 Ronald L. Rivest + * SHA1-32 0.28 GB/s 10
Quoted 10 lines
+ *
+ * Q.Score is a measure of quality of the hash function.
+ * It depends on successfully passing SMHasher test set.
+ * 10 is a perfect score.
+ *
+ * A 64-bits version, named xxh64 offers much better speed,
+ * but for 64-bits applications only.
+ * Name Speed on 64 bits Speed on 32 bits
+ * xxh64 13.8 GB/s 1.9 GB/s
+ * xxh32 6.8 GB/s 6.0 GB/s
This should probably go to the commit message.
...
Quoted 10 lines
+ *
xxh32_wd()- calculate the 32-bit hash of the input with a given seed.
+ * Triggering the watchdog every 'chunk_sz' bytes of input
+ * processed.
+ *+ * @input: The data to hash. + * @length: The length of the data to hash. + * @seed: The seed can be used to alter the result predictably.+ * @chunk_sz: The chunk size for watchdog triggering.
+ *
+ * Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
Hm... what is this information good for? How fast is it on a MPC860 at 50 MHz? How fast on a iMX28 at 400 MHz?
Quoted 5 lines
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
See above. Clean up all over the place and replace with SPDX tags.
Thanks.
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Intel's new motto: United we stand. Divided we fall!