Add benchmarks for LedHash256, and tweak for performance.
Also benchmark against Blake3.
This commit is contained in:
parent
3f3cf5dd3a
commit
a41e1dd7de
436
Cargo.lock
generated
436
Cargo.lock
generated
|
@ -19,13 +19,25 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
|
@ -47,6 +59,8 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
|||
name = "backend"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"criterion",
|
||||
"proptest",
|
||||
"ropey",
|
||||
"unicode-segmentation",
|
||||
|
@ -79,6 +93,41 @@ version = "1.2.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"constant_time_eq",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.7.0"
|
||||
|
@ -91,6 +140,18 @@ version = "1.4.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
@ -99,9 +160,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.3"
|
||||
version = "2.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
|
@ -118,6 +179,93 @@ version = "0.4.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7"
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
||||
|
||||
[[package]]
|
||||
name = "criterion"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"cast",
|
||||
"clap",
|
||||
"criterion-plot",
|
||||
"csv",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"num-traits",
|
||||
"oorandom",
|
||||
"plotters",
|
||||
"rayon",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_cbor",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"tinytemplate",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "criterion-plot"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876"
|
||||
dependencies = [
|
||||
"cast",
|
||||
"itertools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"memoffset",
|
||||
"once_cell",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.20.0"
|
||||
|
@ -143,12 +291,61 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"csv-core",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv-core"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "discard"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||
|
||||
[[package]]
|
||||
name = "filedescriptor"
|
||||
version = "0.8.0"
|
||||
|
@ -176,6 +373,16 @@ dependencies = [
|
|||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.3"
|
||||
|
@ -187,6 +394,12 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "1.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
|
@ -205,12 +418,30 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
|
@ -241,6 +472,21 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.7.13"
|
||||
|
@ -281,6 +527,28 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e"
|
||||
|
||||
[[package]]
|
||||
name = "oorandom"
|
||||
version = "11.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.11.1"
|
||||
|
@ -306,6 +574,34 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plotters"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "716b4eeb6c4a1d3ecc956f75b43ec2e8e8ba80026413e70a3f41fd3313d3492b"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
"plotters-backend",
|
||||
"plotters-svg",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plotters-backend"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142"
|
||||
|
||||
[[package]]
|
||||
name = "plotters-svg"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f"
|
||||
dependencies = [
|
||||
"plotters-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
|
@ -417,6 +713,30 @@ dependencies = [
|
|||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"crossbeam-deque",
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.9"
|
||||
|
@ -426,6 +746,21 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.27"
|
||||
|
@ -477,6 +812,15 @@ version = "1.0.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
|
@ -504,6 +848,16 @@ version = "1.0.126"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03"
|
||||
|
||||
[[package]]
|
||||
name = "serde_cbor"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5"
|
||||
dependencies = [
|
||||
"half",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.126"
|
||||
|
@ -632,6 +986,12 @@ version = "0.8.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.73"
|
||||
|
@ -724,6 +1084,22 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinytemplate"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.7.1"
|
||||
|
@ -763,6 +1139,17 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
|
@ -771,9 +1158,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.74"
|
||||
version = "0.2.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd"
|
||||
checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
|
@ -781,13 +1168,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.74"
|
||||
version = "0.2.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900"
|
||||
checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
|
@ -796,9 +1183,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.74"
|
||||
version = "0.2.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4"
|
||||
checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
|
@ -806,9 +1193,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.74"
|
||||
version = "0.2.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97"
|
||||
checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -819,9 +1206,19 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.74"
|
||||
version = "0.2.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f"
|
||||
checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
|
@ -839,6 +1236,15 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
|
|
@ -15,4 +15,10 @@ ropey = "1"
|
|||
unicode-segmentation = "1.7"
|
||||
|
||||
[dev-dependencies]
|
||||
blake3 = "1.3.1"
|
||||
proptest = "1.0"
|
||||
criterion = "0.3.6"
|
||||
|
||||
[[bench]]
|
||||
name = "hash"
|
||||
harness = false
|
||||
|
|
120
sub_crates/backend/benches/hash.rs
Normal file
120
sub_crates/backend/benches/hash.rs
Normal file
|
@ -0,0 +1,120 @@
|
|||
use backend::hash::LedHash256;
|
||||
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
|
||||
|
||||
//----
|
||||
|
||||
fn hash_10b(c: &mut Criterion) {
|
||||
let size = 10;
|
||||
|
||||
let mut group = c.benchmark_group("hash_10b");
|
||||
let data: Vec<u8> = b"abcdefghijklmnopqrstuvwxyz"
|
||||
.iter()
|
||||
.copied()
|
||||
.cycle()
|
||||
.take(size)
|
||||
.collect();
|
||||
group.throughput(Throughput::Bytes(size as u64));
|
||||
|
||||
group.bench_function("led256", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = LedHash256::new();
|
||||
hash.update(&data);
|
||||
hash.finish();
|
||||
})
|
||||
});
|
||||
|
||||
group.bench_function("blake3", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = blake3::Hasher::new();
|
||||
hash.update(&data);
|
||||
hash.finalize();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn hash_1kb(c: &mut Criterion) {
|
||||
let size = 1000;
|
||||
|
||||
let mut group = c.benchmark_group("hash_1kb");
|
||||
let data: Vec<u8> = b"abcdefghijklmnopqrstuvwxyz"
|
||||
.iter()
|
||||
.copied()
|
||||
.cycle()
|
||||
.take(size)
|
||||
.collect();
|
||||
group.throughput(Throughput::Bytes(size as u64));
|
||||
|
||||
group.bench_function("led256", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = LedHash256::new();
|
||||
hash.update(&data);
|
||||
hash.finish();
|
||||
})
|
||||
});
|
||||
|
||||
group.bench_function("blake3", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = blake3::Hasher::new();
|
||||
hash.update(&data);
|
||||
hash.finalize();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn hash_100kb(c: &mut Criterion) {
|
||||
let size = 100_000;
|
||||
|
||||
let mut group = c.benchmark_group("hash_100kb");
|
||||
let data: Vec<u8> = b"abcdefghijklmnopqrstuvwxyz"
|
||||
.iter()
|
||||
.copied()
|
||||
.cycle()
|
||||
.take(size)
|
||||
.collect();
|
||||
group.throughput(Throughput::Bytes(size as u64));
|
||||
|
||||
group.bench_function("led256_1k_chunk", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = LedHash256::new();
|
||||
for chunk in data.chunks(1000) {
|
||||
hash.update(chunk);
|
||||
}
|
||||
hash.finish();
|
||||
})
|
||||
});
|
||||
|
||||
group.bench_function("led256_10k_chunk", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = LedHash256::new();
|
||||
for chunk in data.chunks(10000) {
|
||||
hash.update(chunk);
|
||||
}
|
||||
hash.finish();
|
||||
})
|
||||
});
|
||||
|
||||
group.bench_function("blake3_1k_chunk", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = blake3::Hasher::new();
|
||||
for chunk in data.chunks(1000) {
|
||||
hash.update(chunk);
|
||||
}
|
||||
hash.finalize();
|
||||
})
|
||||
});
|
||||
|
||||
group.bench_function("blake3_10k_chunk", |bench| {
|
||||
bench.iter(|| {
|
||||
let mut hash = blake3::Hasher::new();
|
||||
for chunk in data.chunks(10000) {
|
||||
hash.update(chunk);
|
||||
}
|
||||
hash.finalize();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
//----
|
||||
|
||||
criterion_group!(benches, hash_10b, hash_1kb, hash_100kb);
|
||||
criterion_main!(benches);
|
|
@ -1,16 +1,22 @@
|
|||
/// A 256-bit non-cryptographic hash function for data identification.
|
||||
///
|
||||
/// This uses the MIX function, constants, and permutation patterns
|
||||
/// from Skein v1.3, but is otherwise largely unrelated--in particular
|
||||
/// it does not use sub-keys, tweak values, or UBI from Skein.
|
||||
///
|
||||
/// This implementation assumes support for 64-bit unsigned integers.
|
||||
///
|
||||
/// This implementation should work on platforms of any endianness,
|
||||
/// but has only been tested on little endian platforms. Running the
|
||||
/// unit tests on a big-endian platform can verify.
|
||||
//! A 256-bit non-cryptographic hash function.
|
||||
//!
|
||||
//! This is intended to be used as a fast, high-quality checksum for
|
||||
//! non-adversarial data identification. It is not intended to stand
|
||||
//! up to attacks of any kind.
|
||||
//!
|
||||
//! This uses the MIX function and permutation patterns from Skein v1.3,
|
||||
//! but is otherwise unrelated. For example, it is not tweakable and
|
||||
//! uses far fewer rounds per data chunk.
|
||||
//!
|
||||
//! This implementation assumes support for 64-bit unsigned integers.
|
||||
//!
|
||||
//! This implementation should work on platforms of any endianness,
|
||||
//! but has only been tested on little endian platforms. Running the
|
||||
//! unit tests on a big-endian platform can verify.
|
||||
|
||||
const BLOCK_SIZE: usize = 256 / 8; // Block size of the hash, in bytes
|
||||
const BLOCK_SIZE: usize = 256 / 8; // Block size of the hash, in bytes.
|
||||
const UPDATE_MIX_ROUNDS: usize = 2;
|
||||
const FINISH_MIX_ROUNDS: usize = 6;
|
||||
|
||||
/// Convenience function to generate a hash for a block of data.
|
||||
pub fn hash(data: &[u8]) -> [u8; BLOCK_SIZE] {
|
||||
|
@ -22,7 +28,7 @@ pub fn hash(data: &[u8]) -> [u8; BLOCK_SIZE] {
|
|||
/// A hash builder. Consumes bytes and generates a 256-bit hash.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(C)]
|
||||
#[repr(align(8))]
|
||||
#[repr(align(32))]
|
||||
pub struct LedHash256 {
|
||||
state: [u64; 4], // Hash state.
|
||||
buf: [u8; BLOCK_SIZE], // Accumulates message data for processing.
|
||||
|
@ -34,11 +40,10 @@ impl LedHash256 {
|
|||
pub fn new() -> LedHash256 {
|
||||
LedHash256 {
|
||||
state: [
|
||||
// Initial Chaining Values from Skein-256-256, v1.3
|
||||
0xFC9DA860D048B449,
|
||||
0x2FCA66479FA7D833,
|
||||
0xB33BC3896656840F,
|
||||
0x6A54E920FDE8DA69,
|
||||
0x302f7bfd333d0b0d,
|
||||
0xb98cf5312d92a4d5,
|
||||
0xb1c885da4c257a6e,
|
||||
0xedb85f57b82c7e10,
|
||||
],
|
||||
buf: [0; BLOCK_SIZE],
|
||||
buf_length: 0,
|
||||
|
@ -51,11 +56,11 @@ impl LedHash256 {
|
|||
self.message_length += data.len() as u64;
|
||||
|
||||
let mut data = data;
|
||||
|
||||
while !data.is_empty() {
|
||||
if self.buf_length >= BLOCK_SIZE {
|
||||
// Process the filled buffer
|
||||
self.mix_buffer_into_state();
|
||||
self.add_buffer_to_state();
|
||||
self.mix_state(UPDATE_MIX_ROUNDS);
|
||||
self.buf_length = 0;
|
||||
} else {
|
||||
// Fill the buffer.
|
||||
|
@ -71,19 +76,15 @@ impl LedHash256 {
|
|||
pub fn finish(mut self) -> [u8; BLOCK_SIZE] {
|
||||
// Hash the remaining bytes if there are any.
|
||||
if self.buf_length > 0 {
|
||||
for i in (&mut self.buf[self.buf_length..]).iter_mut() {
|
||||
*i = 0;
|
||||
}
|
||||
self.mix_buffer_into_state();
|
||||
self.buf_length = 0;
|
||||
(&mut self.buf[self.buf_length..]).fill(0);
|
||||
self.add_buffer_to_state();
|
||||
self.mix_state(UPDATE_MIX_ROUNDS);
|
||||
}
|
||||
|
||||
// Hash the message length, in bits.
|
||||
self.buf[..8].copy_from_slice(&(self.message_length * 8).to_le_bytes());
|
||||
for i in (&mut self.buf[8..]).iter_mut() {
|
||||
*i = 0;
|
||||
}
|
||||
self.mix_buffer_into_state();
|
||||
// Incorporate the message length (in bits) and do the
|
||||
// final mixing.
|
||||
self.state[0] ^= self.message_length * 8;
|
||||
self.mix_state(FINISH_MIX_ROUNDS);
|
||||
|
||||
// Get the digest as a byte array and return it.
|
||||
let mut digest = [0u8; BLOCK_SIZE];
|
||||
|
@ -94,27 +95,8 @@ impl LedHash256 {
|
|||
return digest;
|
||||
}
|
||||
|
||||
/// The main mix function. Mixes the buffer into the hash state.
|
||||
///
|
||||
/// Inspired by Skein 1.3, and using its MIX function and its constants.
|
||||
/// This does 9 rounds of mixing, as that produces full diffusion for
|
||||
/// 256-bit state according to the Skein 1.3 paper.
|
||||
///
|
||||
/// The mix rotation constants, as taken from Skein 1.3 256-bit variant:
|
||||
/// 14 16
|
||||
/// 52 57
|
||||
/// 23 40
|
||||
/// 5 37
|
||||
/// 25 33
|
||||
/// 46 12
|
||||
/// 58 22
|
||||
/// 32 32
|
||||
/// repeat
|
||||
///
|
||||
/// The permute table, as taken from Skein 1.3 256-bit variant:
|
||||
/// Indices: 0 1 2 3
|
||||
/// Become: 0 3 2 1
|
||||
fn mix_buffer_into_state(&mut self) {
|
||||
/// Adds the current contents of the buffer to the hash state.
|
||||
fn add_buffer_to_state(&mut self) {
|
||||
// Convert the buffer to native endian u64's and xor into the
|
||||
// hash state.
|
||||
let (a, b, c) = unsafe { self.buf.align_to::<u64>() };
|
||||
|
@ -124,32 +106,42 @@ impl LedHash256 {
|
|||
self.state[1] ^= u64::from_le(b[1]);
|
||||
self.state[2] ^= u64::from_le(b[2]);
|
||||
self.state[3] ^= u64::from_le(b[3]);
|
||||
}
|
||||
|
||||
// Mixing constants.
|
||||
const ROUNDS: usize = 9;
|
||||
const ROTATION_TABLE: [(u32, u32); 8] = [
|
||||
(14, 16),
|
||||
(52, 57),
|
||||
(23, 40),
|
||||
(5, 37),
|
||||
(25, 33),
|
||||
(46, 12),
|
||||
(58, 22),
|
||||
(32, 32),
|
||||
];
|
||||
|
||||
// Do the mixing.
|
||||
for &(rot_1, rot_2) in ROTATION_TABLE.iter().cycle().take(ROUNDS) {
|
||||
/// The main mix function. Mixes the hash state.
|
||||
///
|
||||
/// Inspired by Skein 1.3, and using its MIX function.
|
||||
///
|
||||
/// The mix rotation constants are:
|
||||
/// - 40 50
|
||||
/// - 27 21
|
||||
///
|
||||
/// They were selected by an exhaustive search of the four-constant
|
||||
/// space, selecting for the best single-bit diffusion at a small
|
||||
/// number of rounds.
|
||||
///
|
||||
/// The permute table is:
|
||||
/// - Indices: 0 1 2 3
|
||||
/// - Become: 0 1 3 2
|
||||
fn mix_state(&mut self, rounds: usize) {
|
||||
for _ in 0..rounds {
|
||||
// Skein MIX function.
|
||||
self.state[0] = self.state[0].wrapping_add(self.state[1]);
|
||||
self.state[1] = self.state[1].rotate_left(rot_1) ^ self.state[0];
|
||||
|
||||
// Skein MIX function.
|
||||
self.state[2] = self.state[2].wrapping_add(self.state[3]);
|
||||
self.state[3] = self.state[3].rotate_left(rot_2) ^ self.state[2];
|
||||
self.state[0] = self.state[0].wrapping_add(self.state[2]);
|
||||
self.state[1] = self.state[1].wrapping_add(self.state[3]);
|
||||
self.state[2] = self.state[2].rotate_left(40) ^ self.state[0];
|
||||
self.state[3] = self.state[3].rotate_left(50) ^ self.state[1];
|
||||
|
||||
// Permute.
|
||||
self.state.swap(1, 3);
|
||||
self.state.swap(2, 3);
|
||||
|
||||
// Skein MIX function.
|
||||
self.state[0] = self.state[0].wrapping_add(self.state[2]);
|
||||
self.state[1] = self.state[1].wrapping_add(self.state[3]);
|
||||
self.state[2] = self.state[2].rotate_left(27) ^ self.state[0];
|
||||
self.state[3] = self.state[3].rotate_left(21) ^ self.state[1];
|
||||
|
||||
// Permute.
|
||||
self.state.swap(2, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,47 +183,47 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn hash_empty() {
|
||||
let correct_digest = "4c0995f905f4e502606dfbaadac265ac4de79d68a61d2ad6431432b0e88cacdb";
|
||||
let correct_digest = "3c26b703d4d7316c7bc6fc8e72893433cb10e1044fb5100ac89d2a67c85ff1a1";
|
||||
assert_eq!(digest_to_string(hash(&[])), correct_digest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_zero() {
|
||||
let correct_digest = "9061db6180de3b2193eca59ada3d00472d0bb25ecced849b55586b367d8e10bd";
|
||||
let correct_digest = "65670a6fd5d2e919f3d5ec856dd18d7c66397683e47f059ac19f2533b1607708";
|
||||
assert_eq!(digest_to_string(hash(&[0u8])), correct_digest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_one() {
|
||||
let correct_digest = "a781e5d5375ece4306b8406e25132be4b50a0af93d544a280dc67cde890235a8";
|
||||
let correct_digest = "6666ad08b0d0164f1972f36be7541c04b6e22947710d52b2733dcd3007908b82";
|
||||
assert_eq!(digest_to_string(hash(&[1u8])), correct_digest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_string_01() {
|
||||
let s = "abc";
|
||||
let correct_digest = "08c83bd40744cd323890d1d1ca72274c4ec4a0e1de0b68761248b1bdd70a845a";
|
||||
let correct_digest = "891862c9ad6003a588194f7b59c6760d48083faa5eda5ade03b5eb0551c538e6";
|
||||
assert_eq!(digest_to_string(hash(s.as_bytes())), correct_digest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_string_02() {
|
||||
let s = "The quick brown fox jumps over the lazy dog.";
|
||||
let correct_digest = "f94bd8c035958bb27c5a733ad7efd21286da12b9cf33a6496d9b9e35813720b7";
|
||||
let correct_digest = "347cce28ceb133b8ab30cca93e52460c40d30156ddf9122b3e13a6239c1e3f17";
|
||||
assert_eq!(digest_to_string(hash(s.as_bytes())), correct_digest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_string_03() {
|
||||
let s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let correct_digest = "9e54edbe1611f9c5e0a306240537df41d2ca1d584a125119cbf09fdb2f6ab880";
|
||||
let correct_digest = "99b7eeae84e40ef9371b398af09e4cad00e800417b74b45f5af6042b49d03e1e";
|
||||
assert_eq!(digest_to_string(hash(s.as_bytes())), correct_digest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_string_04() {
|
||||
let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||
let correct_digest = "5e4a25a709236e55995eee313495ae1d43c09d4acfec69a107b65be20b6c3863";
|
||||
let correct_digest = "8d84fe8c5bc2a41ba0f0f57013bef7f038acf1d2d6a77ebc4d1b0fa14c10629c";
|
||||
assert_eq!(digest_to_string(hash(s.as_bytes())), correct_digest);
|
||||
}
|
||||
|
||||
|
@ -244,7 +236,7 @@ mod test {
|
|||
let test_string4 = "cup";
|
||||
let test_string5 =
|
||||
"idatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||
let correct_digest = "5e4a25a709236e55995eee313495ae1d43c09d4acfec69a107b65be20b6c3863";
|
||||
let correct_digest = "8d84fe8c5bc2a41ba0f0f57013bef7f038acf1d2d6a77ebc4d1b0fa14c10629c";
|
||||
|
||||
let mut hasher = LedHash256::new();
|
||||
hasher.update(test_string1.as_bytes());
|
||||
|
@ -269,15 +261,15 @@ mod test {
|
|||
|
||||
assert_eq!(
|
||||
digest_to_string(hash(len_0)),
|
||||
"4c0995f905f4e502606dfbaadac265ac4de79d68a61d2ad6431432b0e88cacdb",
|
||||
"3c26b703d4d7316c7bc6fc8e72893433cb10e1044fb5100ac89d2a67c85ff1a1",
|
||||
);
|
||||
assert_eq!(
|
||||
digest_to_string(hash(len_1)),
|
||||
"9061db6180de3b2193eca59ada3d00472d0bb25ecced849b55586b367d8e10bd",
|
||||
"65670a6fd5d2e919f3d5ec856dd18d7c66397683e47f059ac19f2533b1607708",
|
||||
);
|
||||
assert_eq!(
|
||||
digest_to_string(hash(len_2)),
|
||||
"054c0440b479e206a28923f5924b7bc0d3f0ead1eaff3360aa56750b98fd5645",
|
||||
"95bba56b21bdaf4a6c8c3a231c4966c0992845757a73fa6bbd48389cf8b7b452",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user