瀏覽代碼

Ensure the rng implements CryptoRng + RngCore

The lower levels require CryptoRng + RngCore, not just RngCore

In programs that use this crate, change:

use rand_core::RngCore;

to

use rand::{CryptoRng, RngCore};

and ensure the rng passed to prepare and handle is
impl CryptoRng + RngCore.
Ian Goldberg 3 月之前
父節點
當前提交
e7b44882fc
共有 6 個文件被更改,包括 12 次插入13 次删除
  1. 1 2
      Cargo.toml
  2. 4 4
      cmzcred_derive/src/lib.rs
  3. 2 2
      src/lib.rs
  4. 1 1
      tests/basic.rs
  5. 1 1
      tests/submodule.rs
  6. 3 3
      tests/wallet.rs

+ 1 - 2
Cargo.toml

@@ -10,7 +10,7 @@ generic_static = "0.2"
 group = "0.13"
 hex = { version = "0.4", features = [ "serde" ] }
 lazy_static = "1"
-rand_core = "0.6"
+rand = "0.8.5"
 serde = { version = "1", features = [ "derive" ] }
 serde_bytes = "0.11"
 serde_with = "3"
@@ -20,5 +20,4 @@ thiserror = "2"
 [dev-dependencies]
 bincode = "1"
 curve25519-dalek = { version = "4", features = [ "group", "rand_core", "digest" ] }
-rand = "0.8"
 sha2 = "0.10"

+ 4 - 4
cmzcred_derive/src/lib.rs

@@ -1280,7 +1280,7 @@ fn protocol_macro(
             };
             // If prove returns Err here, there's an actual bug.
             let #iss_proof_ident = issuer_proof::prove(&iss_proof_params,
-                &iss_proof_witness).unwrap();
+                &iss_proof_witness, rng).unwrap();
         };
         let cli_iss_params_fields = iss_proof_pub_points
             .iter()
@@ -1555,7 +1555,7 @@ fn protocol_macro(
         };
         // If prove returns Err here, there's an actual bug.
         let #cli_proof_ident = client_proof::prove(&cli_proof_params,
-            &cli_proof_witness).unwrap();
+            &cli_proof_witness, rng).unwrap();
     };
     let iss_cli_params_fields = cli_proof_pub_points
         .iter()
@@ -1819,7 +1819,7 @@ fn protocol_macro(
         let reqf = request_fields.field_iter();
         let csf = clientstate_fields.field_iter();
         quote! {
-            pub fn prepare(rng: &mut impl RngCore,
+            pub fn prepare(rng: &mut (impl CryptoRng + RngCore),
                 #(#client_show_args)* #(#client_issue_args)* #client_params_arg)
                     -> Result<(Request, ClientState),CMZError> {
                 let bp = cmz_basepoints::<Point>();
@@ -1953,7 +1953,7 @@ fn protocol_macro(
         };
 
         quote! {
-            pub fn handle<F,A>(rng: &mut impl RngCore,
+            pub fn handle<F,A>(rng: &mut (impl CryptoRng + RngCore),
                 request: Request, fill_creds: F, authorize: A)
                 -> #rettype
             where

+ 2 - 2
src/lib.rs

@@ -9,7 +9,7 @@ use generic_static::StaticTypeMap;
 use group::prime::PrimeGroup;
 use group::{Group, GroupEncoding, WnafBase, WnafScalar};
 use lazy_static::lazy_static;
-use rand_core::RngCore;
+use rand::RngCore;
 pub use serde::{Deserialize, Deserializer, Serialize, Serializer};
 pub use serde_with::{serde_as, DeserializeAs, SerializeAs};
 pub use sigma_compiler::*;
@@ -389,7 +389,7 @@ where
 ///     use cmz::{CMZ, CMZCred, CMZCredential, CMZPrivkey, CMZPubkey, CMZMac};
 ///     use cmz::{cmz_privkey_to_pubkey, serde_as, SerdeScalar, Serialize, Deserialize};
 ///     use group::Group;
-///     use rand_core::RngCore;
+///     use rand::{CryptoRng, RngCore};
 ///     use curve25519_dalek::ristretto::RistrettoPoint as Grp;
 ///     CMZ!{ Name<Grp>: attr1, attr2, attr3 }
 ///

+ 1 - 1
tests/basic.rs

@@ -2,7 +2,7 @@ use cmz::*;
 use curve25519_dalek::ristretto::RistrettoPoint;
 use curve25519_dalek::scalar::Scalar;
 use group::Group;
-use rand_core::RngCore;
+use rand::{CryptoRng, RngCore};
 use sha2::Sha512;
 
 CMZ! { Basic<RistrettoPoint> :

+ 1 - 1
tests/submodule.rs

@@ -4,7 +4,7 @@ use cmz::*;
 use curve25519_dalek::ristretto::RistrettoPoint;
 use curve25519_dalek::scalar::Scalar;
 use group::Group;
-use rand_core::RngCore;
+use rand::{CryptoRng, RngCore};
 use sha2::Sha512;
 
 pub mod cred {

+ 3 - 3
tests/wallet.rs

@@ -5,7 +5,7 @@
 use cmz::*;
 use curve25519_dalek::ristretto::RistrettoPoint as G;
 use group::Group;
-use rand_core::RngCore;
+use rand::{CryptoRng, RngCore};
 use sha2::Sha512;
 
 CMZ! { Wallet: randid, balance }
@@ -48,7 +48,7 @@ macro_rules! protos_def {
             // The issuer runs this on its own to create an Item credential for a
             // particular item (specified by a serial number) with a given price.
             fn issue_item(
-                rng: &mut impl RngCore,
+                rng: &mut (impl CryptoRng + RngCore),
                 serialno: u128,
                 price: u128,
                 privkey: &CMZPrivkey<G>,
@@ -77,7 +77,7 @@ macro_rules! protos_def {
             // with funds, to sent to a client.  The issuer will presumably charge
             // the client out of band for this loaded wallet.
             fn issue_wallet(
-                rng: &mut impl RngCore,
+                rng: &mut (impl CryptoRng + RngCore),
                 balance: u128,
                 privkey: &CMZPrivkey<G>,
                 public: &CMZPubkey<G>,