diff --git a/Cargo.toml b/Cargo.toml index 6f77740f..cb141bde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,19 +15,19 @@ name = "curv" crate-type = ["lib"] [dependencies] -curve25519-dalek = "3" +curve25519-dalek = { version = "4.0.0", features = ["rand_core"] } digest = "0.9" generic-array = "0.14" typenum = "1.13" -ff-zeroize = "0.6.3" +ff-zeroize = { package = "ff", git = "https://github.com/tmpfs/ff-zeroize", branch = "rand-upgrade" } hex = { version = "0.4", features = ["serde"] } hmac = "0.11" thiserror = "1" lazy_static = "1.4" num-traits = "0.2" num-integer = "0.1" -pairing-plus = "0.19" -rand = "0.7" +pairing-plus = { git = "https://github.com/tmpfs/pairing-plus.git", branch = "rand-upgrade" } +rand = "0.8.5" serde = { version = "1.0", features = ["derive"] } serde_bytes = "0.11" serde_derive = "1.0" @@ -60,4 +60,4 @@ blake2 = "0.9" default = ["rust-gmp-kzen"] [package.metadata.docs.rs] -rustdoc-args = [ "--html-in-header", "katex-header.html", "--cfg", "docsrs" ] +rustdoc-args = ["--html-in-header", "katex-header.html", "--cfg", "docsrs"] diff --git a/src/elliptic/curves/curve_ristretto.rs b/src/elliptic/curves/curve_ristretto.rs index 210a200d..a079d744 100644 --- a/src/elliptic/curves/curve_ristretto.rs +++ b/src/elliptic/curves/curve_ristretto.rs @@ -13,6 +13,7 @@ use std::sync::atomic; use curve25519_dalek::constants::{BASEPOINT_ORDER, RISTRETTO_BASEPOINT_POINT}; use curve25519_dalek::ristretto::CompressedRistretto; use curve25519_dalek::traits::{Identity, IsIdentity}; +use curve25519_dalek::Scalar; use generic_array::GenericArray; use rand::thread_rng; use sha2::{Digest, Sha256}; @@ -98,7 +99,7 @@ impl ECScalar for RistrettoScalar { fn zero() -> RistrettoScalar { RistrettoScalar { purpose: "zero", - fe: SK::zero().into(), + fe: SK::ZERO.into(), } } @@ -129,7 +130,7 @@ impl ECScalar for RistrettoScalar { let bytes: [u8; 32] = bytes.try_into().or(Err(DeserializationError))?; Ok(RistrettoScalar { purpose: "from_bigint", - fe: SK::from_canonical_bytes(bytes) + fe: Option::::from(SK::from_canonical_bytes(bytes)) .ok_or(DeserializationError)? .into(), }) @@ -274,6 +275,7 @@ impl ECPoint for RistrettoPoint { buffer[32 - n..].copy_from_slice(bytes); CompressedRistretto::from_slice(&buffer) + .unwrap() .decompress() .ok_or(DeserializationError) .map(|ge| RistrettoPoint { diff --git a/src/elliptic/curves/ed25519.rs b/src/elliptic/curves/ed25519.rs index f00497f0..f7a19f76 100644 --- a/src/elliptic/curves/ed25519.rs +++ b/src/elliptic/curves/ed25519.rs @@ -14,6 +14,7 @@ use super::{ Curve, DeserializationError, NotOnCurve, PointCoords, }; use crate::{arithmetic::traits::*, cryptographic_primitives::hashing::Digest, BigInt}; +use curve25519_dalek::traits::BasepointTable; use curve25519_dalek::{ constants, edwards::{CompressedEdwardsY, EdwardsPoint}, @@ -35,13 +36,13 @@ lazy_static::lazy_static! { ge: EdwardsPoint::identity(), }; - static ref FE_ZERO: SK = Scalar::zero(); + static ref FE_ZERO: SK = Scalar::ZERO; static ref BASE_POINT2: Ed25519Point = { let bytes = GENERATOR.serialize_compressed(); let hashed = sha2::Sha256::digest(bytes.as_ref()); let hashed_twice = sha2::Sha256::digest(&hashed); - let p = CompressedEdwardsY::from_slice(&hashed_twice).decompress().unwrap(); + let p = CompressedEdwardsY::from_slice(&hashed_twice).unwrap().decompress().unwrap(); let eight = Scalar::from(8u8); Ed25519Point { purpose: "base_point2", @@ -151,7 +152,7 @@ impl ECScalar for Ed25519Scalar { let arr: [u8; 32] = bytes.try_into().map_err(|_| DeserializationError)?; Ok(Ed25519Scalar { purpose: "deserialize", - fe: SK::from_bits(arr).into(), + fe: SK::from_bytes_mod_order(arr).into(), }) } @@ -352,7 +353,7 @@ impl ECPoint for Ed25519Point { fn generator_mul(scalar: &Self::Scalar) -> Self { Self { purpose: "generator_mul", - ge: constants::ED25519_BASEPOINT_TABLE.basepoint_mul(&scalar.fe), // Much faster than multiplying manually by the generator point. + ge: constants::ED25519_BASEPOINT_TABLE.mul_base(&scalar.fe), // Much faster than multiplying manually by the generator point. } } diff --git a/src/elliptic/curves/test.rs b/src/elliptic/curves/test.rs index 3bf4bb27..2b0d135a 100644 --- a/src/elliptic/curves/test.rs +++ b/src/elliptic/curves/test.rs @@ -121,7 +121,7 @@ fn scalar_behaves_the_same_as_bigint() { let mut s: E::Scalar = ECScalar::zero(); for _ in 0..100 { - let operation = rng.gen_range(0, 4); + let operation = rng.gen_range(0..4); if operation == 0 { let n_inv = BigInt::mod_inv(&n, q); let s_inv = s.invert().map(|s| s.to_bigint());