[ed25519] downgrade rand_core (#21)

* downgrade rand_core

* Update bench.rs

* remove `try_from_rng`
This commit is contained in:
zz-sol 2026-05-18 21:50:26 -04:00 committed by GitHub
parent ed4a212bcb
commit 154b58b3f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 474 additions and 336 deletions

419
Cargo.lock generated
View file

@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "ahash"
version = "0.8.12"
@ -183,6 +198,21 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "backtrace"
version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-link",
]
[[package]]
name = "base64ct"
version = "1.8.3"
@ -317,9 +347,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cc"
version = "1.2.60"
version = "1.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20"
checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98"
dependencies = [
"find-msvc-tools",
"shlex",
@ -331,17 +361,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "chacha20"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601"
dependencies = [
"cfg-if",
"cpufeatures 0.3.0",
"rand_core 0.10.1",
]
[[package]]
name = "ciborium"
version = "0.2.2"
@ -394,6 +413,33 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
[[package]]
name = "color-eyre"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b88ea9df13354b55bc7234ebcce36e6ef896aca2e42a15de9e10edce01b427"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "const-oid"
version = "0.9.6"
@ -554,9 +600,9 @@ dependencies = [
[[package]]
name = "digest"
version = "0.11.2"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4850db49bf08e663084f7fb5c87d202ef91a3907271aff24a94eb97ff039153c"
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
dependencies = [
"block-buffer 0.12.0",
"crypto-common 0.2.1",
@ -569,7 +615,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53"
dependencies = [
"pkcs8",
"serde",
"signature",
]
@ -610,23 +655,6 @@ dependencies = [
"solana-ed25519",
]
[[package]]
name = "ed25519-zebra"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "775765289f7c6336c18d3d66127527820dd45ffd9eb3b6b8ee4708590e6c20f5"
dependencies = [
"curve25519-dalek",
"ed25519",
"hashbrown 0.16.1",
"pkcs8",
"rand_core 0.6.4",
"serde",
"sha2 0.10.9",
"subtle",
"zeroize",
]
[[package]]
name = "educe"
version = "0.6.0"
@ -681,6 +709,16 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "fastrand"
version = "2.4.1"
@ -722,18 +760,36 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "foldhash"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
[[package]]
name = "funty"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]]
name = "futures-core"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
[[package]]
name = "futures-task"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
[[package]]
name = "futures-util"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
"slab",
]
[[package]]
name = "generic-array"
version = "0.14.7"
@ -776,11 +832,16 @@ dependencies = [
"cfg-if",
"libc",
"r-efi 6.0.0",
"rand_core 0.10.1",
"wasip2",
"wasip3",
]
[[package]]
name = "gimli"
version = "0.32.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
[[package]]
name = "glob"
version = "0.3.3"
@ -796,7 +857,7 @@ dependencies = [
"ff",
"rand 0.8.6",
"rand_core 0.6.4",
"rand_xorshift 0.3.0",
"rand_xorshift",
"subtle",
]
@ -819,25 +880,14 @@ checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash 0.1.5",
"foldhash",
]
[[package]]
name = "hashbrown"
version = "0.16.1"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash 0.2.0",
]
[[package]]
name = "hashbrown"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "heck"
@ -874,9 +924,9 @@ dependencies = [
[[package]]
name = "hybrid-array"
version = "0.4.10"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3944cf8cf766b40e2a1a333ee5e9b563f854d5fa49d6a8ca2764e97c6eddb214"
checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da"
dependencies = [
"typenum",
]
@ -887,6 +937,12 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
[[package]]
name = "indenter"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5"
[[package]]
name = "indexmap"
version = "2.14.0"
@ -894,7 +950,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
dependencies = [
"equivalent",
"hashbrown 0.17.0",
"hashbrown 0.17.1",
"serde",
"serde_core",
]
@ -945,14 +1001,22 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
name = "js-sys"
version = "0.3.95"
version = "0.3.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca"
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
dependencies = [
"cfg-if",
"futures-util",
"once_cell",
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "leb128fmt"
version = "0.1.0"
@ -961,9 +1025,9 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
[[package]]
name = "libc"
version = "0.2.185"
version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f"
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "linux-raw-sys"
@ -998,6 +1062,15 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
]
[[package]]
name = "num-bigint"
version = "0.4.6"
@ -1036,6 +1109,15 @@ dependencies = [
"libc",
]
[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.21.4"
@ -1049,10 +1131,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e"
[[package]]
name = "p3-air"
version = "0.4.2"
name = "owo-colors"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0141a56ed9924ce0265e7e91cd29bbcd230262744b7a7f0c448bfbf212f73182"
checksum = "d211803b9b6b570f68772237e415a029d5a50c65d382910b879fb19d3271f94d"
[[package]]
name = "p3-air"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daee3082e2ca0db2ac876c43c9c8fd53204b0fcb95cfe7258d21f4a925ad82c4"
dependencies = [
"p3-field",
"p3-matrix",
@ -1060,9 +1148,9 @@ dependencies = [
[[package]]
name = "p3-challenger"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20e42ba74a49c08c6e99f74cd9b343bfa31aa5721fea55079b18e3fd65f1dcbc"
checksum = "a7d2d45f5a51dc3f965e8d6da60a6c26c807e88657863d56da275eaa05ad36f1"
dependencies = [
"p3-field",
"p3-maybe-rayon",
@ -1074,9 +1162,9 @@ dependencies = [
[[package]]
name = "p3-commit"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "498211e7b9a0f8366b410b4a9283ae82ff2fc91f473b1c5816aa6e90e74b125d"
checksum = "bf6d7dcb58a8f21f0e1325dc7f7699ad749878ccbe7e286e61f9d46bde2bfa88"
dependencies = [
"itertools 0.14.0",
"p3-challenger",
@ -1089,9 +1177,9 @@ dependencies = [
[[package]]
name = "p3-dft"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e63fa5eb1bd12a240089e72ae3fe10350944d9c166d00a3bfd2a1794db65cf5c"
checksum = "beabb40bc8ac7f5f95870f271fb844c7e2e1ebb7f0761a8eebb2614b56c6b1c1"
dependencies = [
"itertools 0.14.0",
"p3-field",
@ -1104,9 +1192,9 @@ dependencies = [
[[package]]
name = "p3-field"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ebfdb6ef992ae64e9e8f449ac46516ffa584f11afbdf9ee244288c2a633cdf4"
checksum = "4819a3e4c1882431a63d4847ffa10d110017aee4cb9cf4319ca6dca191930969"
dependencies = [
"itertools 0.14.0",
"num-bigint",
@ -1120,9 +1208,9 @@ dependencies = [
[[package]]
name = "p3-fri"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0236da9bb191391b4d1f6e090988227d5da27055a006953aa456f34b683be436"
checksum = "13ca6a795cfc4180425fbf16dfdb4c9c2bfa85971dd55b5930d97b513e0835df"
dependencies = [
"itertools 0.14.0",
"p3-challenger",
@ -1141,9 +1229,9 @@ dependencies = [
[[package]]
name = "p3-interpolation"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d877565a94a527c89459fc8ccb0eb58769d8c86456575d1315a1651bd24616d"
checksum = "f27a3696641a8f4ec990ff8c91862fb4f3b4ff29f589f78005d046023fe3550f"
dependencies = [
"p3-field",
"p3-matrix",
@ -1153,9 +1241,9 @@ dependencies = [
[[package]]
name = "p3-keccak"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d57334537d10316e0f1cda622f0a5b3239f219a5dcd2a95ea87e41e00df6a92"
checksum = "a61b090fb42152d1fcb2f82227b8619b1b022f9cd4a123123dccc9c2ab75d5de"
dependencies = [
"p3-field",
"p3-symmetric",
@ -1165,9 +1253,9 @@ dependencies = [
[[package]]
name = "p3-koala-bear"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5113f50002c56006685b7d7ae12db568150aa1d4bfb092b883d64ece20138042"
checksum = "cfb02789fca0950e246123d652bd78e75a76e3b90a651fd88dbb215cd3e81f5a"
dependencies = [
"p3-challenger",
"p3-field",
@ -1179,9 +1267,9 @@ dependencies = [
[[package]]
name = "p3-matrix"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5542f96504dae8100c91398fb1e3f5ec669eb9c73d9e0b018a93b5fe32bad230"
checksum = "e6fde449bd2963d394284ec46db8c647e6a5602d90601117b76752072ab54168"
dependencies = [
"itertools 0.14.0",
"p3-field",
@ -1190,23 +1278,22 @@ dependencies = [
"rand 0.9.4",
"serde",
"tracing",
"transpose",
]
[[package]]
name = "p3-maybe-rayon"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e5669ca75645f99cd001e9d0289a4eeff2bc2cd9dc3c6c3aaf22643966e83df"
checksum = "54afab3883d8a14676b492709d6c4e9fa535c36718b737db0817aacfaaaa11f6"
dependencies = [
"rayon",
]
[[package]]
name = "p3-mds"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038763af23df9da653065867fd85b38626079031576c86fd537097e5be6a0da0"
checksum = "3895055d735ac96d010747b3aaabd4c2645b9fd80226960550318db2e25afb75"
dependencies = [
"p3-dft",
"p3-field",
@ -1217,9 +1304,9 @@ dependencies = [
[[package]]
name = "p3-merkle-tree"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d93625a3041effddc72ee2511c919f710b7f91fd0f9931ab8a70aeba586fd6e"
checksum = "60e20f61ea816e94f83ed7b8134a5e98d0cad7bd6dff226bc1da17a5143c63cb"
dependencies = [
"itertools 0.14.0",
"p3-commit",
@ -1236,9 +1323,9 @@ dependencies = [
[[package]]
name = "p3-monty-31"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57a981d60da3d8cbf8561014e2c186068578405fd69098fa75b43d4afb364a47"
checksum = "c9fe0be661891af1f703ceaf57334fcbd540804988984dc2b500dd99740e7c81"
dependencies = [
"itertools 0.14.0",
"num-bigint",
@ -1255,14 +1342,13 @@ dependencies = [
"serde",
"spin",
"tracing",
"transpose",
]
[[package]]
name = "p3-poseidon2"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "903b73e4f9a7781a18561c74dc169cf03333497b57a8dd02aaeb130c0f386599"
checksum = "2c6fc2368447576283f8b3849a36095017f25addf06eab9e33b0ce7f96b0b99d"
dependencies = [
"p3-field",
"p3-mds",
@ -1273,9 +1359,9 @@ dependencies = [
[[package]]
name = "p3-symmetric"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd788f04e86dd5c35dd87cad29eefdb6371d2fd5f7664451382eeacae3c3ed0"
checksum = "a14456a42a7d9e65f13999706f1bca2832175935169b3a54286e18331cf1d82f"
dependencies = [
"itertools 0.14.0",
"p3-field",
@ -1284,9 +1370,9 @@ dependencies = [
[[package]]
name = "p3-uni-stark"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68d409704a8cbdb6c77f6b83a05c6b16a3c8a2c00d880146fa34181977a0d3ac"
checksum = "2f3de9a58424e37e103cb3e561a938d11a4b0987f6e1b468a65576202ac1f569"
dependencies = [
"itertools 0.14.0",
"p3-air",
@ -1304,11 +1390,12 @@ dependencies = [
[[package]]
name = "p3-util"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "663b16021930bc600ecada915c6c3965730a3b9d6a6c23434ccf70bfc29d6881"
checksum = "911154accf66034b0eec4452956c088f92a200b37a8225c1caed74cfbd38cc8d"
dependencies = [
"serde",
"transpose",
]
[[package]]
@ -1409,17 +1496,18 @@ dependencies = [
[[package]]
name = "proptest"
version = "1.11.0"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744"
checksum = "14cae93065090804185d3b75f0bf93b8eeda30c7a9b4a33d3bdb3988d6229e50"
dependencies = [
"bit-set",
"bit-vec",
"bitflags",
"lazy_static",
"num-traits",
"rand 0.9.4",
"rand_chacha 0.9.0",
"rand_xorshift 0.4.0",
"rand 0.8.6",
"rand_chacha 0.3.1",
"rand_xorshift",
"regex-syntax",
"rusty-fork",
"tempfile",
@ -1465,6 +1553,7 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a"
dependencies = [
"libc",
"rand_chacha 0.3.1",
"rand_core 0.6.4",
]
@ -1479,17 +1568,6 @@ dependencies = [
"rand_core 0.9.5",
]
[[package]]
name = "rand"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207"
dependencies = [
"chacha20",
"getrandom 0.4.2",
"rand_core 0.10.1",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
@ -1528,12 +1606,6 @@ dependencies = [
"getrandom 0.3.4",
]
[[package]]
name = "rand_core"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
name = "rand_xorshift"
version = "0.3.0"
@ -1543,15 +1615,6 @@ dependencies = [
"rand_core 0.6.4",
]
[[package]]
name = "rand_xorshift"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
dependencies = [
"rand_core 0.9.5",
]
[[package]]
name = "rayon"
version = "1.12.0"
@ -1601,6 +1664,12 @@ version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
[[package]]
name = "rustc-demangle"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d"
[[package]]
name = "rustc_version"
version = "0.4.1"
@ -1737,7 +1806,16 @@ checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4"
dependencies = [
"cfg-if",
"cpufeatures 0.3.0",
"digest 0.11.2",
"digest 0.11.3",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
@ -1755,6 +1833,12 @@ dependencies = [
"rand_core 0.6.4",
]
[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "solana-bls12-381-syscall"
version = "0.1.0"
@ -1797,22 +1881,23 @@ version = "0.1.0"
dependencies = [
"bincode",
"cfg-if",
"color-eyre",
"cpufeatures 0.2.17",
"criterion",
"curve25519-dalek-derive",
"der",
"digest 0.11.2",
"digest 0.11.3",
"ed25519",
"ed25519-dalek",
"ed25519-zebra",
"ff",
"group",
"hashbrown 0.15.5",
"hex",
"once_cell",
"pkcs8",
"proptest",
"rand 0.10.1",
"rand_core 0.10.1",
"rand 0.8.6",
"rand_core 0.6.4",
"rustc_version",
"serde",
"sha2 0.11.0",
@ -1901,6 +1986,15 @@ dependencies = [
"syn",
]
[[package]]
name = "thread_local"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
]
[[package]]
name = "threadpool"
version = "1.8.1"
@ -1956,6 +2050,31 @@ name = "tracing-core"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
name = "transpose"
@ -1991,6 +2110,12 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "version_check"
version = "0.9.5"
@ -2042,9 +2167,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.118"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89"
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
dependencies = [
"cfg-if",
"once_cell",
@ -2055,9 +2180,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.118"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed"
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -2065,9 +2190,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.118"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904"
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
dependencies = [
"bumpalo",
"proc-macro2",
@ -2078,9 +2203,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.118"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129"
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
dependencies = [
"unicode-ident",
]
@ -2121,9 +2246,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.95"
version = "0.3.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f2dfbb17949fa2088e5d39408c48368947b86f7834484e87b73de55bc14d97d"
checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa"
dependencies = [
"js-sys",
"wasm-bindgen",

View file

@ -28,6 +28,7 @@ bytemuck_derive = "1.10.2"
cc = "1.0"
cfg-if = "1"
criterion = { version = "0.5" }
color-eyre = "0.6"
curve25519 = { path = "curve25519/solana-ed25519", package = "solana-ed25519" }
curve25519-dalek-derive = "0.1.1"
cpufeatures = "0.2.17"
@ -35,7 +36,6 @@ der = "0.7.9"
digest = { version = "0.11.0", default-features = false }
ed25519 = { version = "2.2.3", default-features = false }
ed25519-dalek = "2.2.0"
ed25519-zebra = "4.2.0"
ff = { version = "0.13.0", default-features = false }
group = { version = "0.13.0", default-features = false }
hashbrown = "0.15"
@ -43,9 +43,10 @@ hex = "0.4.2"
hex-literal = "1.1.0"
pairing = "0.23.0"
pkcs8 = { version = "0.10.1" }
proptest = "1"
rand = "0.10.0"
rand_core = { version = "0.10.0", default-features = false }
once_cell = "1.21"
proptest = "=1.6.0"
rand = "0.8"
rand_core = { version = "0.6", default-features = false }
rayon = "1.10"
rustc_version = "0.4.0"
serde = { version = "1.0", default-features = false }

View file

@ -33,10 +33,11 @@ all-features = true
[dev-dependencies]
bincode.workspace = true
color-eyre.workspace = true
criterion.workspace = true
ed25519-dalek.workspace = true
ed25519-zebra.workspace = true
hex.workspace = true
once_cell.workspace = true
proptest.workspace = true
rand.workspace = true

View file

@ -105,7 +105,7 @@ use curve25519::ed_sigs::{SigningKey, VerificationKey};
let msg = b"curve25519-sol";
// Generate key and sign
let sk = SigningKey::new(rand::rng());
let sk = SigningKey::new(rand::thread_rng());
let sig = sk.sign(msg);
let vk = VerificationKey::from(&sk);
@ -122,7 +122,7 @@ let mut verifier = batch::Verifier::new();
for (vk_bytes, sig, msg) in items {
verifier.queue((vk_bytes, sig, msg));
}
verifier.verify(rand::rng()).expect("all valid");
verifier.verify(rand::thread_rng()).expect("all valid");
```
### HEEA decomposition example

View file

@ -4,11 +4,10 @@ use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_m
use curve25519::ed_sigs::*;
use ed25519::signature::Verifier as _;
use ed25519_dalek::VerifyingKey as DalekVerifyingKey;
use ed25519_zebra::VerificationKey as ZebraVerificationKey;
fn sigs_with_distinct_pubkeys() -> impl Iterator<Item = (VerificationKeyBytes, Signature)> {
std::iter::repeat_with(|| {
let sk = SigningKey::new(rand::rng());
let sk = SigningKey::new(rand::thread_rng());
let pk_bytes = VerificationKeyBytes::from(&sk);
let sig = sk.sign(b"");
(pk_bytes, sig)
@ -16,7 +15,7 @@ fn sigs_with_distinct_pubkeys() -> impl Iterator<Item = (VerificationKeyBytes, S
}
fn sigs_with_same_pubkey() -> impl Iterator<Item = (VerificationKeyBytes, Signature)> {
let sk = SigningKey::new(rand::rng());
let sk = SigningKey::new(rand::thread_rng());
let pk_bytes = VerificationKeyBytes::from(&sk);
std::iter::repeat_with(move || {
let sig = sk.sign(b"");
@ -24,21 +23,15 @@ fn sigs_with_same_pubkey() -> impl Iterator<Item = (VerificationKeyBytes, Signat
})
}
fn single_verify_inputs() -> (
VerificationKey,
Signature,
ZebraVerificationKey,
DalekVerifyingKey,
) {
let sk = SigningKey::new(rand::rng());
fn single_verify_inputs() -> (VerificationKey, Signature, DalekVerifyingKey) {
let sk = SigningKey::new(rand::thread_rng());
let vk = VerificationKey::from(&sk);
let sig = sk.sign(b"");
let vk_bytes: [u8; 32] = vk.into();
let zebra_vk = ZebraVerificationKey::try_from(vk_bytes).expect("zebra verification key");
let dalek_vk = DalekVerifyingKey::from_bytes(&vk_bytes).expect("dalek verification key");
(vk, sig, zebra_vk, dalek_vk)
(vk, sig, dalek_vk)
}
fn bench_batch_verify(c: &mut Criterion) {
@ -68,7 +61,7 @@ fn bench_batch_verify(c: &mut Criterion) {
for (vk_bytes, sig) in sigs.iter().cloned() {
batch.queue((vk_bytes, sig, b""));
}
batch.verify(rand::rng())
batch.verify(rand::thread_rng())
})
},
);
@ -84,7 +77,7 @@ fn bench_batch_verify(c: &mut Criterion) {
for (vk_bytes, sig) in sigs.iter().cloned() {
batch.queue((vk_bytes, sig, b""));
}
batch.verify(rand::rng())
batch.verify(rand::thread_rng())
})
},
);
@ -96,28 +89,21 @@ fn bench_single_verify(c: &mut Criterion) {
let mut group = c.benchmark_group("Single Verification");
group.bench_function("local_verify_zebra", |b| {
let (vk, sig, _, _) = single_verify_inputs();
let (vk, sig, _) = single_verify_inputs();
b.iter(|| {
let _ = vk.verify_zebra(&sig, b"");
})
});
group.bench_function("local_verify_dalek", |b| {
let (vk, sig, _, _) = single_verify_inputs();
let (vk, sig, _) = single_verify_inputs();
b.iter(|| {
let _ = vk.verify_dalek(&sig, b"");
})
});
group.bench_function("crates_io_ed25519_zebra", |b| {
let (_, sig, zebra_vk, _) = single_verify_inputs();
b.iter(|| {
let _ = zebra_vk.verify(&sig, b"");
})
});
group.bench_function("crates_io_ed25519_dalek", |b| {
let (_, sig, _, dalek_vk) = single_verify_inputs();
let (_, sig, dalek_vk) = single_verify_inputs();
b.iter(|| {
let _ = dalek_vk.verify(b"", &sig);
})

View file

@ -1,7 +1,7 @@
#![allow(non_snake_case)]
use rand::rng;
use rand_core::Rng as RngCore;
use rand::thread_rng;
use rand_core::RngCore;
use criterion::{
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, criterion_main, measurement::Measurement,
@ -32,7 +32,7 @@ mod edwards_benches {
BenchmarkId::new("Batch EdwardsPoint compression", batch_size),
&batch_size,
|b, &size| {
let mut rng = rng();
let mut rng = thread_rng();
let points: Vec<EdwardsPoint> =
(0..size).map(|_| EdwardsPoint::random(&mut rng)).collect();
b.iter(|| EdwardsPoint::compress_batch(&points));
@ -65,7 +65,7 @@ mod edwards_benches {
fn vartime_double_base_scalar_mul<M: Measurement>(c: &mut BenchmarkGroup<M>) {
c.bench_function("Variable-time aA+bB, A variable, B fixed", |bench| {
let mut rng = rng();
let mut rng = thread_rng();
let A = EdwardsPoint::mul_base(&Scalar::random(&mut rng));
bench.iter_batched(
|| (Scalar::random(&mut rng), Scalar::random(&mut rng)),
@ -77,7 +77,7 @@ mod edwards_benches {
#[cfg(feature = "digest")]
fn encode_to_curve<M: Measurement>(c: &mut BenchmarkGroup<M>) {
let mut rng = rng();
let mut rng = thread_rng();
let mut msg = [0u8; 32];
let mut domain_sep = [0u8; 32];
@ -92,7 +92,7 @@ mod edwards_benches {
#[cfg(feature = "digest")]
fn hash_to_curve<M: Measurement>(c: &mut BenchmarkGroup<M>) {
let mut rng = rng();
let mut rng = thread_rng();
let mut msg = [0u8; 32];
let mut domain_sep = [0u8; 32];
@ -131,12 +131,12 @@ mod multiscalar_benches {
use curve25519::traits::VartimePrecomputedMultiscalarMul;
fn construct_scalars(n: usize) -> Vec<Scalar> {
let mut rng = rng();
let mut rng = thread_rng();
(0..n).map(|_| Scalar::random(&mut rng)).collect()
}
fn construct_points(n: usize) -> Vec<EdwardsPoint> {
let mut rng = rng();
let mut rng = thread_rng();
(0..n)
.map(|_| EdwardsPoint::mul_base(&Scalar::random(&mut rng)))
.collect()
@ -302,7 +302,7 @@ mod ristretto_benches {
BenchmarkId::new("Batch Ristretto double-and-encode", *batch_size),
&batch_size,
|b, &&size| {
let mut rng = rng();
let mut rng = thread_rng();
let points: Vec<RistrettoPoint> = (0..size)
.map(|_| RistrettoPoint::random(&mut rng))
.collect();
@ -354,7 +354,7 @@ mod scalar_benches {
use super::*;
fn scalar_arith<M: Measurement>(c: &mut BenchmarkGroup<M>) {
let mut rng = rng();
let mut rng = thread_rng();
c.bench_function("Scalar inversion", |b| {
let s = Scalar::from(897987897u64).invert();
@ -389,7 +389,7 @@ mod scalar_benches {
BenchmarkId::new("Batch scalar inversion", *batch_size),
&batch_size,
|b, &&size| {
let mut rng = rng();
let mut rng = thread_rng();
let scalars: Vec<Scalar> =
(0..size).map(|_| Scalar::random(&mut rng)).collect();
b.iter(|| {

View file

@ -150,14 +150,14 @@ pub fn mul_128_128_256(
#[cfg(test)]
mod test {
use rand::{Rng, rng};
use rand::{RngCore, thread_rng};
use super::*;
use crate::scalar::Scalar;
fn random_scalar() -> Scalar {
let mut wide = [0u8; 64];
let mut rng = rng();
let mut rng = thread_rng();
rng.fill_bytes(&mut wide);
Scalar::from_bytes_mod_order_wide(&wide)
}

View file

@ -37,13 +37,13 @@
//! # use curve25519::ed_sigs::*;
//! let mut batch = batch::Verifier::new();
//! for _ in 0..32 {
//! let sk = SigningKey::new(rand::rng());
//! let sk = SigningKey::new(rand::thread_rng());
//! let vk_bytes = VerificationKeyBytes::from(&sk);
//! let msg = b"BatchVerifyTest";
//! let sig = sk.sign(&msg[..]);
//! batch.queue((vk_bytes, sig, &msg[..]));
//! }
//! assert!(batch.verify(rand::rng()).is_ok());
//! assert!(batch.verify(rand::thread_rng()).is_ok());
//! ```
//!
//! [ZIP215]: https://zips.z.cash/zip-0215
@ -57,14 +57,14 @@ use crate::{
traits::{IsIdentity, VartimeMultiscalarMul},
};
use hashbrown::HashMap;
use rand_core::{CryptoRng, Rng};
use rand_core::{CryptoRng, RngCore};
use sha2::{Sha512, digest::Update};
use super::{Error, VerificationKey, VerificationKeyBytes};
use ed25519::Signature;
// Shim to generate a u128 without importing `rand`.
fn gen_u128<R: Rng + CryptoRng>(mut rng: R) -> u128 {
fn gen_u128<R: RngCore + CryptoRng>(mut rng: R) -> u128 {
let mut bytes = [0u8; 16];
rng.fill_bytes(&mut bytes[..]);
u128::from_le_bytes(bytes)
@ -142,7 +142,7 @@ impl Verifier {
/// Perform batch verification, returning `Ok(())` if all signatures were
/// valid and `Err` otherwise.
#[allow(non_snake_case)]
pub fn verify<R: Rng + CryptoRng>(self, mut rng: R) -> Result<(), Error> {
pub fn verify<R: RngCore + CryptoRng>(self, mut rng: R) -> Result<(), Error> {
// The batch verification equation is
//
// 8*[-sum(z_i * s_i)]B + 8*sum([z_i]R_i) + 8*sum([z_i * k_i]A_i) = 0.

View file

@ -1,7 +1,7 @@
#[cfg(feature = "pkcs8")]
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.101.112"); // RFC 8410
#[cfg(feature = "pkcs8")]
const ALGORITHM_ID: AlgorithmIdentifierRef = AlgorithmIdentifierRef {
const ALGORITHM_ID: AlgorithmIdentifierRef<'_> = AlgorithmIdentifierRef {
oid: OID,
parameters: None,
};
@ -13,7 +13,7 @@ use alloc::string::String;
use core::convert::TryFrom;
#[cfg(feature = "pkcs8")]
use core::convert::TryInto;
use rand_core::{CryptoRng, Rng};
use rand_core::{CryptoRng, RngCore};
use sha2::{Digest, Sha512, digest::Update};
use subtle::ConstantTimeEq;
use zeroize::Zeroize;
@ -176,7 +176,7 @@ impl Eq for SigningKey {}
#[cfg(feature = "pkcs8")]
impl<'a> TryFrom<PrivateKeyInfo<'a>> for SigningKey {
type Error = Error;
fn try_from(pki: PrivateKeyInfo) -> Result<Self, Self::Error> {
fn try_from(pki: PrivateKeyInfo<'a>) -> Result<Self, Self::Error> {
if pki.algorithm == ALGORITHM_ID {
SigningKey::try_from(pki.private_key)
} else {
@ -326,7 +326,7 @@ impl SigningKey {
}
/// Generate a new signing key.
pub fn new<R: Rng + CryptoRng>(mut rng: R) -> SigningKey {
pub fn new<R: RngCore + CryptoRng>(mut rng: R) -> SigningKey {
let mut bytes = [0u8; 32];
rng.fill_bytes(&mut bytes[..]);
bytes.into()

View file

@ -7,13 +7,13 @@ use alloc::vec::Vec;
fn batch_verify() {
let mut batch = batch::Verifier::new();
for _ in 0..32 {
let sk = SigningKey::new(rand::rng());
let sk = SigningKey::new(rand::thread_rng());
let pk_bytes = VerificationKeyBytes::from(&sk);
let msg = b"BatchVerifyTest";
let sig = sk.sign(&msg[..]);
batch.queue((pk_bytes, sig, msg));
}
assert!(batch.verify(rand::rng()).is_ok());
assert!(batch.verify(rand::thread_rng()).is_ok());
}
#[test]
@ -22,7 +22,7 @@ fn batch_verify_with_one_bad_sig() {
let mut batch = batch::Verifier::new();
let mut items = Vec::new();
for i in 0..32 {
let sk = SigningKey::new(rand::rng());
let sk = SigningKey::new(rand::thread_rng());
let pk_bytes = VerificationKeyBytes::from(&sk);
let msg = b"BatchVerifyTest";
let sig = if i != bad_index {
@ -34,7 +34,7 @@ fn batch_verify_with_one_bad_sig() {
items.push(item.clone());
batch.queue(item);
}
assert!(batch.verify(rand::rng()).is_err());
assert!(batch.verify(rand::thread_rng()).is_err());
for (i, item) in items.drain(..).enumerate() {
if i != bad_index {
assert!(item.verify_single().is_ok());

View file

@ -6,35 +6,35 @@ use pkcs8::{DecodePrivateKey, DecodePublicKey};
/// Ed25519 PKCS#8 v1 private key encoded as ASN.1 DER.
#[cfg(feature = "pkcs8")]
const PKCS8_V1_DER: &[u8] = include_bytes!("examples/pkcs8-v1.der");
const PKCS8_V1_DER: &[u8] = include_bytes!("../../../examples/pkcs8-v1.der");
/// Ed25519 PKCS#8 v1 private key encoded as PEM.
#[cfg(feature = "pem")]
const PKCS8_V1_PEM: &str = include_str!("examples/pkcs8-v1.pem");
const PKCS8_V1_PEM: &str = include_str!("../../../examples/pkcs8-v1.pem");
/// Ed25519 PKCS#8 v2 private key + public key encoded as ASN.1 DER.
#[cfg(feature = "pkcs8")]
const PKCS8_V2_DER: &[u8] = include_bytes!("examples/pkcs8-v2.der");
const PKCS8_V2_DER: &[u8] = include_bytes!("../../../examples/pkcs8-v2.der");
/// Ed25519 PKCS#8 v1 private key encoded as PEM.
#[cfg(feature = "pem")]
const PKCS8_V2_PEM: &str = include_str!("examples/pkcs8-v2.pem");
const PKCS8_V2_PEM: &str = include_str!("../../../examples/pkcs8-v2.pem");
/// Ed25519 PKCS#8 v2 private key + mismatched public key encoded as ASN.1 DER.
#[cfg(feature = "pkcs8")]
const PKCS8_V2_DER_BAD: &[u8] = include_bytes!("examples/pkcs8-v2-bad-ver-key.der");
const PKCS8_V2_DER_BAD: &[u8] = include_bytes!("../../../examples/pkcs8-v2-bad-ver-key.der");
/// Ed25519 PKCS#8 v2 private key + mismatched public key encoded as PEM.
#[cfg(feature = "pem")]
const PKCS8_V2_PEM_BAD: &str = include_str!("examples/pkcs8-v2-bad-ver-key.pem");
const PKCS8_V2_PEM_BAD: &str = include_str!("../../../examples/pkcs8-v2-bad-ver-key.pem");
/// Ed25519 SubjectPublicKeyInfo encoded as ASN.1 DER.
#[cfg(feature = "pkcs8")]
const PUBLIC_KEY_DER: &[u8] = include_bytes!("examples/pubkey.der");
const PUBLIC_KEY_DER: &[u8] = include_bytes!("../../../examples/pubkey.der");
/// Ed25519 SubjectPublicKeyInfo encoded as PEM.
#[cfg(feature = "pem")]
const PUBLIC_KEY_PEM: &str = include_str!("examples/pubkey.pem");
const PUBLIC_KEY_PEM: &str = include_str!("../../../examples/pubkey.pem");
#[test]
#[cfg(feature = "pkcs8")]

View file

@ -3,36 +3,33 @@ use crate::ed_sigs::*;
#[cfg(feature = "pem")]
use der::pem::LineEnding;
#[cfg(feature = "pkcs8")]
pub use pkcs8::{
EncodePrivateKey, EncodePublicKey, ObjectIdentifier, PrivateKeyInfo,
spki::AlgorithmIdentifierRef,
};
pub use pkcs8::{EncodePrivateKey, EncodePublicKey};
#[cfg(any(feature = "pem", feature = "pkcs8"))]
use std::convert::TryFrom;
/// Ed25519 PKCS#8 v1 private key encoded as ASN.1 DER.
#[cfg(feature = "pkcs8")]
const PKCS8_V1_DER: &[u8] = include_bytes!("examples/pkcs8-v1.der");
const PKCS8_V1_DER: &[u8] = include_bytes!("../../../examples/pkcs8-v1.der");
/// Ed25519 PKCS#8 v1 private key encoded as PEM.
#[cfg(feature = "pem")]
const PKCS8_V1_PEM: &str = include_str!("examples/pkcs8-v1.pem");
const PKCS8_V1_PEM: &str = include_str!("../../../examples/pkcs8-v1.pem");
/// Ed25519 PKCS#8 v2 private key + public key encoded as ASN.1 DER.
#[cfg(feature = "pkcs8")]
const PKCS8_V2_DER: &[u8] = include_bytes!("examples/pkcs8-v2.der");
const PKCS8_V2_DER: &[u8] = include_bytes!("../../../examples/pkcs8-v2.der");
/// Ed25519 PKCS#8 v1 private key encoded as PEM.
#[cfg(feature = "pem")]
const PKCS8_V2_PEM: &str = include_str!("examples/pkcs8-v2.pem");
const PKCS8_V2_PEM: &str = include_str!("../../../examples/pkcs8-v2.pem");
/// Ed25519 SubjectPublicKeyInfo encoded as ASN.1 DER.
#[cfg(feature = "pkcs8")]
const PUBLIC_KEY_DER: &[u8] = include_bytes!("examples/pubkey.der");
const PUBLIC_KEY_DER: &[u8] = include_bytes!("../../../examples/pubkey.der");
/// Ed25519 SubjectPublicKeyInfo encoded as PEM.
#[cfg(feature = "pem")]
const PUBLIC_KEY_PEM: &str = include_str!("examples/pubkey.pem");
const PUBLIC_KEY_PEM: &str = include_str!("../../../examples/pubkey.pem");
#[test]
#[cfg(feature = "pkcs8")]

View file

@ -9,7 +9,7 @@ use ed25519::Signature;
#[test]
fn test_verify_heea_invalid_signature() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let signing_key = SigningKey::new(&mut rng);
let verification_key = VerificationKey::from(&signing_key);
@ -39,7 +39,7 @@ fn test_verify_heea_invalid_signature() {
#[test]
fn test_verify_heea_multiple_signatures() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for i in 0..100 {
let signing_key = SigningKey::new(&mut rng);
@ -72,7 +72,7 @@ fn test_verify_heea_multiple_signatures() {
#[test]
fn test_default_verification_matches_zebra() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let signing_key = SigningKey::new(&mut rng);
let verification_key = VerificationKey::from(&signing_key);
let msg = b"default verification mode";

View file

@ -7,6 +7,7 @@
use crate::ed_sigs::*;
use ed25519::Signature;
use std::vec::Vec;
fn rfc8032_test_case(sk_bytes: Vec<u8>, pk_bytes: Vec<u8>, sig_bytes: Vec<u8>, msg: Vec<u8>) {
let sk: SigningKey = bincode::deserialize(&sk_bytes).expect("sk should deserialize");

View file

@ -7,6 +7,7 @@ use crate::{
use color_eyre::Report;
use once_cell::sync::Lazy;
use sha2::Sha512;
use std::vec::Vec;
use super::util;
use util::TestCase;
@ -98,7 +99,7 @@ fn individual_matches_batch_verification() -> Result<(), Report> {
VerificationKey::try_from(vkb).and_then(|vk| vk.verify(&sig, msg));
let mut bv = batch::Verifier::new();
bv.queue((vkb, sig, msg));
let batch_verification = bv.verify(rand::rng());
let batch_verification = bv.verify(rand::thread_rng());
assert_eq!(individual_verification.is_ok(), batch_verification.is_ok());
}
Ok(())

View file

@ -6,7 +6,7 @@ use crate::ed_sigs::{Signature, SigningKey, VerificationKey, VerificationKeyByte
#[test]
fn parsing() {
let sk = SigningKey::new(rand::rng());
let sk = SigningKey::new(rand::thread_rng());
let pk = VerificationKey::from(&sk);
let pkb = VerificationKeyBytes::from(&sk);
let sig = sk.sign(b"test");
@ -37,7 +37,7 @@ fn parsing() {
#[test]
fn sign_and_verify() {
let sk = SigningKey::new(rand::rng());
let sk = SigningKey::new(rand::thread_rng());
let pk = VerificationKey::from(&sk);
let msg = b"ed25519-zebra test message";

View file

@ -7,6 +7,7 @@ use crate::edwards::{CompressedEdwardsY, EdwardsPoint};
use color_eyre::{Report, eyre::eyre};
use core::convert::TryFrom;
use std::vec::Vec;
pub struct TestCase {
pub vk_bytes: [u8; 32],
@ -16,7 +17,7 @@ pub struct TestCase {
}
impl core::fmt::Debug for TestCase {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
fmt.debug_struct("TestCase")
.field("vk_bytes", &hex::encode(&self.vk_bytes[..]))
.field("sig_bytes", &hex::encode(&self.sig_bytes[..]))
@ -51,9 +52,9 @@ impl TestCase {
}
fn check_legacy(&self) -> Result<(), Report> {
use ed25519_zebra_legacy::{Signature, VerificationKey};
use ed25519_heea_zip215::{Signature, VerificationKey};
let sig = Signature::from(self.sig_bytes);
VerificationKey::try_from(self.vk_bytes).and_then(|vk| vk.verify(&sig, b"Zcash"))?;
VerificationKey::try_from(self.vk_bytes).and_then(|vk| vk.verify_dalek(&sig, b"Zcash"))?;
Ok(())
}

View file

@ -37,6 +37,64 @@ use super::Error;
/// The length of an ed25519 `VerificationKey`, in bytes.
pub const VERIFICATION_KEY_LENGTH: usize = 32;
const LEGACY_EXCLUDED_R_ENCODINGS: [[u8; 32]; 11] = [
[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
],
[
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
],
[
0x26, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4, 0x89, 0xf2, 0xef, 0x98,
0xf0, 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6, 0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53,
0xfc, 0x05,
],
[
0xc7, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b, 0x76, 0x0d, 0x10, 0x67,
0x0f, 0x2a, 0x20, 0x53, 0xfa, 0x2c, 0x39, 0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac,
0x03, 0x7a,
],
[
0x13, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4, 0x89, 0xf2, 0xef, 0x98,
0xf0, 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6, 0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53,
0xfc, 0x85,
],
[
0xb4, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b, 0x76, 0x0d, 0x10, 0x67,
0x0f, 0x2a, 0x20, 0x53, 0xfa, 0x2c, 0x39, 0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac,
0x03, 0xfa,
],
[
0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x7f,
],
[
0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x7f,
],
[
0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x7f,
],
[
0xd9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff,
],
[
0xda, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff,
],
];
/// A refinement type for `[u8; 32]` indicating that the bytes represent an
/// encoding of an Ed25519 verification key.
///
@ -50,7 +108,7 @@ pub const VERIFICATION_KEY_LENGTH: usize = 32;
/// use core::convert::TryFrom;
/// # use curve25519::ed_sigs::*;
/// # let msg = b"Zcash";
/// # let sk = SigningKey::new(rand::rng());
/// # let sk = SigningKey::new(rand::thread_rng());
/// # let sig = sk.sign(msg);
/// # let vk_bytes = VerificationKeyBytes::from(&sk);
/// VerificationKey::try_from(vk_bytes)
@ -103,7 +161,7 @@ impl From<VerificationKeyBytes> for [u8; 32] {
impl<'a> TryFrom<SubjectPublicKeyInfoRef<'a>> for VerificationKeyBytes {
type Error = Error;
fn try_from(spki: SubjectPublicKeyInfoRef) -> Result<VerificationKeyBytes, Error> {
fn try_from(spki: SubjectPublicKeyInfoRef<'a>) -> Result<VerificationKeyBytes, Error> {
Ok(VerificationKeyBytes::try_from(spki.subject_public_key.as_bytes().unwrap()).unwrap())
}
}
@ -352,6 +410,10 @@ impl VerificationKey {
#[allow(non_snake_case)]
fn verify_dalek_prehashed(&self, signature: &Signature, h: Scalar) -> Result<(), Error> {
if self.A_bytes.0 == [0; 32] || LEGACY_EXCLUDED_R_ENCODINGS.contains(signature.r_bytes()) {
return Err(Error::InvalidSignature);
}
let s = Option::<Scalar>::from(Scalar::from_canonical_bytes(*signature.s_bytes()))
.ok_or(Error::InvalidSignature)?;

View file

@ -113,12 +113,12 @@ use digest::{
#[cfg(feature = "group")]
use {
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
rand_core::TryRng,
rand_core::RngCore as GroupRngCore,
subtle::CtOption,
};
#[cfg(feature = "rand_core")]
use rand_core::Rng as RngCore;
use rand_core::RngCore;
use subtle::Choice;
use subtle::ConditionallyNegatable;
@ -1481,13 +1481,13 @@ impl Debug for EdwardsPoint {
impl group::Group for EdwardsPoint {
type Scalar = Scalar;
fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
fn random(mut rng: impl GroupRngCore) -> Self {
let mut repr = CompressedEdwardsY([0u8; 32]);
loop {
rng.try_fill_bytes(&mut repr.0)?;
rng.fill_bytes(&mut repr.0);
if let Some(p) = repr.decompress() {
if !IsIdentity::is_identity(&p) {
break Ok(p);
break p;
}
}
}
@ -1733,20 +1733,20 @@ impl Zeroize for SubgroupPoint {
impl group::Group for SubgroupPoint {
type Scalar = Scalar;
fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
fn random(mut rng: impl GroupRngCore) -> Self {
use group::ff::Field;
// This will almost never loop, but `Group::random` is documented as returning a
// non-identity element.
let s = loop {
let s: Scalar = Field::try_from_rng(rng)?;
let s: Scalar = Field::random(&mut rng);
if !s.is_zero_vartime() {
break s;
}
};
// This gives an element of the prime-order subgroup.
Ok(Self::generator() * s)
Self::generator() * s
}
fn identity() -> Self {
@ -1810,8 +1810,7 @@ impl CofactorGroup for EdwardsPoint {
#[cfg(test)]
mod test {
use super::*;
use rand::RngExt;
use rand::Rng;
#[cfg(feature = "precomputed-tables")]
use crate::constants::ED25519_BASEPOINT_TABLE;
@ -2097,7 +2096,7 @@ mod test {
/// Check that mul_base_clamped and mul_clamped agree
#[test]
fn mul_base_clamped() {
let mut csprng = rand::rng();
let mut csprng = rand::thread_rng();
// Make a random curve point in the curve. Give it torsion to make things interesting.
#[cfg(feature = "precomputed-tables")]
@ -2214,7 +2213,7 @@ mod test {
#[cfg(all(feature = "alloc", feature = "rand_core"))]
#[test]
fn compress_batch() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
// TODO(tarcieri): proptests?
// Make some points deterministically then randomly
@ -2270,7 +2269,7 @@ mod test {
// A single iteration of a consistency check for MSM.
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn multiscalar_consistency_iter(n: usize) {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
// Construct random coefficients x0, ..., x_{n-1},
// followed by some extra hardcoded ones.
@ -2333,7 +2332,7 @@ mod test {
#[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn batch_to_montgomery() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let scalars = (0..128)
.map(|_| Scalar::random(&mut rng))
@ -2358,7 +2357,7 @@ mod test {
#[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let static_scalars = (0..128)
.map(|_| Scalar::random(&mut rng))

View file

@ -42,7 +42,7 @@
extern crate alloc;
// TODO: move std-dependent tests to `tests/`
#[cfg(test)]
#[cfg(any(test, feature = "std"))]
#[macro_use]
extern crate std;

View file

@ -281,7 +281,7 @@ mod test {
// Tests that lizard_decode of a random point is None
#[test]
fn lizard_invalid() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..100 {
let pt = RistrettoPoint::random(&mut rng);
assert!(
@ -297,7 +297,7 @@ mod test {
// is the identity
#[test]
fn elligator_inv() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for i in 0..100 {
let mut fe_bytes = [0u8; 32];
@ -342,7 +342,7 @@ mod test {
// Tests that map_to_curve ○ map_to_curve_inverse is the identity
#[test]
fn map_to_curve_inverse() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..100 {
let mut input = [0u8; 32];
@ -365,7 +365,7 @@ mod test {
// return value in the first 8 elements
#[test]
fn map_pos_felem_to_curve_inverse() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..100 {
let mut input = [0u8; 32];

View file

@ -512,8 +512,7 @@ mod test {
use crate::constants;
#[cfg(feature = "rand_core")]
use rand::CryptoRng;
use rand::TryRng;
use rand::{CryptoRng, RngCore};
#[test]
fn identity_in_different_coordinates() {
@ -602,7 +601,7 @@ mod test {
/// Returns a random point on the prime-order subgroup
#[cfg(feature = "rand_core")]
fn rand_prime_order_point<R: CryptoRng + ?Sized>(rng: &mut R) -> EdwardsPoint {
fn rand_prime_order_point<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> EdwardsPoint {
let s: Scalar = Scalar::random(rng);
EdwardsPoint::mul_base(&s)
}
@ -622,7 +621,7 @@ mod test {
#[cfg(feature = "rand_core")]
#[test]
fn montgomery_ladder_matches_edwards_scalarmult() {
let mut csprng = rand::rng();
let mut csprng = rand::thread_rng();
for _ in 0..100 {
let p_edwards = rand_prime_order_point(&mut csprng);
@ -641,7 +640,7 @@ mod test {
#[cfg(feature = "rand_core")]
#[test]
fn montgomery_mul_bits_be() {
let mut csprng = rand::rng();
let mut csprng = rand::thread_rng();
for _ in 0..100 {
// Make a random prime-order point P
@ -650,7 +649,7 @@ mod test {
// Make a random integer b
let mut bigint = [0u8; 64];
csprng.try_fill_bytes(&mut bigint[..]).unwrap();
csprng.fill_bytes(&mut bigint[..]);
let bigint_bits_be = bytestring_bits_le(&bigint).rev();
// Check that bP is the same whether calculated as scalar-times-edwards or
@ -666,27 +665,21 @@ mod test {
// integers b₁, b₂ and random (curve or twist) point P.
#[test]
fn montgomery_mul_bits_be_twist() {
let mut csprng = rand::rngs::SysRng;
let mut csprng = rand::rngs::OsRng;
for _ in 0..100 {
// Make a random point P on the curve or its twist
let p_montgomery = {
let mut buf = [0u8; 32];
csprng
.try_fill_bytes(&mut buf)
.expect("rng should not fail");
csprng.fill_bytes(&mut buf);
MontgomeryPoint(buf)
};
// Compute two big integers b₁ and b₂
let mut bigint1 = [0u8; 64];
let mut bigint2 = [0u8; 64];
csprng
.try_fill_bytes(&mut bigint1[..])
.expect("rng should not fail");
csprng
.try_fill_bytes(&mut bigint2[..])
.expect("rng should not fail");
csprng.fill_bytes(&mut bigint1[..]);
csprng.fill_bytes(&mut bigint2[..]);
// Compute b₁P and b₂P
let bigint1_bits_be = bytestring_bits_le(&bigint1).rev();
@ -705,7 +698,7 @@ mod test {
/// Check that mul_base_clamped and mul_clamped agree
#[test]
fn mul_base_clamped() {
let mut csprng = rand::rngs::SysRng;
let mut csprng = rand::rngs::OsRng;
// Test agreement on a large integer. Even after clamping, this is not reduced mod l.
let a_bytes = [0xff; 32];
@ -718,9 +711,7 @@ mod test {
for _ in 0..100 {
// This will be reduced mod l with probability l / 2^256 ≈ 6.25%
let mut a_bytes = [0u8; 32];
csprng
.try_fill_bytes(&mut a_bytes)
.expect("rng should not fail");
csprng.fill_bytes(&mut a_bytes);
assert_eq!(
MontgomeryPoint::mul_base_clamped(a_bytes),

View file

@ -180,15 +180,12 @@ use crate::field::FieldElement;
#[cfg(feature = "group")]
use {
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
rand_core::TryRng,
rand_core::RngCore as GroupRngCore,
subtle::CtOption,
};
#[cfg(feature = "rand_core")]
use {
core::convert::Infallible,
rand_core::{CryptoRng, TryCryptoRng},
};
use rand_core::{CryptoRng, RngCore};
use subtle::Choice;
use subtle::ConditionallyNegatable;
@ -547,7 +544,7 @@ impl RistrettoPoint {
/// # // Need fn main() here in comment so the doctest compiles
/// # // See https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
/// # fn main() {
/// let mut rng = rand::rng();
/// let mut rng = rand::thread_rng();
///
/// let points: Vec<RistrettoPoint> =
/// (0..32).map(|_| RistrettoPoint::random(&mut rng)).collect();
@ -672,34 +669,11 @@ impl RistrettoPoint {
/// point should be unknown. The map is applied twice and the
/// results are added, to ensure a uniform distribution.
#[cfg(feature = "rand_core")]
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
Self::try_from_rng(rng)
.map_err(|_: Infallible| {})
.expect("[bug] unfallible rng failed")
}
/// Return a `RistrettoPoint` chosen uniformly at random using a user-provided RNG.
///
/// # Inputs
///
/// * `rng`: any RNG which implements `TryCryptoRng` interface.
///
/// # Returns
///
/// A random element of the Ristretto group.
///
/// # Implementation
///
/// Uses the Ristretto-flavoured Elligator 2 map, so that the
/// discrete log of the output point with respect to any other
/// point should be unknown. The map is applied twice and the
/// results are added, to ensure a uniform distribution.
#[cfg(feature = "rand_core")]
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
pub fn random<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
let mut uniform_bytes = [0u8; 64];
rng.try_fill_bytes(&mut uniform_bytes)?;
rng.fill_bytes(&mut uniform_bytes);
Ok(RistrettoPoint::from_uniform_bytes(&uniform_bytes))
RistrettoPoint::from_uniform_bytes(&uniform_bytes)
}
#[cfg(feature = "digest")]
@ -1178,11 +1152,11 @@ impl Debug for RistrettoPoint {
impl group::Group for RistrettoPoint {
type Scalar = Scalar;
fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
fn random(mut rng: impl GroupRngCore) -> Self {
// NOTE: this is duplicated due to different `rng` bounds
let mut uniform_bytes = [0u8; 64];
rng.try_fill_bytes(&mut uniform_bytes)?;
Ok(RistrettoPoint::from_uniform_bytes(&uniform_bytes))
rng.fill_bytes(&mut uniform_bytes);
RistrettoPoint::from_uniform_bytes(&uniform_bytes)
}
fn identity() -> Self {
@ -1277,7 +1251,7 @@ mod test {
#[cfg(feature = "group")]
use proptest::prelude::*;
#[cfg(all(feature = "rand_core", feature = "group"))]
use rand::rngs::SysRng;
use rand::rngs::OsRng;
#[test]
#[cfg(feature = "serde")]
@ -1476,7 +1450,7 @@ mod test {
#[cfg(feature = "rand_core")]
#[test]
fn four_torsion_random() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let P = RistrettoPoint::mul_base(&Scalar::random(&mut rng));
let P_coset = P.coset4();
for point in P_coset {
@ -1487,7 +1461,7 @@ mod test {
#[cfg(feature = "rand_core")]
#[test]
fn random_roundtrip() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..100 {
let P = RistrettoPoint::mul_base(&Scalar::random(&mut rng));
let compressed_P = P.compress();
@ -1502,10 +1476,10 @@ mod test {
#[cfg(all(feature = "alloc", feature = "rand_core", feature = "group"))]
fn double_and_compress_1024_random_points() {
use group::Group;
let mut rng = SysRng;
let mut rng = OsRng;
let mut points: Vec<RistrettoPoint> = (0..1024)
.map(|_| RistrettoPoint::try_from_rng(&mut rng).unwrap())
.map(|_| RistrettoPoint::random(&mut rng))
.collect();
points[500] = <RistrettoPoint as Group>::identity();
@ -1552,7 +1526,7 @@ mod test {
#[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let static_scalars = (0..128)
.map(|_| Scalar::random(&mut rng))
@ -1603,7 +1577,7 @@ mod test {
#[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_mixed_multiscalar_empty() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let n_static = 16;
let n_dynamic = 8;
@ -1646,7 +1620,7 @@ mod test {
#[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_mixed_multiscalar() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let n_static = 16;
let n_dynamic = 8;
@ -1691,7 +1665,7 @@ mod test {
#[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_multiscalar() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let n_static = 16;
@ -1720,7 +1694,7 @@ mod test {
#[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_multiscalar_empty() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let n_static = 16;

View file

@ -125,8 +125,8 @@ use group::ff::{Field, FromUniformBytes, PrimeField};
#[cfg(feature = "group-bits")]
use group::ff::{FieldBits, PrimeFieldBits};
#[cfg(feature = "group")]
use rand_core::TryRng;
#[cfg(any(feature = "group", feature = "rand_core"))]
use rand_core::RngCore;
#[cfg(feature = "rand_core")]
use rand_core::CryptoRng;
@ -589,11 +589,11 @@ impl Scalar {
/// # fn main() {
/// use curve25519::scalar::Scalar;
///
/// let mut csprng = rand::rng();
/// let mut csprng = rand::thread_rng();
/// let a: Scalar = Scalar::random(&mut csprng);
/// # }
#[cfg(feature = "rand_core")]
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
pub fn random<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
let mut scalar_bytes = [0u8; 64];
rng.fill_bytes(&mut scalar_bytes);
Scalar::from_bytes_mod_order_wide(&scalar_bytes)
@ -1263,11 +1263,11 @@ impl Field for Scalar {
const ZERO: Self = Self::ZERO;
const ONE: Self = Self::ONE;
fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
fn random(mut rng: impl RngCore) -> Self {
// NOTE: this is duplicated due to different `rng` bounds
let mut scalar_bytes = [0u8; 64];
rng.try_fill_bytes(&mut scalar_bytes)?;
Ok(Self::from_bytes_mod_order_wide(&scalar_bytes))
rng.fill_bytes(&mut scalar_bytes);
Self::from_bytes_mod_order_wide(&scalar_bytes)
}
fn square(&self) -> Self {
@ -1443,7 +1443,6 @@ pub const fn clamp_integer(mut bytes: [u8; 32]) -> [u8; 32] {
#[cfg(test)]
pub(crate) mod test {
use super::*;
use rand::Rng;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
@ -1605,7 +1604,7 @@ pub(crate) mod test {
#[cfg(feature = "rand_core")]
#[test]
fn non_adjacent_form_random() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..1_000 {
let x = Scalar::random(&mut rng);
for w in &[5, 6, 7, 8] {
@ -2135,7 +2134,7 @@ pub(crate) mod test {
// was reduced and b was clamped and unreduced. This checks that was always well-defined.
#[test]
fn test_mul_reduction_invariance() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..10 {
// Also define c that's clamped. We'll make sure that clamping doesn't affect

View file

@ -423,15 +423,15 @@ mod tests {
use crate::{Scalar, digest::Update, traits::HEEADecomposition};
#[cfg(feature = "rand_core")]
use rand_core::Rng;
use rand_core::RngCore;
#[test]
#[cfg(all(feature = "rand_core", feature = "digest"))]
fn test_generate_half_size_scalars() {
use rand::rng;
use rand::thread_rng;
use sha2::{Digest, Sha512};
let mut rng = rng();
let mut rng = thread_rng();
// Test with multiple random scalars
for _ in 0..1000 {

View file

@ -220,7 +220,7 @@ mod tests {
use super::{sw_a, sw_b};
use crate::constants;
use crate::scalar::Scalar;
use rand::{Rng, RngExt};
use rand::Rng;
fn sw_scalar_mul(point: &SwPoint, scalar: &Scalar) -> SwPoint {
let mut acc = SwPoint::Identity;
@ -246,7 +246,7 @@ mod tests {
#[test]
fn sw_round_trip_add_matches_edwards() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..32 {
let a = random_scalar(&mut rng);
@ -273,7 +273,7 @@ mod tests {
#[test]
fn sw_scalar_mul_matches_edwards() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..32 {
let s = random_scalar(&mut rng);
@ -292,7 +292,7 @@ mod tests {
#[test]
fn sw_add_associativity() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
for _ in 0..32 {
let a = random_scalar(&mut rng);
@ -314,7 +314,7 @@ mod tests {
#[test]
fn sw_scalar_mul_associativity_commutes() {
let mut rng = rand::rng();
let mut rng = rand::thread_rng();
let base = SwPoint::from_edwards(&constants::ED25519_BASEPOINT_POINT);
for _ in 0..32 {