Skip to content

Commit

Permalink
update to rand 0.8.5 to fix wasm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Aug 2, 2023
1 parent 3cbf3aa commit da54057
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
6 changes: 4 additions & 2 deletions src/elliptic/curves/curve_ristretto.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -98,7 +99,7 @@ impl ECScalar for RistrettoScalar {
fn zero() -> RistrettoScalar {
RistrettoScalar {
purpose: "zero",
fe: SK::zero().into(),
fe: SK::ZERO.into(),
}
}

Expand Down Expand Up @@ -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::<Scalar>::from(SK::from_canonical_bytes(bytes))
.ok_or(DeserializationError)?
.into(),
})
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions src/elliptic/curves/ed25519.rs
Expand Up @@ -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},
Expand All @@ -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",
Expand Down Expand Up @@ -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(),
})
}

Expand Down Expand Up @@ -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.
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/elliptic/curves/test.rs
Expand Up @@ -121,7 +121,7 @@ fn scalar_behaves_the_same_as_bigint<E: Curve>() {
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());
Expand Down

0 comments on commit da54057

Please sign in to comment.