From 1439efd3c4f0a2df448e96b8351bc7b7f97dcf61 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 07:18:03 -0700 Subject: [PATCH 1/8] [WIP] Bump `elliptic-curve` crate to v0.14.0-pre.1 --- Cargo.lock | 229 ++++++++++-------- Cargo.toml | 4 + bign256/Cargo.toml | 17 +- bign256/src/arithmetic/scalar.rs | 10 +- bign256/src/dsa.rs | 8 +- bign256/src/dsa/signing.rs | 10 +- bign256/src/dsa/verifying.rs | 5 +- bign256/src/lib.rs | 4 +- bp256/Cargo.toml | 12 +- bp256/src/arithmetic/scalar.rs | 10 +- bp256/src/lib.rs | 4 +- bp384/Cargo.toml | 12 +- bp384/src/arithmetic/scalar.rs | 10 +- bp384/src/lib.rs | 4 +- k256/Cargo.toml | 16 +- k256/benches/ecdsa.rs | 2 +- k256/benches/scalar.rs | 2 +- .../arithmetic/scalar.txt | 7 + k256/src/arithmetic.rs | 2 +- k256/src/arithmetic/field.rs | 9 +- k256/src/arithmetic/hash2curve.rs | 18 +- k256/src/arithmetic/projective.rs | 16 +- k256/src/arithmetic/scalar.rs | 14 +- k256/src/ecdsa.rs | 10 +- k256/src/lib.rs | 6 +- k256/src/schnorr.rs | 8 +- p192/Cargo.toml | 16 +- p192/src/arithmetic/scalar.rs | 10 +- p192/src/lib.rs | 4 +- p224/Cargo.toml | 16 +- p224/src/arithmetic/scalar.rs | 10 +- p224/src/lib.rs | 4 +- p256/Cargo.toml | 16 +- p256/src/arithmetic/field.rs | 7 +- p256/src/arithmetic/hash2curve.rs | 20 +- p256/src/arithmetic/scalar.rs | 12 +- p256/src/ecdsa.rs | 17 +- p256/src/lib.rs | 6 +- p256/tests/affine.rs | 4 +- p384/Cargo.toml | 16 +- p384/src/arithmetic/hash2curve.rs | 16 +- p384/src/arithmetic/scalar.rs | 10 +- p384/src/ecdsa.rs | 12 +- p384/src/lib.rs | 6 +- p521/Cargo.toml | 16 +- p521/src/arithmetic/field.rs | 8 +- p521/src/arithmetic/hash2curve.rs | 26 +- p521/src/arithmetic/scalar.rs | 18 +- p521/src/ecdsa.rs | 4 +- p521/src/lib.rs | 4 +- primeorder/Cargo.toml | 6 +- primeorder/src/affine.rs | 17 +- primeorder/src/dev.rs | 5 +- primeorder/src/field.rs | 4 +- primeorder/src/lib.rs | 4 +- primeorder/src/projective.rs | 25 +- sm2/Cargo.toml | 14 +- sm2/src/arithmetic/scalar.rs | 10 +- sm2/src/dsa.rs | 1 - sm2/src/dsa/signing.rs | 2 +- sm2/src/dsa/verifying.rs | 2 +- sm2/src/lib.rs | 4 +- 62 files changed, 422 insertions(+), 399 deletions(-) create mode 100644 k256/proptest-regressions/arithmetic/scalar.txt diff --git a/Cargo.lock b/Cargo.lock index db2e6498..36cff5ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,9 +40,9 @@ checksum = "d9aa1eef3994e2ccd304a78fe3fea4a73e5792007f85f09b79bb82143ca5f82b" [[package]] name = "belt-hash" -version = "0.1.0" +version = "0.2.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d8ee43afdfcc493dec1e51c8032546cc1c52b4d68549e6469d03ff2cf3c3d91" +checksum = "0625acf009be193873699e396d2e83db1d92717b4d3de4ce48aa2e04348ed5b5" dependencies = [ "belt-block", "digest", @@ -50,18 +50,17 @@ dependencies = [ [[package]] name = "bign256" -version = "0.13.1" +version = "0.14.0-pre" dependencies = [ "belt-hash", "criterion", - "crypto-bigint", "elliptic-curve", "hex", "hex-literal", "primeorder", "proptest", "rand_core", - "rfc6979", + "rfc6979 0.5.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "signature", ] @@ -112,16 +111,16 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.11.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "0edadbde8e0243b49d434f9a23ec0590af201f400a34d7d51049284e4a77c568" dependencies = [ - "generic-array", + "crypto-common", ] [[package]] name = "bp256" -version = "0.6.1" +version = "0.7.0-pre" dependencies = [ "ecdsa", "elliptic-curve", @@ -131,7 +130,7 @@ dependencies = [ [[package]] name = "bp384" -version = "0.6.1" +version = "0.7.0-pre" dependencies = [ "ecdsa", "elliptic-curve", @@ -218,9 +217,9 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" [[package]] name = "const-oid" -version = "0.9.2" +version = "0.10.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" +checksum = "f7e3352a27098ba6b09546e5f13b15165e6a88b5c2723afecb3ea9576b27e3ea" [[package]] name = "cpufeatures" @@ -318,11 +317,12 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.5.5" +version = "0.6.0-pre.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +checksum = "1ccdf8183c2226b057661e7d89624e75108e67b28306c898581fee700ff2d992" dependencies = [ - "generic-array", + "hybrid-array", + "num-traits", "rand_core", "subtle", "zeroize", @@ -330,19 +330,18 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.2.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "806e4e3731d44f1340b069551225b44c2056c105cad9e67f0c46266db8a3a6b9" dependencies = [ - "generic-array", - "typenum", + "hybrid-array", ] [[package]] name = "der" -version = "0.7.2" +version = "0.8.0-pre.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19c5cb402c5c958281c7c0702edea7b780d03b86b606497ca3a10fcd3fc393ac" +checksum = "b489fd2221710c1dd46637d66b984161fb66134f81437a8489800306bcc2ecea" dependencies = [ "const-oid", "pem-rfc7468", @@ -351,9 +350,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.7" +version = "0.11.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "b429fb535b92bad18c86f1d7ee7584a175c2810800c7ac5b75b9408b13981979" dependencies = [ "block-buffer", "const-oid", @@ -363,15 +362,13 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +version = "0.17.0-pre.1" dependencies = [ "der", "digest", "elliptic-curve", - "rfc6979", - "serdect", + "rfc6979 0.5.0-pre.1", + "serdect 0.2.0", "signature", "spki", ] @@ -384,25 +381,25 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "elliptic-curve" -version = "0.13.8" +version = "0.14.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +checksum = "27861f85de50861460eaa0787325f5bc69c763b1496e24a3ca9a2f243f180553" dependencies = [ "base16ct", "base64ct", "crypto-bigint", "digest", "ff", - "generic-array", "group", "hex-literal", "hkdf", + "hybrid-array", "pem-rfc7468", "pkcs8", "rand_core", "sec1", "serde_json", - "serdect", + "serdect 0.3.0-pre.0", "subtle", "tap", "zeroize", @@ -461,17 +458,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - [[package]] name = "getrandom" version = "0.2.8" @@ -529,22 +515,32 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "hkdf" -version = "0.12.3" +version = "0.13.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +checksum = "8030479f3be0f2d183d7fcb5a8bb3c08c31ba40c49a1af5780544272ab8494fb" dependencies = [ "hmac", ] [[package]] name = "hmac" -version = "0.12.1" +version = "0.13.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +checksum = "1ad9bdb2c4daa57033321e5e64c7a8cab02086ee130f8702f72b5c164893026a" dependencies = [ "digest", ] +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c5517ac29f08e88170b9647d85cc5f21c2596de177b4867232e20b214b8da1" +dependencies = [ + "typenum", + "zeroize", +] + [[package]] name = "instant" version = "0.1.12" @@ -602,7 +598,7 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.3" +version = "0.14.0-pre" dependencies = [ "blobby", "cfg-if", @@ -615,7 +611,7 @@ dependencies = [ "once_cell", "proptest", "rand_core", - "serdect", + "serdect 0.2.0", "sha2", "sha3", "signature", @@ -737,19 +733,19 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "p192" -version = "0.13.0" +version = "0.14.0-pre" dependencies = [ "ecdsa", "elliptic-curve", "hex-literal", "primeorder", "sec1", - "serdect", + "serdect 0.2.0", ] [[package]] name = "p224" -version = "0.13.2" +version = "0.14.0-pre" dependencies = [ "blobby", "ecdsa", @@ -757,13 +753,13 @@ dependencies = [ "hex-literal", "primeorder", "rand_core", - "serdect", + "serdect 0.2.0", "sha2", ] [[package]] name = "p256" -version = "0.13.2" +version = "0.14.0-pre" dependencies = [ "blobby", "criterion", @@ -773,13 +769,13 @@ dependencies = [ "primeorder", "proptest", "rand_core", - "serdect", + "serdect 0.2.0", "sha2", ] [[package]] name = "p384" -version = "0.13.0" +version = "0.14.0-pre" dependencies = [ "blobby", "criterion", @@ -789,13 +785,13 @@ dependencies = [ "primeorder", "proptest", "rand_core", - "serdect", + "serdect 0.2.0", "sha2", ] [[package]] name = "p521" -version = "0.13.3" +version = "0.14.0-pre" dependencies = [ "base16ct", "blobby", @@ -805,24 +801,24 @@ dependencies = [ "primeorder", "proptest", "rand_core", - "serdect", + "serdect 0.2.0", "sha2", ] [[package]] name = "pem-rfc7468" -version = "0.7.0" +version = "1.0.0-pre.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +checksum = "76a65e1c27d1680f8805b3f8c9949f08d6aa5d6cbd088c9896e64a53821dc27d" dependencies = [ "base64ct", ] [[package]] name = "pkcs8" -version = "0.10.2" +version = "0.11.0-pre.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "935c09e0aecb0cb8f8907b57438b19a068cb74a25189b06724f061170b2465ff" dependencies = [ "der", "spki", @@ -870,17 +866,17 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "primeorder" -version = "0.13.6" +version = "0.14.0-pre" dependencies = [ "elliptic-curve", - "serdect", + "serdect 0.2.0", ] [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -913,9 +909,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1019,9 +1015,17 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rfc6979" -version = "0.4.0" +version = "0.5.0-pre.1" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "rfc6979" +version = "0.5.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +checksum = "f74fe2f5245b7dcff4f1c633a5dcc1fb54dbb0e4b1fa569ab60863806229d54f" dependencies = [ "hmac", "subtle", @@ -1090,37 +1094,37 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sec1" -version = "0.7.3" +version = "0.8.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +checksum = "02dc081ed777a3bab68583b52ffb8221677b6e90d483b320963a247e2c07f328" dependencies = [ "base16ct", "der", - "generic-array", + "hybrid-array", "pkcs8", - "serdect", + "serdect 0.3.0-pre.0", "subtle", "zeroize", ] [[package]] name = "serde" -version = "1.0.152" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1144,11 +1148,21 @@ dependencies = [ "serde", ] +[[package]] +name = "serdect" +version = "0.3.0-pre.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791ef964bfaba6be28a5c3f0c56836e17cb711ac009ca1074b9c735a3ebf240a" +dependencies = [ + "base16ct", + "serde", +] + [[package]] name = "sha2" -version = "0.10.8" +version = "0.11.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "9daa731ca112bb569b34b41775363a461422813d8ed1ea6dba352eb58ec4e684" dependencies = [ "cfg-if", "cpufeatures", @@ -1157,9 +1171,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.8" +version = "0.11.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +checksum = "23f5da8ebbbfc6bd857bb4d209bb42109772703b118ea137d57352c2a95b3322" dependencies = [ "digest", "keccak", @@ -1167,9 +1181,9 @@ dependencies = [ [[package]] name = "signature" -version = "2.2.0" +version = "2.3.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +checksum = "4d40c007df8d40a44d464726cc639e1b48c1894ad074eb4168ff91e62d94b53a" dependencies = [ "digest", "rand_core", @@ -1177,33 +1191,33 @@ dependencies = [ [[package]] name = "sm2" -version = "0.13.3" +version = "0.14.0-pre" dependencies = [ "elliptic-curve", "hex-literal", "primeorder", "proptest", "rand_core", - "rfc6979", - "serdect", + "rfc6979 0.5.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serdect 0.2.0", "signature", "sm3", ] [[package]] name = "sm3" -version = "0.4.2" +version = "0.5.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebb9a3b702d0a7e33bc4d85a14456633d2b165c2ad839c5fd9a8417c1ab15860" +checksum = "72b6ef3d77873a42e29556a31c798acde8010117e79817bcebacbd536be772dd" dependencies = [ "digest", ] [[package]] name = "spki" -version = "0.7.2" +version = "0.8.0-pre.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +checksum = "cb2b56670f5ef52934c97efad30bf42585de0c33ec3e2a886e38b80d2db67243" dependencies = [ "base64ct", "der", @@ -1211,9 +1225,9 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" @@ -1226,6 +1240,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tap" version = "1.0.1" @@ -1257,9 +1282,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unarray" @@ -1273,12 +1298,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wait-timeout" version = "0.2.0" @@ -1326,7 +1345,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -1348,7 +1367,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index 15523c0f..f5a2c624 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,7 @@ members = [ [profile.dev] opt-level = 2 + +[patch.crates-io.ecdsa] +#git = "https://github.com/RustCrypto/signatures.git" +path = "../signatures/ecdsa" diff --git a/bign256/Cargo.toml b/bign256/Cargo.toml index 5d5b3a14..ed2416d4 100644 --- a/bign256/Cargo.toml +++ b/bign256/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bign256" -version = "0.13.1" +version = "0.14.0-pre" description = """ Pure Rust implementation of the Bign P-256 (a.k.a. bign-curve256v1) elliptic curve as defined in STB 34.101.45-2013, with @@ -14,17 +14,16 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "stb", "bign-curve256v1", "bignp256"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13.8", features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", features = ["hazmat", "sec1"] } # optional dependencies -primeorder = { version = "0.13.5", optional = true, path = "../primeorder" } -signature = { version = "2", optional = true } -belt-hash = { version = "0.1.0", optional = true, default-features = false } -crypto-bigint = { version = "0.5.5", optional = true } -rfc6979 = { version = "0.4", optional = true } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } +signature = { version = "=2.3.0-pre.1", optional = true } +belt-hash = { version = "=0.2.0-pre.1", optional = true, default-features = false } +rfc6979 = { version = "=0.5.0-pre.1", optional = true } [dev-dependencies] criterion = "0.5" @@ -38,7 +37,7 @@ default = ["arithmetic", "pkcs8", "std", "dsa"] alloc = ["elliptic-curve/alloc", "primeorder?/alloc"] std = ["alloc", "elliptic-curve/std", "signature?/std"] -dsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash", "dep:crypto-bigint"] +dsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash"] arithmetic = ["dep:primeorder", "elliptic-curve/arithmetic"] pkcs8 = ["elliptic-curve/pkcs8"] diff --git a/bign256/src/arithmetic/scalar.rs b/bign256/src/arithmetic/scalar.rs index 43587571..c2551eb6 100644 --- a/bign256/src/arithmetic/scalar.rs +++ b/bign256/src/arithmetic/scalar.rs @@ -125,8 +125,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } } @@ -154,7 +154,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U256 = BignP256::ORDER.shr_vartime(1); + const MODULUS_SHR1: U256 = BignP256::ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -163,7 +163,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -171,7 +171,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/bign256/src/dsa.rs b/bign256/src/dsa.rs index 3fcb31e7..ffd084a7 100644 --- a/bign256/src/dsa.rs +++ b/bign256/src/dsa.rs @@ -43,9 +43,9 @@ pub use self::{signing::SigningKey, verifying::VerifyingKey}; use crate::{BignP256, FieldBytes, NonZeroScalar, Scalar}; use core::fmt::{self, Debug}; -use crypto_bigint::{ +use elliptic_curve::{ + array::Array, consts::{U32, U48}, - generic_array::GenericArray, }; use signature::{Error, Result, SignatureEncoding}; @@ -76,7 +76,7 @@ impl Signature { /// Parse an BignP256 signature from a byte array. pub fn from_bytes(bytes: &SignatureBytes) -> Result { let (s0, s1) = bytes.split_at(Self::BYTE_SIZE / 3); - let mut s0_bytes: GenericArray = Default::default(); + let mut s0_bytes: Array = Default::default(); s0_bytes[..16].copy_from_slice(s0); let s0 = ScalarPrimitive::from_slice(&s0_bytes).map_err(|_| Error::new())?; @@ -106,7 +106,7 @@ impl Signature { s0.reverse(); s1.reverse(); - let mut s: GenericArray = Default::default(); + let mut s: Array = Default::default(); s[..Self::BYTE_SIZE / 3].copy_from_slice(s0); s[Self::BYTE_SIZE / 3..Self::BYTE_SIZE].copy_from_slice(&s1); diff --git a/bign256/src/dsa/signing.rs b/bign256/src/dsa/signing.rs index aa56317a..a4d4f577 100644 --- a/bign256/src/dsa/signing.rs +++ b/bign256/src/dsa/signing.rs @@ -16,9 +16,10 @@ use super::{Signature, VerifyingKey, BELT_OID}; use crate::{BignP256, FieldBytes, NonZeroScalar, ProjectivePoint, PublicKey, Scalar, SecretKey}; +use belt_hash::{BeltHash, Digest}; use core::fmt::{self, Debug}; use elliptic_curve::{ - generic_array::typenum::Unsigned, + array::{consts::U32, typenum::Unsigned, Array}, ops::{MulByGenerator, Reduce}, point::AffineCoordinates, subtle::{Choice, ConstantTimeEq}, @@ -26,9 +27,6 @@ use elliptic_curve::{ }; use signature::{hazmat::PrehashSigner, Error, KeypairRef, Result, Signer}; -use belt_hash::{BeltHash, Digest}; -use crypto_bigint::{consts::U32, generic_array::GenericArray}; - /// BignP256 secret key used for signing messages and producing signatures. /// /// ## Usage @@ -107,7 +105,7 @@ impl PrehashSigner for SigningKey { if prehash.len() != ::FieldBytesSize::USIZE { return Err(Error::new()); } - let mut h_word: GenericArray = GenericArray::clone_from_slice(prehash); + let mut h_word: Array = Array::clone_from_slice(prehash); h_word.reverse(); let h = Scalar::reduce_bytes(&h_word); @@ -122,7 +120,7 @@ impl PrehashSigner for SigningKey { .unwrap(); // 3. Set ๐‘… โ† ๐‘˜๐บ. - let mut R: GenericArray = ProjectivePoint::mul_by_generator(&k).to_affine().x(); + let mut R: Array = ProjectivePoint::mul_by_generator(&k).to_affine().x(); R.reverse(); // 4. Set ๐‘†0 โ† โŸจ๏ธ€belt-hash(OID(โ„Ž) โ€– โŸจ๐‘…โŸฉ2๐‘™ โ€– ๐ป)โŸฉ๏ธ€_๐‘™. diff --git a/bign256/src/dsa/verifying.rs b/bign256/src/dsa/verifying.rs index da799bcd..b3dd4b53 100644 --- a/bign256/src/dsa/verifying.rs +++ b/bign256/src/dsa/verifying.rs @@ -22,9 +22,8 @@ use belt_hash::{ digest::{Digest, FixedOutput}, BeltHash, }; -use crypto_bigint::{consts::U32, generic_array::GenericArray}; use elliptic_curve::{ - generic_array::typenum::Unsigned, + array::{consts::U32, typenum::Unsigned, Array}, group::GroupEncoding, ops::{LinearCombination, Reduce}, sec1::ToEncodedPoint, @@ -122,7 +121,7 @@ impl PrehashVerifier for VerifyingKey { // 3. If ๐‘†1 โฉพ ๐‘ž, return NO. let s1 = signature.s1(); - let mut hash: GenericArray = GenericArray::clone_from_slice(prehash); + let mut hash: Array = Array::clone_from_slice(prehash); hash.reverse(); let hw = Scalar::reduce_bytes(FieldBytes::from_slice(&hash)); diff --git a/bign256/src/lib.rs b/bign256/src/lib.rs index 87fe3467..2f6c5862 100644 --- a/bign256/src/lib.rs +++ b/bign256/src/lib.rs @@ -48,9 +48,9 @@ pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint}; pub use elliptic_curve::pkcs8; use elliptic_curve::{ + array::Array, bigint::ArrayEncoding, consts::{U32, U33}, - generic_array::GenericArray, FieldBytesEncoding, }; @@ -107,7 +107,7 @@ impl pkcs8::AssociatedOid for BignP256 { } /// Compressed SEC1-encoded BIGN P256 curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// BIGN P-256 field element serialized as bytes. /// diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index 8bfb5032..e9430289 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bp256" -version = "0.6.1" +version = "0.7.0-pre" description = "Brainpool P-256 (brainpoolP256r1 and brainpoolP256t1) elliptic curves" authors = ["RustCrypto Developers"] license = "Apache-2.0 OR MIT" @@ -10,15 +10,15 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["brainpool", "crypto", "ecc"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa = { version = "0.16", optional = true, default-features = false, features = ["der"] } -primeorder = { version = "0.13.5", optional = true, path = "../primeorder" } -sha2 = { version = "0.10", optional = true, default-features = false } +ecdsa = { version = "=0.17.0-pre.1", optional = true, default-features = false, features = ["der"] } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } +sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [features] default = ["pkcs8", "std"] diff --git a/bp256/src/arithmetic/scalar.rs b/bp256/src/arithmetic/scalar.rs index c91b3634..9ec5c3aa 100644 --- a/bp256/src/arithmetic/scalar.rs +++ b/bp256/src/arithmetic/scalar.rs @@ -174,8 +174,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } /// Compute modular square. @@ -296,7 +296,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U256 = ORDER.shr_vartime(1); + const MODULUS_SHR1: U256 = ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -305,7 +305,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -313,7 +313,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/bp256/src/lib.rs b/bp256/src/lib.rs index 3fc37d34..55c13061 100644 --- a/bp256/src/lib.rs +++ b/bp256/src/lib.rs @@ -30,13 +30,13 @@ pub use crate::arithmetic::scalar::Scalar; #[cfg(feature = "pkcs8")] pub use elliptic_curve::pkcs8; -use elliptic_curve::generic_array::{typenum::U32, GenericArray}; +use elliptic_curve::array::{typenum::U32, Array}; #[cfg(feature = "wip-arithmetic-do-not-use")] pub(crate) use crate::arithmetic::field::FieldElement; /// Byte representation of a base/scalar field element of a given curve. -pub type FieldBytes = GenericArray; +pub type FieldBytes = Array; const ORDER_HEX: &str = "a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7"; const ORDER: U256 = U256::from_be_hex(ORDER_HEX); diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index 9e94519b..4a73cbe3 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bp384" -version = "0.6.1" +version = "0.7.0-pre" description = "Brainpool P-384 (brainpoolP384r1 and brainpoolP384t1) elliptic curves" authors = ["RustCrypto Developers"] license = "Apache-2.0 OR MIT" @@ -10,15 +10,15 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["brainpool", "crypto", "ecc"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa = { version = "0.16", optional = true, default-features = false, features = ["der"] } -primeorder = { version = "0.13.5", optional = true, path = "../primeorder" } -sha2 = { version = "0.10", optional = true, default-features = false } +ecdsa = { version = "=0.17.0-pre.1", optional = true, default-features = false, features = ["der"] } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } +sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [features] default = ["pkcs8", "std"] diff --git a/bp384/src/arithmetic/scalar.rs b/bp384/src/arithmetic/scalar.rs index 0cb77ef0..a7c73e18 100644 --- a/bp384/src/arithmetic/scalar.rs +++ b/bp384/src/arithmetic/scalar.rs @@ -174,8 +174,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } /// Compute modular square. @@ -303,7 +303,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U384 = ORDER.shr_vartime(1); + const MODULUS_SHR1: U384 = ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -312,7 +312,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -320,7 +320,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/bp384/src/lib.rs b/bp384/src/lib.rs index 47c0b9d4..05769d84 100644 --- a/bp384/src/lib.rs +++ b/bp384/src/lib.rs @@ -30,13 +30,13 @@ pub use crate::arithmetic::scalar::Scalar; #[cfg(feature = "pkcs8")] pub use elliptic_curve::pkcs8; -use elliptic_curve::generic_array::{typenum::U48, GenericArray}; +use elliptic_curve::array::{typenum::U48, Array}; #[cfg(feature = "wip-arithmetic-do-not-use")] pub(crate) use crate::arithmetic::field::FieldElement; /// Byte representation of a base/scalar field element of a given curve. -pub type FieldBytes = GenericArray; +pub type FieldBytes = Array; const ORDER_HEX: &str = "8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565"; const ORDER: U384 = U384::from_be_hex(ORDER_HEX); diff --git a/k256/Cargo.toml b/k256/Cargo.toml index 7d4e8c6a..8bc56f72 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "k256" -version = "0.13.3" +version = "0.14.0-pre" description = """ secp256k1 elliptic curve library written in pure Rust with support for ECDSA signing/verification/public-key recovery, Taproot Schnorr signatures (BIP340), @@ -15,30 +15,30 @@ readme = "README.md" categories = ["cryptography", "cryptography::cryptocurrencies", "no-std"] keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] cfg-if = "1.0" -elliptic-curve = { version = "0.13.8", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies once_cell = { version = "1.19", optional = true, default-features = false } -ecdsa-core = { version = "0.16.8", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } serdect = { version = "0.2", optional = true, default-features = false } -sha2 = { version = "0.10", optional = true, default-features = false } -signature = { version = "2", optional = true } +sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } +signature = { version = "=2.3.0-pre.1", optional = true } [dev-dependencies] blobby = "0.3" criterion = "0.5" -ecdsa-core = { version = "0.16", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" num-bigint = "0.4" num-traits = "0.2" proptest = "1.4" rand_core = { version = "0.6", features = ["getrandom"] } -sha3 = { version = "0.10", default-features = false } +sha3 = { version = "=0.11.0-pre.1", default-features = false } [features] default = ["arithmetic", "ecdsa", "pkcs8", "precomputed-tables", "schnorr", "std"] diff --git a/k256/benches/ecdsa.rs b/k256/benches/ecdsa.rs index 548b16b9..da32db12 100644 --- a/k256/benches/ecdsa.rs +++ b/k256/benches/ecdsa.rs @@ -6,7 +6,7 @@ use ecdsa_core::{ hazmat::{SignPrimitive, VerifyPrimitive}, }; use k256::{ - elliptic_curve::{generic_array::arr, group::ff::PrimeField}, + elliptic_curve::{array::arr, group::ff::PrimeField}, AffinePoint, FieldBytes, Scalar, }; diff --git a/k256/benches/scalar.rs b/k256/benches/scalar.rs index c6f73d2b..ea88a8dd 100644 --- a/k256/benches/scalar.rs +++ b/k256/benches/scalar.rs @@ -6,7 +6,7 @@ use criterion::{ use hex_literal::hex; use k256::{ elliptic_curve::{ - generic_array::arr, group::ff::PrimeField, ops::LinearCombination, ops::MulByGenerator, + array::arr, group::ff::PrimeField, ops::LinearCombination, ops::MulByGenerator, }, ProjectivePoint, Scalar, }; diff --git a/k256/proptest-regressions/arithmetic/scalar.txt b/k256/proptest-regressions/arithmetic/scalar.txt new file mode 100644 index 00000000..ec731cc1 --- /dev/null +++ b/k256/proptest-regressions/arithmetic/scalar.txt @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 6511feae44fafd76e794999ecd3410c4a507306bbea8776dc08bb6f44160332a # shrinks to a = Scalar(Uint(0x0000000000000000000000000000000000000008000000000000000000000000)), b = 256 diff --git a/k256/src/arithmetic.rs b/k256/src/arithmetic.rs index b6ba5673..1b83dc06 100644 --- a/k256/src/arithmetic.rs +++ b/k256/src/arithmetic.rs @@ -43,7 +43,7 @@ mod tests { #[test] fn verify_constants() { - assert_eq!(CURVE_EQUATION_B.to_bytes(), CURVE_EQUATION_B_BYTES.into()); + assert_eq!(CURVE_EQUATION_B.to_bytes(), CURVE_EQUATION_B_BYTES); } #[test] diff --git a/k256/src/arithmetic/field.rs b/k256/src/arithmetic/field.rs index db2f556c..aff92693 100644 --- a/k256/src/arithmetic/field.rs +++ b/k256/src/arithmetic/field.rs @@ -629,14 +629,13 @@ mod tests { #[test] fn to_bytes() { - assert_eq!(FieldElement::ZERO.to_bytes(), [0; 32].into()); + assert_eq!(FieldElement::ZERO.to_bytes(), [0; 32]); assert_eq!( FieldElement::ONE.to_bytes(), [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ] - .into() ); } @@ -644,7 +643,7 @@ mod tests { fn repeated_add() { let mut r = FieldElement::ONE; for i in 0..DBL_TEST_VECTORS.len() { - assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i].into()); + assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i]); r = (r + &r).normalize(); } } @@ -653,7 +652,7 @@ mod tests { fn repeated_double() { let mut r = FieldElement::ONE; for i in 0..DBL_TEST_VECTORS.len() { - assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i].into()); + assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i]); r = r.double().normalize(); } } @@ -663,7 +662,7 @@ mod tests { let mut r = FieldElement::ONE; let two = r + &r; for i in 0..DBL_TEST_VECTORS.len() { - assert_eq!(r.normalize().to_bytes(), DBL_TEST_VECTORS[i].into()); + assert_eq!(r.normalize().to_bytes(), DBL_TEST_VECTORS[i]); r = r * &two; } } diff --git a/k256/src/arithmetic/hash2curve.rs b/k256/src/arithmetic/hash2curve.rs index 5ce39321..598748b8 100644 --- a/k256/src/arithmetic/hash2curve.rs +++ b/k256/src/arithmetic/hash2curve.rs @@ -1,6 +1,6 @@ +use elliptic_curve::array::Array; use elliptic_curve::bigint::{ArrayEncoding, U256}; use elliptic_curve::consts::{U4, U48}; -use elliptic_curve::generic_array::GenericArray; use elliptic_curve::group::cofactor::CofactorGroup; use elliptic_curve::hash2curve::{ FromOkm, GroupDigest, Isogeny, IsogenyCoefficients, MapToCurve, OsswuMap, OsswuMapParams, Sgn0, @@ -19,7 +19,7 @@ impl GroupDigest for Secp256k1 { impl FromOkm for FieldElement { type Length = U48; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { // 0x0000000000000001000000000000000000000000000000000000000000000000 const F_2_192: FieldElement = FieldElement::from_bytes_unchecked(&[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -147,16 +147,16 @@ impl MapToCurve for FieldElement { impl FromOkm for Scalar { type Length = U48; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { const F_2_192: Scalar = Scalar(U256::from_be_hex( "0000000000000001000000000000000000000000000000000000000000000000", )); - let mut d0 = GenericArray::default(); + let mut d0 = Array::default(); d0[8..].copy_from_slice(&data[0..24]); let d0 = Scalar(U256::from_be_byte_array(d0)); - let mut d1 = GenericArray::default(); + let mut d1 = Array::default(); d1[8..].copy_from_slice(&data[24..]); let d1 = Scalar(U256::from_be_byte_array(d1)); @@ -276,9 +276,9 @@ impl CofactorGroup for ProjectivePoint { mod tests { use crate::{FieldElement, Scalar, Secp256k1, U256}; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, NonZero, U384}, consts::U48, - generic_array::GenericArray, group::cofactor::CofactorGroup, hash2curve::{FromOkm, GroupDigest, MapToCurve}, Curve, @@ -402,11 +402,11 @@ mod tests { #[test] fn from_okm_fuzz() { - let mut wide_order = GenericArray::default(); + let mut wide_order = Array::default(); wide_order[16..].copy_from_slice(&Secp256k1::ORDER.to_be_byte_array()); let wide_order = NonZero::new(U384::from_be_byte_array(wide_order)).unwrap(); - let simple_from_okm = move |data: GenericArray| -> Scalar { + let simple_from_okm = move |data: Array| -> Scalar { let data = U384::from_be_slice(&data); let scalar = data % wide_order; @@ -416,7 +416,7 @@ mod tests { }; proptest!(ProptestConfig::with_cases(1000), |(b0 in ANY, b1 in ANY, b2 in ANY, b3 in ANY, b4 in ANY, b5 in ANY)| { - let mut data = GenericArray::default(); + let mut data = Array::default(); data[..8].copy_from_slice(&b0.to_be_bytes()); data[8..16].copy_from_slice(&b1.to_be_bytes()); data[16..24].copy_from_slice(&b2.to_be_bytes()); diff --git a/k256/src/arithmetic/projective.rs b/k256/src/arithmetic/projective.rs index a7f7bbbe..14de4dab 100644 --- a/k256/src/arithmetic/projective.rs +++ b/k256/src/arithmetic/projective.rs @@ -798,8 +798,8 @@ mod tests { let affine = p.to_affine(); let (expected_x, expected_y) = ADD_TEST_VECTORS[i]; - assert_eq!(affine.x.to_bytes(), expected_x.into()); - assert_eq!(affine.y.to_bytes(), expected_y.into()); + assert_eq!(affine.x.to_bytes(), expected_x); + assert_eq!(affine.y.to_bytes(), expected_y); p += &generator; } @@ -814,8 +814,8 @@ mod tests { let affine = p.to_affine(); let (expected_x, expected_y) = ADD_TEST_VECTORS[i]; - assert_eq!(affine.x.to_bytes(), expected_x.into()); - assert_eq!(affine.y.to_bytes(), expected_y.into()); + assert_eq!(affine.x.to_bytes(), expected_x); + assert_eq!(affine.y.to_bytes(), expected_y); p += &generator; } @@ -838,8 +838,8 @@ mod tests { let affine = p.to_affine(); let (expected_x, expected_y) = ADD_TEST_VECTORS[i]; - assert_eq!(affine.x.to_bytes(), expected_x.into()); - assert_eq!(affine.y.to_bytes(), expected_y.into()); + assert_eq!(affine.x.to_bytes(), expected_x); + assert_eq!(affine.y.to_bytes(), expected_y); p = p.double(); } @@ -895,8 +895,8 @@ mod tests { ) { let res = (generator * &k).to_affine(); - assert_eq!(res.x.to_bytes(), coords.0.into()); - assert_eq!(res.y.to_bytes(), coords.1.into()); + assert_eq!(res.x.to_bytes(), coords.0); + assert_eq!(res.y.to_bytes(), coords.1); } } diff --git a/k256/src/arithmetic/scalar.rs b/k256/src/arithmetic/scalar.rs index e0f98595..943eed72 100644 --- a/k256/src/arithmetic/scalar.rs +++ b/k256/src/arithmetic/scalar.rs @@ -39,7 +39,7 @@ use num_bigint::{BigUint, ToBigUint}; const MODULUS: [Word; U256::LIMBS] = ORDER.to_words(); /// Constant representing the modulus / 2 -const FRAC_MODULUS_2: U256 = ORDER.shr_vartime(1); +const FRAC_MODULUS_2: U256 = ORDER.wrapping_shr_vartime(1); /// Scalars are elements in the finite field modulo n. /// @@ -120,8 +120,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } /// Inverts the scalar. @@ -488,7 +488,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -496,7 +496,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -794,9 +794,9 @@ mod tests { FieldBytes, NonZeroScalar, WideBytes, ORDER, }; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, U256, U512}, ff::{Field, PrimeField}, - generic_array::GenericArray, ops::{Invert, Reduce}, scalar::IsHigh, }; @@ -1038,7 +1038,7 @@ mod tests { let m = Scalar::modulus_as_biguint(); fn reduce>(arr: &[u8]) -> T { - T::reduce_bytes(GenericArray::from_slice(arr)) + T::reduce_bytes(Array::from_slice(arr)) } // Regular reduction diff --git a/k256/src/ecdsa.rs b/k256/src/ecdsa.rs index a3f28ab7..dad5d112 100644 --- a/k256/src/ecdsa.rs +++ b/k256/src/ecdsa.rs @@ -345,7 +345,7 @@ mod tests { mod wycheproof { use crate::{EncodedPoint, Secp256k1}; use ecdsa_core::{signature::Verifier, Signature}; - use elliptic_curve::generic_array::typenum::Unsigned; + use elliptic_curve::array::typenum::Unsigned; #[test] fn wycheproof() { @@ -364,10 +364,10 @@ mod tests { } elliptic_curve::FieldBytes::::clone_from_slice(&data[offset..]) } else { - let iter = core::iter::repeat(0) - .take(point_len - data.len()) - .chain(data.iter().cloned()); - elliptic_curve::FieldBytes::::from_exact_iter(iter).unwrap() + let mut point = elliptic_curve::FieldBytes::::default(); + let offset = point_len - data.len(); + point[offset..].copy_from_slice(data); + point } } diff --git a/k256/src/lib.rs b/k256/src/lib.rs index f47f4882..43504563 100644 --- a/k256/src/lib.rs +++ b/k256/src/lib.rs @@ -62,9 +62,9 @@ pub use elliptic_curve::pkcs8; pub use sha2; use elliptic_curve::{ + array::Array, bigint::ArrayEncoding, consts::{U32, U33, U64}, - generic_array::GenericArray, FieldBytesEncoding, }; @@ -117,7 +117,7 @@ impl pkcs8::AssociatedOid for Secp256k1 { } /// Compressed SEC1-encoded secp256k1 (K-256) curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// SEC1-encoded secp256k1 (K-256) curve point. pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint; @@ -138,7 +138,7 @@ impl FieldBytesEncoding for U256 { } /// Bytes used by a wide reduction: twice the width of [`FieldBytes`]. -pub type WideBytes = GenericArray; +pub type WideBytes = Array; /// Non-zero secp256k1 (K-256) scalar field element. #[cfg(feature = "arithmetic")] diff --git a/k256/src/schnorr.rs b/k256/src/schnorr.rs index b8439d80..59021ab4 100644 --- a/k256/src/schnorr.rs +++ b/k256/src/schnorr.rs @@ -68,7 +68,7 @@ mod verifying; pub use self::{signing::SigningKey, verifying::VerifyingKey}; pub use signature::{self, rand_core::CryptoRngCore, Error}; -use crate::{arithmetic::FieldElement, NonZeroScalar}; +use crate::{arithmetic::FieldElement, FieldBytes, NonZeroScalar}; use core::fmt; use elliptic_curve::subtle::ConstantTimeEq; use sha2::{Digest, Sha256}; @@ -145,8 +145,10 @@ impl TryFrom<&[u8]> for Signature { fn try_from(bytes: &[u8]) -> Result { let (r_bytes, s_bytes) = bytes.split_at(Self::BYTE_SIZE / 2); - let r: FieldElement = - Option::from(FieldElement::from_bytes(r_bytes.into())).ok_or_else(Error::new)?; + let r: FieldElement = Option::from(FieldElement::from_bytes(FieldBytes::from_slice( + r_bytes, + ))) + .ok_or_else(Error::new)?; // one of the rules for valid signatures: !is_infinite(R); if r.is_zero().into() { diff --git a/p192/Cargo.toml b/p192/Cargo.toml index 1060f6b6..d5db6b39 100644 --- a/p192/Cargo.toml +++ b/p192/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "p192" -version = "0.13.0" +version = "0.14.0-pre" description = """ Pure Rust implementation of the NIST P-192 (a.k.a. secp192r1) elliptic curve as defined in SP 800-186 @@ -13,22 +13,22 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "secp192r1"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] } -sec1 = { version = "0.7.3", default-features = false } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +sec1 = { version = "=0.8.0-pre.1", default-features = false } # optional dependencies -ecdsa-core = { version = "0.16.6", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } -primeorder = { version = "0.13.5", optional = true, path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } [dev-dependencies] -ecdsa-core = { version = "0.16", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" -primeorder = { version = "0.13", features = ["dev"], path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } [features] default = ["arithmetic", "ecdsa", "pem", "std"] diff --git a/p192/src/arithmetic/scalar.rs b/p192/src/arithmetic/scalar.rs index a7e3b060..aa9c83e9 100644 --- a/p192/src/arithmetic/scalar.rs +++ b/p192/src/arithmetic/scalar.rs @@ -157,8 +157,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } } @@ -192,7 +192,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U192 = NistP192::ORDER.shr_vartime(1); + const MODULUS_SHR1: U192 = NistP192::ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -201,7 +201,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -209,7 +209,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/p192/src/lib.rs b/p192/src/lib.rs index cc551fa2..158a0d19 100644 --- a/p192/src/lib.rs +++ b/p192/src/lib.rs @@ -33,9 +33,9 @@ pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint}; pub use elliptic_curve::pkcs8; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, U192}, consts::{U24, U25}, - generic_array::GenericArray, FieldBytesEncoding, }; @@ -69,7 +69,7 @@ impl pkcs8::AssociatedOid for NistP192 { } /// Compressed SEC1-encoded NIST P-192 curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// NIST P-192 SEC1 encoded point. pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint; diff --git a/p224/Cargo.toml b/p224/Cargo.toml index 9762e5b0..8418e89c 100644 --- a/p224/Cargo.toml +++ b/p224/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "p224" -version = "0.13.2" +version = "0.14.0-pre" description = """ Pure Rust implementation of the NIST P-224 (a.k.a. secp224r1) elliptic curve as defined in SP 800-186 @@ -13,23 +13,23 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "secp224r1"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13.8", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "0.16.6", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } -primeorder = { version = "0.13.5", optional = true, path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } -sha2 = { version = "0.10", optional = true, default-features = false } +sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { version = "0.16", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" -primeorder = { version = "0.13", features = ["dev"], path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } rand_core = { version = "0.6", features = ["getrandom"] } [features] diff --git a/p224/src/arithmetic/scalar.rs b/p224/src/arithmetic/scalar.rs index 8f7da4d3..5fc0e5ba 100644 --- a/p224/src/arithmetic/scalar.rs +++ b/p224/src/arithmetic/scalar.rs @@ -147,8 +147,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } } @@ -176,7 +176,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: Uint = NistP224::ORDER.shr_vartime(1); + const MODULUS_SHR1: Uint = NistP224::ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -185,7 +185,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -193,7 +193,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/p224/src/lib.rs b/p224/src/lib.rs index 90deb736..b730fdcf 100644 --- a/p224/src/lib.rs +++ b/p224/src/lib.rs @@ -36,8 +36,8 @@ pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint}; pub use elliptic_curve::pkcs8; use elliptic_curve::{ + array::Array, consts::{U28, U29}, - generic_array::GenericArray, FieldBytesEncoding, }; @@ -89,7 +89,7 @@ impl pkcs8::AssociatedOid for NistP224 { pub type BlindedScalar = elliptic_curve::scalar::BlindedScalar; /// Compressed SEC1-encoded NIST P-224 curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// NIST P-224 SEC1 encoded point. pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint; diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 59b98444..3cb518ae 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "p256" -version = "0.13.2" +version = "0.14.0-pre" description = """ Pure Rust implementation of the NIST P-256 (a.k.a. secp256r1, prime256v1) elliptic curve as defined in SP 800-186, with support for ECDH, ECDSA @@ -14,24 +14,24 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "prime256v1", "secp256r1"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13.8", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "0.16", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } -primeorder = { version = "0.13", optional = true, path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } -sha2 = { version = "0.10", optional = true, default-features = false } +sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.5" -ecdsa-core = { version = "0.16", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" -primeorder = { version = "0.13.5", features = ["dev"], path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } proptest = "1" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p256/src/arithmetic/field.rs b/p256/src/arithmetic/field.rs index eb54746d..97d2cc2b 100644 --- a/p256/src/arithmetic/field.rs +++ b/p256/src/arithmetic/field.rs @@ -716,7 +716,6 @@ mod tests { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ] - .into() ); } @@ -724,7 +723,7 @@ mod tests { fn repeated_add() { let mut r = FieldElement::ONE; for i in 0..DBL_TEST_VECTORS.len() { - assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i].into()); + assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i]); r = r + &r; } } @@ -733,7 +732,7 @@ mod tests { fn repeated_double() { let mut r = FieldElement::ONE; for i in 0..DBL_TEST_VECTORS.len() { - assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i].into()); + assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i]); r = r.double(); } } @@ -743,7 +742,7 @@ mod tests { let mut r = FieldElement::ONE; let two = r + &r; for i in 0..DBL_TEST_VECTORS.len() { - assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i].into()); + assert_eq!(r.to_bytes(), DBL_TEST_VECTORS[i]); r = r * &two; } } diff --git a/p256/src/arithmetic/hash2curve.rs b/p256/src/arithmetic/hash2curve.rs index b1520e9f..c6da89b9 100644 --- a/p256/src/arithmetic/hash2curve.rs +++ b/p256/src/arithmetic/hash2curve.rs @@ -1,9 +1,9 @@ use super::FieldElement; use crate::{AffinePoint, FieldBytes, NistP256, ProjectivePoint, Scalar}; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, U256}, consts::U48, - generic_array::GenericArray, hash2curve::{FromOkm, GroupDigest, MapToCurve, OsswuMap, OsswuMapParams, Sgn0}, point::DecompressPoint, subtle::Choice, @@ -16,7 +16,7 @@ impl GroupDigest for NistP256 { impl FromOkm for FieldElement { type Length = U48; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { const F_2_192: FieldElement = FieldElement(U256::from_be_hex( "00000000000000030000000200000000fffffffffffffffefffffffeffffffff", )); @@ -74,16 +74,16 @@ impl MapToCurve for FieldElement { impl FromOkm for Scalar { type Length = U48; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { const F_2_192: Scalar = Scalar(U256::from_be_hex( "0000000000000001000000000000000000000000000000000000000000000000", )); - let mut d0 = GenericArray::default(); + let mut d0 = Array::default(); d0[8..].copy_from_slice(&data[0..24]); let d0 = Scalar(U256::from_be_byte_array(d0)); - let mut d1 = GenericArray::default(); + let mut d1 = Array::default(); d1[8..].copy_from_slice(&data[24..]); let d1 = Scalar(U256::from_be_byte_array(d1)); @@ -96,9 +96,9 @@ mod tests { use super::FieldElement; use crate::{arithmetic::field::MODULUS, NistP256, Scalar, U256}; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, CheckedSub, NonZero, U384}, consts::U48, - generic_array::GenericArray, group::cofactor::CofactorGroup, hash2curve::{self, ExpandMsgXmd, FromOkm, GroupDigest, MapToCurve, OsswuMap}, sec1::{self, ToEncodedPoint}, @@ -115,7 +115,7 @@ mod tests { let c1 = MODULUS.0.checked_sub(&U256::from_u8(3)).unwrap() / NonZero::new(U256::from_u8(4)).unwrap(); assert_eq!( - GenericArray::from_iter(params.c1.iter().rev().flat_map(|v| v.to_be_bytes())), + Array::from_iter(params.c1.iter().rev().flat_map(|v| v.to_be_bytes())), c1.to_be_byte_array() ); @@ -302,11 +302,11 @@ mod tests { #[test] fn from_okm_fuzz() { - let mut wide_order = GenericArray::default(); + let mut wide_order = Array::default(); wide_order[16..].copy_from_slice(&NistP256::ORDER.to_be_byte_array()); let wide_order = NonZero::new(U384::from_be_byte_array(wide_order)).unwrap(); - let simple_from_okm = move |data: GenericArray| -> Scalar { + let simple_from_okm = move |data: Array| -> Scalar { let data = U384::from_be_slice(&data); let scalar = data % wide_order; @@ -316,7 +316,7 @@ mod tests { }; proptest!(ProptestConfig::with_cases(1000), |(b0 in ANY, b1 in ANY, b2 in ANY, b3 in ANY, b4 in ANY, b5 in ANY)| { - let mut data = GenericArray::default(); + let mut data = Array::default(); data[..8].copy_from_slice(&b0.to_be_bytes()); data[8..16].copy_from_slice(&b1.to_be_bytes()); data[16..24].copy_from_slice(&b2.to_be_bytes()); diff --git a/p256/src/arithmetic/scalar.rs b/p256/src/arithmetic/scalar.rs index 61a331ec..7ffe1284 100644 --- a/p256/src/arithmetic/scalar.rs +++ b/p256/src/arithmetic/scalar.rs @@ -36,7 +36,7 @@ use serdect::serde::{de, ser, Deserialize, Serialize}; pub(crate) const MODULUS: U256 = NistP256::ORDER; /// `MODULUS / 2` -const FRAC_MODULUS_2: Scalar = Scalar(MODULUS.shr_vartime(1)); +const FRAC_MODULUS_2: Scalar = Scalar(MODULUS.wrapping_shr_vartime(1)); /// MU = floor(2^512 / n) /// = 115792089264276142090721624801893421302707618245269942344307673200490803338238 @@ -112,7 +112,7 @@ impl Scalar { /// Returns self * rhs mod n pub const fn multiply(&self, rhs: &Self) -> Self { - let (lo, hi) = self.0.mul_wide(&rhs.0); + let (lo, hi) = self.0.split_mul(&rhs.0); Self(barrett_reduce(lo, hi)) } @@ -125,8 +125,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } /// Returns the multiplicative inverse of self, if self is non-zero @@ -419,7 +419,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -427,7 +427,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/p256/src/ecdsa.rs b/p256/src/ecdsa.rs index e5cf3d44..883f0022 100644 --- a/p256/src/ecdsa.rs +++ b/p256/src/ecdsa.rs @@ -87,8 +87,7 @@ mod tests { }; use ecdsa_core::hazmat::SignPrimitive; use elliptic_curve::{ - generic_array::GenericArray, group::ff::PrimeField, rand_core::OsRng, - sec1::FromEncodedPoint, + array::Array, group::ff::PrimeField, rand_core::OsRng, sec1::FromEncodedPoint, }; use hex_literal::hex; use sha2::Digest; @@ -141,10 +140,10 @@ mod tests { // let verifier = VerifyingKey::from_affine( AffinePoint::from_encoded_point(&EncodedPoint::from_affine_coordinates( - GenericArray::from_slice(&hex!( + Array::from_slice(&hex!( "e0e7b99bc62d8dd67883e39ed9fa0657789c5ff556cc1fd8dd1e2a55e9e3f243" )), - GenericArray::from_slice(&hex!( + Array::from_slice(&hex!( "63fbfd0232b95578075c903a4dbf85ad58f8350516e1ec89b0ee1f5e1362da69" )), false, @@ -153,10 +152,10 @@ mod tests { ) .unwrap(); let signature = Signature::from_scalars( - GenericArray::clone_from_slice(&hex!( + Array::clone_from_slice(&hex!( "f5087878e212b703578f5c66f434883f3ef414dc23e2e8d8ab6a8d159ed5ad83" )), - GenericArray::clone_from_slice(&hex!( + Array::clone_from_slice(&hex!( "306b4c6c20213707982dffbb30fba99b96e792163dd59dbe606e734328dd7c8a" )), ) @@ -171,10 +170,10 @@ mod tests { #[test] fn scalar_blinding() { let vector = &ECDSA_TEST_VECTORS[0]; - let d = Scalar::from_repr(GenericArray::clone_from_slice(vector.d)).unwrap(); - let k = Scalar::from_repr(GenericArray::clone_from_slice(vector.k)).unwrap(); + let d = Scalar::from_repr(Array::clone_from_slice(vector.d)).unwrap(); + let k = Scalar::from_repr(Array::clone_from_slice(vector.k)).unwrap(); let k_blinded = BlindedScalar::new(k, &mut OsRng); - let z = GenericArray::clone_from_slice(vector.m); + let z = Array::clone_from_slice(vector.m); let sig = d.try_sign_prehashed(k_blinded, &z).unwrap().0; assert_eq!(vector.r, sig.r().to_bytes().as_slice()); diff --git a/p256/src/lib.rs b/p256/src/lib.rs index 656d2329..5ba447e5 100644 --- a/p256/src/lib.rs +++ b/p256/src/lib.rs @@ -49,9 +49,7 @@ pub use arithmetic::field::FieldElement; #[cfg(feature = "pkcs8")] pub use elliptic_curve::pkcs8; -use elliptic_curve::{ - bigint::ArrayEncoding, consts::U33, generic_array::GenericArray, FieldBytesEncoding, -}; +use elliptic_curve::{array::Array, bigint::ArrayEncoding, consts::U33, FieldBytesEncoding}; /// Order of NIST P-256's elliptic curve group (i.e. scalar modulus) serialized /// as hexadecimal. @@ -135,7 +133,7 @@ impl pkcs8::AssociatedOid for NistP256 { pub type BlindedScalar = elliptic_curve::scalar::BlindedScalar; /// Compressed SEC1-encoded NIST P-256 curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// NIST P-256 SEC1 encoded point. pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint; diff --git a/p256/tests/affine.rs b/p256/tests/affine.rs index 8e4bb816..a339811b 100644 --- a/p256/tests/affine.rs +++ b/p256/tests/affine.rs @@ -119,8 +119,8 @@ fn identity_encoding() { #[test] fn noncompatible_is_none() { - use elliptic_curve::generic_array::GenericArray; - let noncompactable_secret = GenericArray::from([ + use elliptic_curve::array::Array; + let noncompactable_secret = Array::from([ 175, 232, 180, 255, 91, 106, 124, 191, 224, 31, 177, 208, 236, 127, 191, 169, 201, 217, 75, 141, 184, 175, 120, 85, 171, 8, 54, 57, 33, 177, 83, 211, ]); diff --git a/p384/Cargo.toml b/p384/Cargo.toml index a39ae32c..f10ce761 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "p384" -version = "0.13.0" +version = "0.14.0-pre" description = """ Pure Rust implementation of the NIST P-384 (a.k.a. secp384r1) elliptic curve as defined in SP 800-186 with support for ECDH, ECDSA signing/verification, @@ -14,24 +14,24 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "secp384r1"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "0.16", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } -primeorder = { version = "0.13.1", optional = true, path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } -sha2 = { version = "0.10", optional = true, default-features = false } +sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.5" -ecdsa-core = { version = "0.16", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" -primeorder = { version = "0.13.5", features = ["dev"], path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } proptest = "1.4" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p384/src/arithmetic/hash2curve.rs b/p384/src/arithmetic/hash2curve.rs index fb183a61..1e103aa8 100644 --- a/p384/src/arithmetic/hash2curve.rs +++ b/p384/src/arithmetic/hash2curve.rs @@ -1,9 +1,9 @@ use super::FieldElement; use crate::{AffinePoint, FieldBytes, NistP384, ProjectivePoint, Scalar}; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, U384}, consts::U72, - generic_array::GenericArray, hash2curve::{FromOkm, GroupDigest, MapToCurve, OsswuMap, OsswuMapParams, Sgn0}, ops::Reduce, point::DecompressPoint, @@ -17,7 +17,7 @@ impl GroupDigest for NistP384 { impl FromOkm for FieldElement { type Length = U72; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { const F_2_288: FieldElement = FieldElement::from_hex( "000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000", ); @@ -77,7 +77,7 @@ impl MapToCurve for FieldElement { impl FromOkm for Scalar { type Length = U72; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { const F_2_288: Scalar = Scalar::from_hex( "000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000", ); @@ -98,9 +98,9 @@ impl FromOkm for Scalar { mod tests { use crate::{arithmetic::field::MODULUS, FieldElement, NistP384, Scalar}; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, CheckedSub, NonZero, U384, U576}, consts::U72, - generic_array::GenericArray, group::cofactor::CofactorGroup, hash2curve::{self, ExpandMsgXmd, FromOkm, GroupDigest, MapToCurve, OsswuMap}, ops::Reduce, @@ -118,7 +118,7 @@ mod tests { let c1 = MODULUS.checked_sub(&U384::from_u8(3)).unwrap() / NonZero::new(U384::from_u8(4)).unwrap(); assert_eq!( - GenericArray::from_iter(params.c1.iter().rev().flat_map(|v| v.to_be_bytes())), + Array::from_iter(params.c1.iter().rev().flat_map(|v| v.to_be_bytes())), c1.to_be_byte_array() ); @@ -304,11 +304,11 @@ mod tests { #[test] fn from_okm_fuzz() { - let mut wide_order = GenericArray::default(); + let mut wide_order = Array::default(); wide_order[24..].copy_from_slice(&NistP384::ORDER.to_be_byte_array()); let wide_order = NonZero::new(U576::from_be_byte_array(wide_order)).unwrap(); - let simple_from_okm = move |data: GenericArray| -> Scalar { + let simple_from_okm = move |data: Array| -> Scalar { let data = U576::from_be_slice(&data); let scalar = data % wide_order; @@ -318,7 +318,7 @@ mod tests { }; proptest!(ProptestConfig::with_cases(1000), |(b0 in ANY, b1 in ANY, b2 in ANY, b3 in ANY, b4 in ANY, b5 in ANY, b6 in ANY, b7 in ANY, b8 in ANY)| { - let mut data = GenericArray::default(); + let mut data = Array::default(); data[..8].copy_from_slice(&b0.to_be_bytes()); data[8..16].copy_from_slice(&b1.to_be_bytes()); data[16..24].copy_from_slice(&b2.to_be_bytes()); diff --git a/p384/src/arithmetic/scalar.rs b/p384/src/arithmetic/scalar.rs index 71492397..cae876ca 100644 --- a/p384/src/arithmetic/scalar.rs +++ b/p384/src/arithmetic/scalar.rs @@ -177,8 +177,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } } @@ -206,7 +206,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U384 = NistP384::ORDER.shr_vartime(1); + const MODULUS_SHR1: U384 = NistP384::ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -215,7 +215,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -223,7 +223,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/p384/src/ecdsa.rs b/p384/src/ecdsa.rs index 7ed34385..06b8bfa3 100644 --- a/p384/src/ecdsa.rs +++ b/p384/src/ecdsa.rs @@ -82,7 +82,7 @@ mod tests { AffinePoint, EncodedPoint, SecretKey, }; - use elliptic_curve::{generic_array::GenericArray, sec1::FromEncodedPoint}; + use elliptic_curve::{array::Array, sec1::FromEncodedPoint}; use hex_literal::hex; use sha2::Digest; @@ -136,15 +136,17 @@ mod tests { let verifier = VerifyingKey::from_affine( AffinePoint::from_encoded_point( &EncodedPoint::from_affine_coordinates( - GenericArray::from_slice(&hex!("0400193b21f07cd059826e9453d3e96dd145041c97d49ff6b7047f86bb0b0439e909274cb9c282bfab88674c0765bc75")), - GenericArray::from_slice(&hex!("f70d89c52acbc70468d2c5ae75c76d7f69b76af62dcf95e99eba5dd11adf8f42ec9a425b0c5ec98e2f234a926b82a147")), + Array::from_slice(&hex! + ("0400193b21f07cd059826e9453d3e96dd145041c97d49ff6b7047f86bb0b0439e909274cb9c282bfab88674c0765bc75")), + Array::from_slice(&hex! + ("f70d89c52acbc70468d2c5ae75c76d7f69b76af62dcf95e99eba5dd11adf8f42ec9a425b0c5ec98e2f234a926b82a147")), false, ), ).unwrap() ).unwrap(); let signature = Signature::from_scalars( - GenericArray::clone_from_slice(&hex!("b11db00cdaf53286d4483f38cd02785948477ed7ebc2ad609054551da0ab0359978c61851788aa2ec3267946d440e878")), - GenericArray::clone_from_slice(&hex!("16007873c5b0604ce68112a8fee973e8e2b6e3319c683a762ff5065a076512d7c98b27e74b7887671048ac027df8cbf2")), + Array::clone_from_slice(&hex!("b11db00cdaf53286d4483f38cd02785948477ed7ebc2ad609054551da0ab0359978c61851788aa2ec3267946d440e878")), + Array::clone_from_slice(&hex!("16007873c5b0604ce68112a8fee973e8e2b6e3319c683a762ff5065a076512d7c98b27e74b7887671048ac027df8cbf2")), ).unwrap(); let result = verifier.verify_prehash( &hex!("bbbd0a5f645d3fda10e288d172b299455f9dff00e0fbc2833e18cd017d7f3ed1"), diff --git a/p384/src/lib.rs b/p384/src/lib.rs index 0544d061..a0bd2bc1 100644 --- a/p384/src/lib.rs +++ b/p384/src/lib.rs @@ -42,9 +42,7 @@ pub use arithmetic::field::FieldElement; #[cfg(feature = "pkcs8")] pub use elliptic_curve::pkcs8; -use elliptic_curve::{ - bigint::ArrayEncoding, consts::U49, generic_array::GenericArray, FieldBytesEncoding, -}; +use elliptic_curve::{array::Array, bigint::ArrayEncoding, consts::U49, FieldBytesEncoding}; /// Order of NIST P-384's elliptic curve group (i.e. scalar modulus) in hexadecimal. const ORDER_HEX: &str = "ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"; @@ -87,7 +85,7 @@ impl pkcs8::AssociatedOid for NistP384 { } /// Compressed SEC1-encoded NIST P-384 curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// NIST P-384 SEC1 encoded point. pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint; diff --git a/p521/Cargo.toml b/p521/Cargo.toml index 8aee7bf3..0fd3a229 100644 --- a/p521/Cargo.toml +++ b/p521/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "p521" -version = "0.13.3" +version = "0.14.0-pre" description = """ Pure Rust implementation of the NIST P-521 (a.k.a. secp521r1) elliptic curve as defined in SP 800-186 @@ -13,25 +13,25 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "secp521r1"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] base16ct = "0.2" -elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "0.16.5", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } -primeorder = { version = "0.13.5", optional = true, path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } rand_core = { version = "0.6", optional = true, default-features = false } serdect = { version = "0.2", optional = true, default-features = false } -sha2 = { version = "0.10", optional = true, default-features = false } +sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { version = "0.16", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" -primeorder = { version = "0.13.3", features = ["dev"], path = "../primeorder" } +primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } proptest = "1.4" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p521/src/arithmetic/field.rs b/p521/src/arithmetic/field.rs index 70382335..a3ef84cd 100644 --- a/p521/src/arithmetic/field.rs +++ b/p521/src/arithmetic/field.rs @@ -36,8 +36,8 @@ use core::{ }; use elliptic_curve::ops::Invert; use elliptic_curve::{ + array::Array, ff::{self, Field, PrimeField}, - generic_array::GenericArray, rand_core::RngCore, subtle::{Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeLess, CtOption}, zeroize::DefaultIsZeroes, @@ -76,7 +76,7 @@ impl FieldElement { return Err(Error); } - Option::from(Self::from_bytes(GenericArray::from_slice(slice))).ok_or(Error) + Option::from(Self::from_bytes(Array::from_slice(slice))).ok_or(Error) } /// Decode [`FieldElement`] from [`U576`]. @@ -144,7 +144,7 @@ impl FieldElement { pub fn to_bytes(self) -> FieldBytes { let mut ret = fiat_p521_to_bytes(&self.0); ret.reverse(); - GenericArray::clone_from_slice(&ret) + Array::clone_from_slice(&ret) } /// Determine if this [`FieldElement`] is odd in the SEC1 sense: `self mod 2 == 1`. @@ -693,7 +693,7 @@ mod tests { #[test] fn decode_invalid_field_element_returns_err() { let overflowing_bytes = hex!("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - let ct_option = FieldElement::from_bytes(overflowing_bytes.as_ref().into()); + let ct_option = FieldElement::from_bytes(&overflowing_bytes.into()); assert!(bool::from(ct_option.is_none())); } } diff --git a/p521/src/arithmetic/hash2curve.rs b/p521/src/arithmetic/hash2curve.rs index fa4c5b6f..1eed93e4 100644 --- a/p521/src/arithmetic/hash2curve.rs +++ b/p521/src/arithmetic/hash2curve.rs @@ -1,9 +1,9 @@ use super::FieldElement; use crate::{AffinePoint, NistP521, ProjectivePoint, Scalar}; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, U576}, consts::U98, - generic_array::GenericArray, hash2curve::{FromOkm, GroupDigest, MapToCurve, OsswuMap, OsswuMapParams, Sgn0}, ops::Reduce, point::DecompressPoint, @@ -17,16 +17,16 @@ impl GroupDigest for NistP521 { impl FromOkm for FieldElement { type Length = U98; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { const F_2_392: FieldElement = FieldElement::from_hex( "000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", ); - let mut d0 = GenericArray::default(); + let mut d0 = Array::default(); d0[23..].copy_from_slice(&data[0..49]); let d0 = FieldElement::from_uint_unchecked(U576::from_be_byte_array(d0)); - let mut d1 = GenericArray::default(); + let mut d1 = Array::default(); d1[23..].copy_from_slice(&data[49..]); let d1 = FieldElement::from_uint_unchecked(U576::from_be_byte_array(d1)); @@ -80,16 +80,16 @@ impl MapToCurve for FieldElement { impl FromOkm for Scalar { type Length = U98; - fn from_okm(data: &GenericArray) -> Self { + fn from_okm(data: &Array) -> Self { const F_2_392: Scalar = Scalar::from_hex( "000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", ); - let mut d0 = GenericArray::default(); + let mut d0 = Array::default(); d0[23..].copy_from_slice(&data[0..49]); let d0 = Scalar::reduce(U576::from_be_byte_array(d0)); - let mut d1 = GenericArray::default(); + let mut d1 = Array::default(); d1[23..].copy_from_slice(&data[49..]); let d1 = Scalar::reduce(U576::from_be_byte_array(d1)); @@ -104,9 +104,9 @@ mod tests { NistP521, Scalar, }; use elliptic_curve::{ + array::Array, bigint::{ArrayEncoding, CheckedSub, NonZero, U576, U896}, consts::U98, - generic_array::GenericArray, group::cofactor::CofactorGroup, hash2curve::{self, ExpandMsgXmd, FromOkm, GroupDigest, MapToCurve, OsswuMap}, ops::Reduce, @@ -124,7 +124,7 @@ mod tests { let c1 = MODULUS.checked_sub(&U576::from_u8(3)).unwrap() / NonZero::new(U576::from_u8(4)).unwrap(); assert_eq!( - GenericArray::from_iter(params.c1.iter().rev().flat_map(|v| v.to_be_bytes())), + Array::from_iter(params.c1.iter().rev().flat_map(|v| v.to_be_bytes())), c1.to_be_byte_array() ); @@ -310,13 +310,13 @@ mod tests { #[test] fn from_okm_fuzz() { - let mut wide_order = GenericArray::default(); + let mut wide_order = Array::default(); wide_order[40..].copy_from_slice(NistP521::ORDER.to_be_byte_array().as_slice()); // TODO: This could be reduced to `U832` when `crypto-bigint` implements `ArrayEncoding`. let wide_order = NonZero::new(U896::from_be_byte_array(wide_order)).unwrap(); - let simple_from_okm = move |data: GenericArray| -> Scalar { - let mut wide_data = GenericArray::default(); + let simple_from_okm = move |data: Array| -> Scalar { + let mut wide_data = Array::default(); wide_data[14..].copy_from_slice(data.as_slice()); let wide_data = U896::from_be_byte_array(wide_data); @@ -343,7 +343,7 @@ mod tests { b11 in num::u64::ANY, b12 in num::u16::ANY, )| { - let mut data = GenericArray::default(); + let mut data = Array::default(); data[..8].copy_from_slice(&b0.to_be_bytes()); data[8..16].copy_from_slice(&b1.to_be_bytes()); data[16..24].copy_from_slice(&b2.to_be_bytes()); diff --git a/p521/src/arithmetic/scalar.rs b/p521/src/arithmetic/scalar.rs index 66de4997..7cb03834 100644 --- a/p521/src/arithmetic/scalar.rs +++ b/p521/src/arithmetic/scalar.rs @@ -21,9 +21,9 @@ use core::{ ops::{AddAssign, MulAssign, Neg, Shr, ShrAssign, SubAssign}, }; use elliptic_curve::{ + array::Array, bigint::{self, Integer}, ff::{self, Field, PrimeField}, - generic_array::GenericArray, ops::{Invert, Reduce}, rand_core::RngCore, scalar::{FromUintUnchecked, IsHigh}, @@ -95,7 +95,7 @@ impl Scalar { return Err(Error); } - Option::from(Self::from_bytes(GenericArray::from_slice(slice))).ok_or(Error) + Option::from(Self::from_bytes(Array::from_slice(slice))).ok_or(Error) } /// Decode [`Scalar`] from [`U576`] converting it into Montgomery form: @@ -299,8 +299,12 @@ impl Scalar { /// /// Note: not constant-time with respect to the `shift` parameter. #[cfg(target_pointer_width = "64")] - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(U576::from_words(self.0).shr_vartime(shift).to_words()) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self( + U576::from_words(self.0) + .wrapping_shr_vartime(shift) + .to_words(), + ) } } @@ -507,7 +511,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U576 = NistP521::ORDER.shr_vartime(1); + const MODULUS_SHR1: U576 = NistP521::ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -516,7 +520,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -524,7 +528,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/p521/src/ecdsa.rs b/p521/src/ecdsa.rs index 659aeed1..dc62e0fc 100644 --- a/p521/src/ecdsa.rs +++ b/p521/src/ecdsa.rs @@ -251,7 +251,7 @@ mod tests { #[test] fn wycheproof() { use blobby::Blob5Iterator; - use elliptic_curve::generic_array::typenum::Unsigned; + use elliptic_curve::array::typenum::Unsigned; // Build a field element but allow for too-short input (left pad with zeros) // or too-long input (check excess leftmost bytes are zeros). @@ -271,7 +271,7 @@ mod tests { let iter = core::iter::repeat(0) .take(point_len - data.len()) .chain(data.iter().cloned()); - elliptic_curve::FieldBytes::::from_exact_iter(iter).unwrap() + elliptic_curve::FieldBytes::::from_iter(iter) } } diff --git a/p521/src/lib.rs b/p521/src/lib.rs index e0056a01..4a42a808 100644 --- a/p521/src/lib.rs +++ b/p521/src/lib.rs @@ -45,7 +45,7 @@ pub use elliptic_curve::{self, bigint::U576}; #[cfg(feature = "pkcs8")] pub use elliptic_curve::pkcs8; -use elliptic_curve::{consts::U66, generic_array::GenericArray, FieldBytesEncoding}; +use elliptic_curve::{array::Array, consts::U66, FieldBytesEncoding}; /// NIST P-521 elliptic curve. #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] @@ -85,7 +85,7 @@ impl pkcs8::AssociatedOid for NistP521 { } /// Compressed SEC1-encoded NIST P-521 curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// NIST P-521 SEC1 encoded point. pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint; diff --git a/primeorder/Cargo.toml b/primeorder/Cargo.toml index 3f2f3cf0..3c51e57f 100644 --- a/primeorder/Cargo.toml +++ b/primeorder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "primeorder" -version = "0.13.6" +version = "0.14.0-pre" description = """ Pure Rust implementation of complete addition formulas for prime order elliptic curves (Renes-Costello-Batina 2015). Generic over field elements and curve @@ -14,10 +14,10 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13.8", default-features = false, features = ["arithmetic", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["arithmetic", "sec1"] } # optional dependencies serdect = { version = "0.2", optional = true, default-features = false } diff --git a/primeorder/src/affine.rs b/primeorder/src/affine.rs index 6801c5d3..02ae6e1d 100644 --- a/primeorder/src/affine.rs +++ b/primeorder/src/affine.rs @@ -8,8 +8,8 @@ use core::{ ops::{Mul, Neg}, }; use elliptic_curve::{ + array::ArraySize, ff::{Field, PrimeField}, - generic_array::ArrayLength, group::{prime::PrimeCurveAffine, GroupEncoding}, point::{AffineCoordinates, DecompactPoint, DecompressPoint, Double}, sec1::{ @@ -235,7 +235,7 @@ where C: PrimeCurveParams, FieldBytesSize: ModulusSize, CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { fn from(affine: AffinePoint) -> EncodedPoint { affine.to_encoded_point(false) @@ -245,10 +245,10 @@ where impl GroupEncoding for AffinePoint where C: PrimeCurveParams, + CompressedPoint: Copy + Send + Sync, FieldBytes: Copy, FieldBytesSize: ModulusSize, - CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { type Repr = CompressedPoint; @@ -290,11 +290,12 @@ where impl PrimeCurveAffine for AffinePoint where C: PrimeCurveParams, + CompressedPoint: Send + Sync, FieldBytes: Copy, FieldBytesSize: ModulusSize, ProjectivePoint: Double, CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { type Curve = ProjectivePoint; type Scalar = Scalar; @@ -321,7 +322,7 @@ where C: PrimeCurveParams, FieldBytesSize: ModulusSize, CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { /// Serialize this value as a SEC1 compact [`EncodedPoint`] fn to_compact_encoded_point(&self) -> CtOption> { @@ -342,7 +343,7 @@ where C: PrimeCurveParams, FieldBytesSize: ModulusSize, CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { fn to_encoded_point(&self, compress: bool) -> EncodedPoint { EncodedPoint::::conditional_select( @@ -460,7 +461,7 @@ where C: PrimeCurveParams, FieldBytesSize: ModulusSize, CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { fn serialize(&self, serializer: S) -> core::result::Result where diff --git a/primeorder/src/dev.rs b/primeorder/src/dev.rs index a70027f0..bf0abb23 100644 --- a/primeorder/src/dev.rs +++ b/primeorder/src/dev.rs @@ -141,10 +141,7 @@ macro_rules! impl_projective_arithmetic_tests { .map(|(k, coords)| (<$scalar>::from(k as u64 + 1), *coords)) .chain($mul_vectors.iter().cloned().map(|(k, x, y)| { ( - <$scalar>::from_repr( - $crate::generic_array::GenericArray::clone_from_slice(&k), - ) - .unwrap(), + <$scalar>::from_repr($crate::array::Array::clone_from_slice(&k)).unwrap(), (x, y), ) })) diff --git a/primeorder/src/field.rs b/primeorder/src/field.rs index 9a3b6ead..44070228 100644 --- a/primeorder/src/field.rs +++ b/primeorder/src/field.rs @@ -80,13 +80,13 @@ macro_rules! impl_mont_field_element { #[doc = stringify!($fe)] /// `] from a big endian byte slice. pub fn from_slice(slice: &[u8]) -> $crate::elliptic_curve::Result { - use $crate::elliptic_curve::generic_array::{typenum::Unsigned, GenericArray}; + use $crate::elliptic_curve::array::{typenum::Unsigned, Array}; if slice.len() != <$curve as $crate::elliptic_curve::Curve>::FieldBytesSize::USIZE { return Err($crate::elliptic_curve::Error); } - Option::from(Self::from_bytes(GenericArray::from_slice(slice))) + Option::from(Self::from_bytes(Array::from_slice(slice))) .ok_or($crate::elliptic_curve::Error) } diff --git a/primeorder/src/lib.rs b/primeorder/src/lib.rs index 46b1860a..75f25d20 100644 --- a/primeorder/src/lib.rs +++ b/primeorder/src/lib.rs @@ -21,9 +21,7 @@ mod field; mod projective; pub use crate::{affine::AffinePoint, projective::ProjectivePoint}; -pub use elliptic_curve::{ - self, generic_array, point::Double, Field, FieldBytes, PrimeCurve, PrimeField, -}; +pub use elliptic_curve::{self, array, point::Double, Field, FieldBytes, PrimeCurve, PrimeField}; use elliptic_curve::CurveArithmetic; diff --git a/primeorder/src/projective.rs b/primeorder/src/projective.rs index 884b1374..5b310935 100644 --- a/primeorder/src/projective.rs +++ b/primeorder/src/projective.rs @@ -9,8 +9,8 @@ use core::{ ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; use elliptic_curve::{ - bigint::{ArrayEncoding, Integer}, - generic_array::ArrayLength, + array::ArraySize, + bigint::{ArrayEncoding, Bounded}, group::{ self, cofactor::CofactorGroup, @@ -122,7 +122,7 @@ where } let mut q = Self::IDENTITY; - let mut pos = C::Uint::BITS - 4; + let mut pos = C::Uint::BITS as usize - 4; loop { let slot = (k[pos >> 3] >> (pos & 7)) & 0xf; @@ -154,10 +154,10 @@ impl CofactorGroup for ProjectivePoint where Self: Double, C: PrimeCurveParams, + CompressedPoint: Copy + Send + Sync, FieldBytes: Copy, FieldBytesSize: ModulusSize, - CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { type Subgroup = Self; @@ -301,10 +301,11 @@ where impl GroupEncoding for ProjectivePoint where C: PrimeCurveParams, + CompressedPoint: Send + Sync, FieldBytes: Copy, FieldBytesSize: ModulusSize, CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { type Repr = CompressedPoint; @@ -434,10 +435,10 @@ impl PrimeGroup for ProjectivePoint where Self: Double, C: PrimeCurveParams, + CompressedPoint: Copy + Send + Sync, FieldBytes: Copy, FieldBytesSize: ModulusSize, - CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { } @@ -445,10 +446,10 @@ impl PrimeCurve for ProjectivePoint where Self: Double, C: PrimeCurveParams, + CompressedPoint: Copy + Send + Sync, FieldBytes: Copy, FieldBytesSize: ModulusSize, - CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + as ArraySize>::ArrayType: Copy, { type Affine = AffinePoint; } @@ -465,9 +466,9 @@ where impl ToEncodedPoint for ProjectivePoint where C: PrimeCurveParams, - FieldBytesSize: ModulusSize, CompressedPoint: Copy, - as ArrayLength>::ArrayType: Copy, + FieldBytesSize: ModulusSize, + as ArraySize>::ArrayType: Copy, { fn to_encoded_point(&self, compress: bool) -> EncodedPoint { self.to_affine().to_encoded_point(compress) diff --git a/sm2/Cargo.toml b/sm2/Cargo.toml index 2847f36c..8e456f26 100644 --- a/sm2/Cargo.toml +++ b/sm2/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sm2" -version = "0.13.3" +version = "0.14.0-pre" description = """ Pure Rust implementation of the SM2 elliptic curve as defined in the Chinese national standard GM/T 0003-2012 as well as ISO/IEC 14888. Includes support for @@ -14,17 +14,17 @@ readme = "README.md" categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "shangmi", "signature"] edition = "2021" -rust-version = "1.65" +rust-version = "1.73" [dependencies] -elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -primeorder = { version = "0.13.1", optional = true, path = "../primeorder" } -rfc6979 = { version = "0.4", optional = true } +primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } +rfc6979 = { version = "=0.5.0-pre.1", optional = true } serdect = { version = "0.2", optional = true, default-features = false } -signature = { version = "2.2", optional = true, features = ["rand_core"] } -sm3 = { version = "0.4", optional = true, default-features = false } +signature = { version = "=2.3.0-pre.1", optional = true, features = ["rand_core"] } +sm3 = { version = "=0.5.0-pre.1", optional = true, default-features = false } [dev-dependencies] hex-literal = "0.4" diff --git a/sm2/src/arithmetic/scalar.rs b/sm2/src/arithmetic/scalar.rs index 3cbd1cd8..652d3a0b 100644 --- a/sm2/src/arithmetic/scalar.rs +++ b/sm2/src/arithmetic/scalar.rs @@ -137,8 +137,8 @@ impl Scalar { /// Right shifts the scalar. /// /// Note: not constant-time with respect to the `shift` parameter. - pub const fn shr_vartime(&self, shift: usize) -> Scalar { - Self(self.0.shr_vartime(shift)) + pub const fn shr_vartime(&self, shift: u32) -> Scalar { + Self(self.0.wrapping_shr_vartime(shift)) } } @@ -164,7 +164,7 @@ impl FromUintUnchecked for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U256 = Sm2::ORDER.shr_vartime(1); + const MODULUS_SHR1: U256 = Sm2::ORDER.wrapping_shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } @@ -173,7 +173,7 @@ impl Shr for Scalar { type Output = Self; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } @@ -181,7 +181,7 @@ impl Shr for &Scalar { type Output = Scalar; fn shr(self, rhs: usize) -> Self::Output { - self.shr_vartime(rhs) + self.shr_vartime(rhs as u32) } } diff --git a/sm2/src/dsa.rs b/sm2/src/dsa.rs index ffbcb90e..b853f65b 100644 --- a/sm2/src/dsa.rs +++ b/sm2/src/dsa.rs @@ -45,7 +45,6 @@ pub use self::{signing::SigningKey, verifying::VerifyingKey}; use crate::{FieldBytes, NonZeroScalar, Sm2}; use core::fmt::{self, Debug}; -use elliptic_curve::generic_array::sequence::Concat; use signature::{Error, Result, SignatureEncoding}; #[cfg(feature = "alloc")] diff --git a/sm2/src/dsa/signing.rs b/sm2/src/dsa/signing.rs index 8b692790..b884fb7e 100644 --- a/sm2/src/dsa/signing.rs +++ b/sm2/src/dsa/signing.rs @@ -20,7 +20,7 @@ use crate::{ }; use core::fmt::{self, Debug}; use elliptic_curve::{ - generic_array::typenum::Unsigned, + array::typenum::Unsigned, ops::{MulByGenerator, Reduce}, point::AffineCoordinates, subtle::{Choice, ConstantTimeEq}, diff --git a/sm2/src/dsa/verifying.rs b/sm2/src/dsa/verifying.rs index a3f3cbe4..12fd2c84 100644 --- a/sm2/src/dsa/verifying.rs +++ b/sm2/src/dsa/verifying.rs @@ -18,7 +18,7 @@ use crate::{ PublicKey, Scalar, Sm2, }; use elliptic_curve::{ - generic_array::typenum::Unsigned, + array::typenum::Unsigned, ops::{LinearCombination, Reduce}, point::AffineCoordinates, sec1::ToEncodedPoint, diff --git a/sm2/src/lib.rs b/sm2/src/lib.rs index 33752722..e4d34d54 100644 --- a/sm2/src/lib.rs +++ b/sm2/src/lib.rs @@ -46,9 +46,9 @@ pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint}; pub use elliptic_curve::pkcs8; use elliptic_curve::{ + array::{typenum::U33, Array}, bigint::ArrayEncoding, consts::U32, - generic_array::{typenum::U33, GenericArray}, FieldBytesEncoding, }; @@ -91,7 +91,7 @@ impl pkcs8::AssociatedOid for Sm2 { } /// Compressed SEC1-encoded curve point. -pub type CompressedPoint = GenericArray; +pub type CompressedPoint = Array; /// SEC1 encoded point. pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint; From 1155a4233099492a7d1dab7ae3874bfea4246146 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 14:01:33 -0700 Subject: [PATCH 2/8] Update MSRV in CI configs and README.mds --- .github/workflows/bign256.yml | 12 ++++++------ .github/workflows/bp256.yml | 4 ++-- .github/workflows/bp384.yml | 4 ++-- .github/workflows/k256.yml | 14 +++++++------- .github/workflows/p192.yml | 6 +++--- .github/workflows/p224.yml | 6 +++--- .github/workflows/p256.yml | 12 ++++++------ .github/workflows/p384.yml | 12 ++++++------ .github/workflows/p521.yml | 6 +++--- .github/workflows/primeorder.yml | 4 ++-- .github/workflows/sm2.yml | 6 +++--- Cargo.lock | 8 +++++--- Cargo.toml | 3 +-- README.md | 4 ++-- bign256/README.md | 4 ++-- bp256/README.md | 4 ++-- bp384/README.md | 4 ++-- k256/README.md | 4 ++-- p192/README.md | 4 ++-- p224/README.md | 4 ++-- p256/README.md | 4 ++-- p384/README.md | 4 ++-- p521/README.md | 4 ++-- primeorder/README.md | 4 ++-- sm2/README.md | 4 ++-- 25 files changed, 73 insertions(+), 72 deletions(-) diff --git a/.github/workflows/bign256.yml b/.github/workflows/bign256.yml index 30a82ae4..f319e1af 100644 --- a/.github/workflows/bign256.yml +++ b/.github/workflows/bign256.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -46,7 +46,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -54,7 +54,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable @@ -76,19 +76,19 @@ jobs: include: # ARM32 - target: armv7-unknown-linux-gnueabihf - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: armv7-unknown-linux-gnueabihf rust: stable # ARM64 - target: aarch64-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: aarch64-unknown-linux-gnu rust: stable # PPC32 - target: powerpc-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: powerpc-unknown-linux-gnu rust: stable diff --git a/.github/workflows/bp256.yml b/.github/workflows/bp256.yml index f04c64e5..55c70453 100644 --- a/.github/workflows/bp256.yml +++ b/.github/workflows/bp256.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -49,7 +49,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/bp384.yml b/.github/workflows/bp384.yml index 579ab062..9529fb6d 100644 --- a/.github/workflows/bp384.yml +++ b/.github/workflows/bp384.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -49,7 +49,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/k256.yml b/.github/workflows/k256.yml index b7a6d973..3ccb7997 100644 --- a/.github/workflows/k256.yml +++ b/.github/workflows/k256.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -59,7 +59,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable steps: - uses: actions/checkout@v4 @@ -75,7 +75,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -83,7 +83,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable @@ -105,19 +105,19 @@ jobs: include: # ARM32 - target: armv7-unknown-linux-gnueabihf - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: armv7-unknown-linux-gnueabihf rust: stable # ARM64 - target: aarch64-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: aarch64-unknown-linux-gnu rust: stable # PPC32 - target: powerpc-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: powerpc-unknown-linux-gnu rust: stable diff --git a/.github/workflows/p192.yml b/.github/workflows/p192.yml index 6a444a60..06e9fce1 100644 --- a/.github/workflows/p192.yml +++ b/.github/workflows/p192.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -49,7 +49,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -57,7 +57,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable diff --git a/.github/workflows/p224.yml b/.github/workflows/p224.yml index 08f554b2..102fab0c 100644 --- a/.github/workflows/p224.yml +++ b/.github/workflows/p224.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -51,7 +51,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -59,7 +59,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable diff --git a/.github/workflows/p256.yml b/.github/workflows/p256.yml index a720c90d..854597c1 100644 --- a/.github/workflows/p256.yml +++ b/.github/workflows/p256.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -58,7 +58,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -66,7 +66,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable @@ -89,19 +89,19 @@ jobs: include: # ARM32 - target: armv7-unknown-linux-gnueabihf - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: armv7-unknown-linux-gnueabihf rust: stable # ARM64 - target: aarch64-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: aarch64-unknown-linux-gnu rust: stable # PPC32 - target: powerpc-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: powerpc-unknown-linux-gnu rust: stable diff --git a/.github/workflows/p384.yml b/.github/workflows/p384.yml index f2df146e..999a2c37 100644 --- a/.github/workflows/p384.yml +++ b/.github/workflows/p384.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -55,7 +55,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -63,7 +63,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable @@ -85,19 +85,19 @@ jobs: include: # ARM32 - target: armv7-unknown-linux-gnueabihf - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: armv7-unknown-linux-gnueabihf rust: stable # ARM64 - target: aarch64-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: aarch64-unknown-linux-gnu rust: stable # PPC32 - target: powerpc-unknown-linux-gnu - rust: 1.65.0 # MSRV (cross) + rust: 1.73.0 # MSRV (cross) - target: powerpc-unknown-linux-gnu rust: stable diff --git a/.github/workflows/p521.yml b/.github/workflows/p521.yml index d5011d99..f67b51d0 100644 --- a/.github/workflows/p521.yml +++ b/.github/workflows/p521.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -58,7 +58,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -66,7 +66,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable diff --git a/.github/workflows/primeorder.yml b/.github/workflows/primeorder.yml index 87d680b1..08407085 100644 --- a/.github/workflows/primeorder.yml +++ b/.github/workflows/primeorder.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -43,7 +43,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/sm2.yml b/.github/workflows/sm2.yml index da798d13..b0fda8ca 100644 --- a/.github/workflows/sm2.yml +++ b/.github/workflows/sm2.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.65.0 # MSRV + - 1.73.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -48,7 +48,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -56,7 +56,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.65.0 # MSRV + rust: 1.73.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable diff --git a/Cargo.lock b/Cargo.lock index 36cff5ec..0e34ba68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -363,11 +363,12 @@ dependencies = [ [[package]] name = "ecdsa" version = "0.17.0-pre.1" +source = "git+https://github.com/RustCrypto/signatures.git#2cb7693956865c8c07b93b26055a16e58eb863ba" dependencies = [ "der", "digest", "elliptic-curve", - "rfc6979 0.5.0-pre.1", + "rfc6979 0.5.0-pre.1 (git+https://github.com/RustCrypto/signatures.git)", "serdect 0.2.0", "signature", "spki", @@ -1016,6 +1017,8 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rfc6979" version = "0.5.0-pre.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f74fe2f5245b7dcff4f1c633a5dcc1fb54dbb0e4b1fa569ab60863806229d54f" dependencies = [ "hmac", "subtle", @@ -1024,8 +1027,7 @@ dependencies = [ [[package]] name = "rfc6979" version = "0.5.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f74fe2f5245b7dcff4f1c633a5dcc1fb54dbb0e4b1fa569ab60863806229d54f" +source = "git+https://github.com/RustCrypto/signatures.git#2cb7693956865c8c07b93b26055a16e58eb863ba" dependencies = [ "hmac", "subtle", diff --git a/Cargo.toml b/Cargo.toml index f5a2c624..1f1d9c50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,4 @@ members = [ opt-level = 2 [patch.crates-io.ecdsa] -#git = "https://github.com/RustCrypto/signatures.git" -path = "../signatures/ecdsa" +git = "https://github.com/RustCrypto/signatures.git" diff --git a/README.md b/README.md index c8ea4d72..f46309d9 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ if you are interested in curves beyond the ones listed here. ## Minimum Supported Rust Version -All crates in this repository support Rust **1.65** or higher. +All crates in this repository support Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -57,7 +57,7 @@ dual licensed as above, without any additional terms or conditions. [//]: # (badges) -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [deps-image]: https://deps.rs/repo/github/RustCrypto/elliptic-curves/status.svg diff --git a/bign256/README.md b/bign256/README.md index b6ac89a4..9a848ac8 100644 --- a/bign256/README.md +++ b/bign256/README.md @@ -35,7 +35,7 @@ Also known as bign-curve256v1. ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -69,7 +69,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/bign256.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/bign256.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/bp256/README.md b/bp256/README.md index 3df706ae..b63de610 100644 --- a/bp256/README.md +++ b/bp256/README.md @@ -14,7 +14,7 @@ implemented in terms of traits from the [`elliptic-curve`] crate. ## Minimum Supported Rust Version -Rust **1.65* or higher. +Rust **1.73* or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -46,7 +46,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/bp256/badge.svg [docs-link]: https://docs.rs/bp256/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/bp256/badge.svg?branch=master&event=push diff --git a/bp384/README.md b/bp384/README.md index 9950bd29..ddc04578 100644 --- a/bp384/README.md +++ b/bp384/README.md @@ -14,7 +14,7 @@ implemented in terms of traits from the [`elliptic-curve`] crate. ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -46,7 +46,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/bp384/badge.svg [docs-link]: https://docs.rs/bp384/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/bp384/badge.svg?branch=master&event=push diff --git a/k256/README.md b/k256/README.md index 2f4cebaf..034dd6f3 100644 --- a/k256/README.md +++ b/k256/README.md @@ -71,7 +71,7 @@ most popular and commonly used elliptic curves. ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -105,7 +105,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/k256/badge.svg?branch=master&event=push [build-link]: https://github.com/RustCrypto/elliptic-curves/actions?query=workflow%3Ak256 [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/p192/README.md b/p192/README.md index f7957160..011c97b4 100644 --- a/p192/README.md +++ b/p192/README.md @@ -53,7 +53,7 @@ Also known as secp192r1 (SECG). ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -87,7 +87,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p192.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p192.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/p224/README.md b/p224/README.md index e667fe76..61ae577b 100644 --- a/p224/README.md +++ b/p224/README.md @@ -42,7 +42,7 @@ Also known as secp224r1 (SECG). ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -76,7 +76,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p224.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p224.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/p256/README.md b/p256/README.md index 610910c7..c4d55c50 100644 --- a/p256/README.md +++ b/p256/README.md @@ -44,7 +44,7 @@ like TLS and the associated X.509 PKI. ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -78,7 +78,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p256.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p256.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/p384/README.md b/p384/README.md index 1bd31af2..e5fa4022 100644 --- a/p384/README.md +++ b/p384/README.md @@ -44,7 +44,7 @@ X.509 PKI. ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -78,7 +78,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p384.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p384.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/p521/README.md b/p521/README.md index 9826311c..e358a5b4 100644 --- a/p521/README.md +++ b/p521/README.md @@ -39,7 +39,7 @@ Also known as secp521r1 (SECG). ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -73,7 +73,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p521.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p521.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/primeorder/README.md b/primeorder/README.md index 60309043..0d4d836a 100644 --- a/primeorder/README.md +++ b/primeorder/README.md @@ -45,7 +45,7 @@ USE AT YOUR OWN RISK! ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -79,7 +79,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/primeorder.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/primeorder.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves diff --git a/sm2/README.md b/sm2/README.md index fec819f0..fe25bf94 100644 --- a/sm2/README.md +++ b/sm2/README.md @@ -37,7 +37,7 @@ The SM2 cryptosystem is composed of three distinct algorithms: ## Minimum Supported Rust Version -Rust **1.65** or higher. +Rust **1.73** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -71,7 +71,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/sm2.yml/badge.svg [build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/sm2.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.73+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves From ee6d1b35ce87379bbb08c592bd89a01474dedc1c Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 14:14:07 -0700 Subject: [PATCH 3/8] rustfmt --- k256/src/schnorr.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/k256/src/schnorr.rs b/k256/src/schnorr.rs index 59021ab4..0e94c68b 100644 --- a/k256/src/schnorr.rs +++ b/k256/src/schnorr.rs @@ -145,10 +145,9 @@ impl TryFrom<&[u8]> for Signature { fn try_from(bytes: &[u8]) -> Result { let (r_bytes, s_bytes) = bytes.split_at(Self::BYTE_SIZE / 2); - let r: FieldElement = Option::from(FieldElement::from_bytes(FieldBytes::from_slice( - r_bytes, - ))) - .ok_or_else(Error::new)?; + let r: FieldElement = + Option::from(FieldElement::from_bytes(FieldBytes::from_slice(r_bytes))) + .ok_or_else(Error::new)?; // one of the rules for valid signatures: !is_infinite(R); if r.is_zero().into() { From bcc057d1f76c875cb3c04351b0a7e71d0b22e154 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 14:23:01 -0700 Subject: [PATCH 4/8] Bump clippy to 1.73 and fix --- .github/workflows/workspace.yml | 2 +- sm2/src/arithmetic/field.rs | 1 - sm2/src/arithmetic/scalar.rs | 1 - sm2/src/lib.rs | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index d3c258b9..59ee8b24 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.66.0 + toolchain: 1.73.0 components: clippy - run: cargo clippy --all --all-features -- -D warnings diff --git a/sm2/src/arithmetic/field.rs b/sm2/src/arithmetic/field.rs index e0d7c77d..9abb746f 100644 --- a/sm2/src/arithmetic/field.rs +++ b/sm2/src/arithmetic/field.rs @@ -14,7 +14,6 @@ clippy::cast_possible_wrap, clippy::cast_sign_loss, clippy::cast_possible_truncation, - clippy::integer_arithmetic, clippy::should_implement_trait, clippy::suspicious_op_assign_impl, clippy::unused_unit, diff --git a/sm2/src/arithmetic/scalar.rs b/sm2/src/arithmetic/scalar.rs index 652d3a0b..c00bf721 100644 --- a/sm2/src/arithmetic/scalar.rs +++ b/sm2/src/arithmetic/scalar.rs @@ -15,7 +15,6 @@ clippy::cast_sign_loss, clippy::cast_possible_truncation, clippy::identity_op, - clippy::integer_arithmetic, clippy::too_many_arguments, clippy::unnecessary_cast )] diff --git a/sm2/src/lib.rs b/sm2/src/lib.rs index e4d34d54..0e0271f7 100644 --- a/sm2/src/lib.rs +++ b/sm2/src/lib.rs @@ -15,7 +15,6 @@ clippy::cast_sign_loss, clippy::checked_conversions, clippy::implicit_saturating_sub, - clippy::integer_arithmetic, clippy::panic, clippy::panic_in_result_fn, clippy::unwrap_used, From ddeaccdc9cd5f65488f1200ed8db1b9a04372818 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 14:35:34 -0700 Subject: [PATCH 5/8] p521: fix 32-bit targets --- p521/src/arithmetic/scalar.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p521/src/arithmetic/scalar.rs b/p521/src/arithmetic/scalar.rs index 7cb03834..065dec5b 100644 --- a/p521/src/arithmetic/scalar.rs +++ b/p521/src/arithmetic/scalar.rs @@ -287,10 +287,10 @@ impl Scalar { /// /// Note: not constant-time with respect to the `shift` parameter. #[cfg(target_pointer_width = "32")] - pub const fn shr_vartime(&self, shift: usize) -> Scalar { + pub const fn shr_vartime(&self, shift: u32) -> Scalar { Self(u32x18_to_u64x9( &U576::from_words(u64x9_to_u32x18(&self.0)) - .shr_vartime(shift) + .wrapping_shr_vartime(shift) .to_words(), )) } From 5af298eb43d34e5ebce146c015523e68c362850d Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 17:52:15 -0700 Subject: [PATCH 6/8] Bump elliptic-curve to v0.14.0-pre.2 --- Cargo.lock | 28 ++++++++++------------------ Cargo.toml | 3 --- bign256/Cargo.toml | 2 +- bp256/Cargo.toml | 4 ++-- bp384/Cargo.toml | 4 ++-- k256/Cargo.toml | 6 +++--- p192/Cargo.toml | 6 +++--- p224/Cargo.toml | 6 +++--- p256/Cargo.toml | 6 +++--- p384/Cargo.toml | 6 +++--- p521/Cargo.toml | 6 +++--- primeorder/Cargo.toml | 2 +- sm2/Cargo.toml | 2 +- 13 files changed, 35 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e34ba68..00b5fec1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,7 +60,7 @@ dependencies = [ "primeorder", "proptest", "rand_core", - "rfc6979 0.5.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rfc6979", "signature", ] @@ -317,9 +317,9 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.6.0-pre.9" +version = "0.6.0-pre.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ccdf8183c2226b057661e7d89624e75108e67b28306c898581fee700ff2d992" +checksum = "12979c1e0771d68f02c2fb93fb0ad54e597f82d608fb569db792d99ebd0bb3c5" dependencies = [ "hybrid-array", "num-traits", @@ -362,13 +362,14 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.17.0-pre.1" -source = "git+https://github.com/RustCrypto/signatures.git#2cb7693956865c8c07b93b26055a16e58eb863ba" +version = "0.17.0-pre.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cae8ed6f5c6fcb637533628167d436653c3045721175741f2bf201ac6fbe3270" dependencies = [ "der", "digest", "elliptic-curve", - "rfc6979 0.5.0-pre.1 (git+https://github.com/RustCrypto/signatures.git)", + "rfc6979", "serdect 0.2.0", "signature", "spki", @@ -382,9 +383,9 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "elliptic-curve" -version = "0.14.0-pre.1" +version = "0.14.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27861f85de50861460eaa0787325f5bc69c763b1496e24a3ca9a2f243f180553" +checksum = "53c5ff6cab3de51acc7aa1b7ed79e85d4ac92dc718f18899d7622cf9dc0fae94" dependencies = [ "base16ct", "base64ct", @@ -1024,15 +1025,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "rfc6979" -version = "0.5.0-pre.1" -source = "git+https://github.com/RustCrypto/signatures.git#2cb7693956865c8c07b93b26055a16e58eb863ba" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "rustix" version = "0.36.16" @@ -1200,7 +1192,7 @@ dependencies = [ "primeorder", "proptest", "rand_core", - "rfc6979 0.5.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rfc6979", "serdect 0.2.0", "signature", "sm3", diff --git a/Cargo.toml b/Cargo.toml index 1f1d9c50..15523c0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,3 @@ members = [ [profile.dev] opt-level = 2 - -[patch.crates-io.ecdsa] -git = "https://github.com/RustCrypto/signatures.git" diff --git a/bign256/Cargo.toml b/bign256/Cargo.toml index ed2416d4..67d475b4 100644 --- a/bign256/Cargo.toml +++ b/bign256/Cargo.toml @@ -17,7 +17,7 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", features = ["hazmat", "sec1"] } # optional dependencies primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index e9430289..9868cf1a 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -13,10 +13,10 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa = { version = "=0.17.0-pre.1", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "=0.17.0-pre.2", optional = true, default-features = false, features = ["der"] } primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index 4a73cbe3..7b0b15bd 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -13,10 +13,10 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa = { version = "=0.17.0-pre.1", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "=0.17.0-pre.2", optional = true, default-features = false, features = ["der"] } primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } diff --git a/k256/Cargo.toml b/k256/Cargo.toml index 8bc56f72..f9fca056 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -19,11 +19,11 @@ rust-version = "1.73" [dependencies] cfg-if = "1.0" -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies once_cell = { version = "1.19", optional = true, default-features = false } -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } serdect = { version = "0.2", optional = true, default-features = false } sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } @@ -32,7 +32,7 @@ signature = { version = "=2.3.0-pre.1", optional = true } [dev-dependencies] blobby = "0.3" criterion = "0.5" -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" num-bigint = "0.4" num-traits = "0.2" diff --git a/p192/Cargo.toml b/p192/Cargo.toml index d5db6b39..3c601b40 100644 --- a/p192/Cargo.toml +++ b/p192/Cargo.toml @@ -16,17 +16,17 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "=0.8.0-pre.1", default-features = false } # optional dependencies -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } [dev-dependencies] -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } diff --git a/p224/Cargo.toml b/p224/Cargo.toml index 8418e89c..e6f880dd 100644 --- a/p224/Cargo.toml +++ b/p224/Cargo.toml @@ -16,10 +16,10 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } @@ -27,7 +27,7 @@ sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 3cb518ae..900210cb 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,10 +17,10 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } @@ -29,7 +29,7 @@ sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.5" -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } proptest = "1" diff --git a/p384/Cargo.toml b/p384/Cargo.toml index f10ce761..7dae411c 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -17,10 +17,10 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } serdect = { version = "0.2", optional = true, default-features = false } @@ -29,7 +29,7 @@ sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.5" -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } proptest = "1.4" diff --git a/p521/Cargo.toml b/p521/Cargo.toml index 0fd3a229..eca1e10d 100644 --- a/p521/Cargo.toml +++ b/p521/Cargo.toml @@ -17,10 +17,10 @@ rust-version = "1.73" [dependencies] base16ct = "0.2" -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.4", optional = true } primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } rand_core = { version = "0.6", optional = true, default-features = false } @@ -29,7 +29,7 @@ sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" -ecdsa-core = { version = "=0.17.0-pre.1", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.17.0-pre.2", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.4" primeorder = { version = "=0.14.0-pre", features = ["dev"], path = "../primeorder" } proptest = "1.4" diff --git a/primeorder/Cargo.toml b/primeorder/Cargo.toml index 3c51e57f..640f945c 100644 --- a/primeorder/Cargo.toml +++ b/primeorder/Cargo.toml @@ -17,7 +17,7 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["arithmetic", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["arithmetic", "sec1"] } # optional dependencies serdect = { version = "0.2", optional = true, default-features = false } diff --git a/sm2/Cargo.toml b/sm2/Cargo.toml index 8e456f26..4757b0d6 100644 --- a/sm2/Cargo.toml +++ b/sm2/Cargo.toml @@ -17,7 +17,7 @@ edition = "2021" rust-version = "1.73" [dependencies] -elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "=0.14.0-pre.2", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" } From 9621f375a265adef5a79b0380614c6756c17e2f1 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 17:53:19 -0700 Subject: [PATCH 7/8] Use shr_vartime --- bign256/src/arithmetic/scalar.rs | 2 +- bp256/src/arithmetic/scalar.rs | 2 +- bp384/src/arithmetic/scalar.rs | 2 +- k256/src/arithmetic/scalar.rs | 2 +- p192/src/arithmetic/scalar.rs | 2 +- p224/src/arithmetic/scalar.rs | 2 +- p256/src/arithmetic/scalar.rs | 2 +- p384/src/arithmetic/scalar.rs | 2 +- p521/src/arithmetic/scalar.rs | 2 +- sm2/src/arithmetic/scalar.rs | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bign256/src/arithmetic/scalar.rs b/bign256/src/arithmetic/scalar.rs index c2551eb6..340f5169 100644 --- a/bign256/src/arithmetic/scalar.rs +++ b/bign256/src/arithmetic/scalar.rs @@ -154,7 +154,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U256 = BignP256::ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: U256 = BignP256::ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } diff --git a/bp256/src/arithmetic/scalar.rs b/bp256/src/arithmetic/scalar.rs index 9ec5c3aa..8f44cc19 100644 --- a/bp256/src/arithmetic/scalar.rs +++ b/bp256/src/arithmetic/scalar.rs @@ -296,7 +296,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U256 = ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: U256 = ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } diff --git a/bp384/src/arithmetic/scalar.rs b/bp384/src/arithmetic/scalar.rs index a7c73e18..ed954011 100644 --- a/bp384/src/arithmetic/scalar.rs +++ b/bp384/src/arithmetic/scalar.rs @@ -303,7 +303,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U384 = ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: U384 = ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } diff --git a/k256/src/arithmetic/scalar.rs b/k256/src/arithmetic/scalar.rs index 943eed72..0d9f814a 100644 --- a/k256/src/arithmetic/scalar.rs +++ b/k256/src/arithmetic/scalar.rs @@ -39,7 +39,7 @@ use num_bigint::{BigUint, ToBigUint}; const MODULUS: [Word; U256::LIMBS] = ORDER.to_words(); /// Constant representing the modulus / 2 -const FRAC_MODULUS_2: U256 = ORDER.wrapping_shr_vartime(1); +const FRAC_MODULUS_2: U256 = ORDER.shr_vartime(1); /// Scalars are elements in the finite field modulo n. /// diff --git a/p192/src/arithmetic/scalar.rs b/p192/src/arithmetic/scalar.rs index aa9c83e9..f5c5c44c 100644 --- a/p192/src/arithmetic/scalar.rs +++ b/p192/src/arithmetic/scalar.rs @@ -192,7 +192,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U192 = NistP192::ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: U192 = NistP192::ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } diff --git a/p224/src/arithmetic/scalar.rs b/p224/src/arithmetic/scalar.rs index 5fc0e5ba..e0a1f6db 100644 --- a/p224/src/arithmetic/scalar.rs +++ b/p224/src/arithmetic/scalar.rs @@ -176,7 +176,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: Uint = NistP224::ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: Uint = NistP224::ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } diff --git a/p256/src/arithmetic/scalar.rs b/p256/src/arithmetic/scalar.rs index 7ffe1284..32cac621 100644 --- a/p256/src/arithmetic/scalar.rs +++ b/p256/src/arithmetic/scalar.rs @@ -36,7 +36,7 @@ use serdect::serde::{de, ser, Deserialize, Serialize}; pub(crate) const MODULUS: U256 = NistP256::ORDER; /// `MODULUS / 2` -const FRAC_MODULUS_2: Scalar = Scalar(MODULUS.wrapping_shr_vartime(1)); +const FRAC_MODULUS_2: Scalar = Scalar(MODULUS.shr_vartime(1)); /// MU = floor(2^512 / n) /// = 115792089264276142090721624801893421302707618245269942344307673200490803338238 diff --git a/p384/src/arithmetic/scalar.rs b/p384/src/arithmetic/scalar.rs index cae876ca..336640dc 100644 --- a/p384/src/arithmetic/scalar.rs +++ b/p384/src/arithmetic/scalar.rs @@ -206,7 +206,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U384 = NistP384::ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: U384 = NistP384::ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } diff --git a/p521/src/arithmetic/scalar.rs b/p521/src/arithmetic/scalar.rs index 065dec5b..13c6726b 100644 --- a/p521/src/arithmetic/scalar.rs +++ b/p521/src/arithmetic/scalar.rs @@ -511,7 +511,7 @@ impl Invert for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U576 = NistP521::ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: U576 = NistP521::ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } diff --git a/sm2/src/arithmetic/scalar.rs b/sm2/src/arithmetic/scalar.rs index c00bf721..e1ec6afc 100644 --- a/sm2/src/arithmetic/scalar.rs +++ b/sm2/src/arithmetic/scalar.rs @@ -163,7 +163,7 @@ impl FromUintUnchecked for Scalar { impl IsHigh for Scalar { fn is_high(&self) -> Choice { - const MODULUS_SHR1: U256 = Sm2::ORDER.wrapping_shr_vartime(1); + const MODULUS_SHR1: U256 = Sm2::ORDER.shr_vartime(1); self.to_canonical().ct_gt(&MODULUS_SHR1) } } From ad020be5dbceab96299dab26e9caf2f071cd1fcc Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 18:03:16 -0700 Subject: [PATCH 8/8] k256: fix benchmarks --- k256/benches/ecdsa.rs | 40 ++++++++++++++++++++++------------------ k256/benches/scalar.rs | 30 +++++++++++++++++------------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/k256/benches/ecdsa.rs b/k256/benches/ecdsa.rs index da32db12..572d42b8 100644 --- a/k256/benches/ecdsa.rs +++ b/k256/benches/ecdsa.rs @@ -5,35 +5,39 @@ use ecdsa_core::{ elliptic_curve::group::prime::PrimeCurveAffine, hazmat::{SignPrimitive, VerifyPrimitive}, }; -use k256::{ - elliptic_curve::{array::arr, group::ff::PrimeField}, - AffinePoint, FieldBytes, Scalar, -}; +use k256::{elliptic_curve::group::ff::PrimeField, AffinePoint, FieldBytes, Scalar}; fn test_scalar_d() -> Scalar { - Scalar::from_repr(arr![u8; - 0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70, - 0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8, - 0x82, 0xf1, 0x56, 0xa6, - ]) + Scalar::from_repr( + [ + 0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70, + 0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8, + 0x82, 0xf1, 0x56, 0xa6, + ] + .into(), + ) .unwrap() } fn test_scalar_k() -> Scalar { - Scalar::from_repr(arr![u8; - 0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5, - 0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e, - 0xeb, 0x80, 0x35, 0xe3, - ]) + Scalar::from_repr( + [ + 0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5, + 0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e, + 0xeb, 0x80, 0x35, 0xe3, + ] + .into(), + ) .unwrap() } fn test_scalar_z() -> FieldBytes { - arr![u8; - 0xe3, 0x35, 0x80, 0xeb, 0x6e, 0xd0, 0x22, 0xae, 0xd6, 0xaf, 0x20, 0xd9, 0x22, 0x37, - 0x63, 0x5e, 0x7c, 0x20, 0xc5, 0xf1, 0xbc, 0xd6, 0xae, 0xe8, 0x81, 0x82, 0xed, 0x71, - 0x80, 0xf6, 0xe2, 0x67 + [ + 0xe3, 0x35, 0x80, 0xeb, 0x6e, 0xd0, 0x22, 0xae, 0xd6, 0xaf, 0x20, 0xd9, 0x22, 0x37, 0x63, + 0x5e, 0x7c, 0x20, 0xc5, 0xf1, 0xbc, 0xd6, 0xae, 0xe8, 0x81, 0x82, 0xed, 0x71, 0x80, 0xf6, + 0xe2, 0x67, ] + .into() } fn bench_ecdsa(c: &mut Criterion) { diff --git a/k256/benches/scalar.rs b/k256/benches/scalar.rs index ea88a8dd..d7bc7f9e 100644 --- a/k256/benches/scalar.rs +++ b/k256/benches/scalar.rs @@ -5,27 +5,31 @@ use criterion::{ }; use hex_literal::hex; use k256::{ - elliptic_curve::{ - array::arr, group::ff::PrimeField, ops::LinearCombination, ops::MulByGenerator, - }, + elliptic_curve::{group::ff::PrimeField, ops::LinearCombination, ops::MulByGenerator}, ProjectivePoint, Scalar, }; fn test_scalar_x() -> Scalar { - Scalar::from_repr(arr![u8; - 0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70, - 0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8, - 0x82, 0xf1, 0x56, 0xa6, - ]) + Scalar::from_repr( + [ + 0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70, + 0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8, + 0x82, 0xf1, 0x56, 0xa6, + ] + .into(), + ) .unwrap() } fn test_scalar_y() -> Scalar { - Scalar::from_repr(arr![u8; - 0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5, - 0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e, - 0xeb, 0x80, 0x35, 0xe3, - ]) + Scalar::from_repr( + [ + 0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5, + 0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e, + 0xeb, 0x80, 0x35, 0xe3, + ] + .into(), + ) .unwrap() }