Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
10d9e committed Nov 2, 2023
1 parent 1958f61 commit c21a030
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
28 changes: 16 additions & 12 deletions src/bin/client.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use curve25519_dalek::{RistrettoPoint, Scalar};
use num_bigint::{BigUint, RandBigInt};
use num_bigint::BigUint;
use rand::rngs::OsRng;
use sha2::{Digest, Sha512};
use std::str::FromStr;
use structopt::StructOpt;
use strum::VariantNames;
use zk_pass::conversion::ByteConvertible;

use std::error::Error;
use zk_pass::chaum_pedersen::GroupParams;
use zk_pass::chaum_pedersen::{
curve25519::EllipticCurveChaumPedersen, discretelog::DiscreteLogChaumPedersen,
ChaumPedersen,
curve25519::EllipticCurveChaumPedersen, discretelog::DiscreteLogChaumPedersen, ChaumPedersen,
};
use zk_pass::rand::RandomGenerator;
use zk_pass::client::AuthClientLib;
use zk_pass::cmdutil::{ChaumPedersenType, EllipticCurveType, RfcModpType};
use std::error::Error;
use zk_pass::rand::RandomGenerator;

/// Command-line options structure for the ZKPass client.
#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -86,7 +85,9 @@ struct Opt {
/// let random_secret: [u8; 64] = hash_or_randomize_secret(None);
/// // random_secret is now a randomly generated array of bytes.
/// ```
fn hash_or_randomize_secret<T: ByteConvertible<T> + RandomGenerator<T>>(secret: Option<&String>) -> T {
fn hash_or_randomize_secret<T: ByteConvertible<T> + RandomGenerator<T>>(
secret: Option<&String>,
) -> T {
match secret {
Some(s) => {
let mut hasher = Sha512::new();
Expand Down Expand Up @@ -153,10 +154,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
let opt = Opt::from_args(); // Parses command-line arguments.

// Parses group parameters for Discrete Log and Elliptic Curve implementations.
let dl_params = GroupParams::<BigUint>::from_str(&opt.modp.to_string())
.map_err(|_| "Invalid discrete log group parameters provided in command-line arguments".to_string())?;
let ec_params = GroupParams::<RistrettoPoint>::from_str(&opt.curve.to_string())
.map_err(|_| "Invalid elliptic curve group parameters provided in command-line arguments".to_string())?;
let dl_params = GroupParams::<BigUint>::from_str(&opt.modp.to_string()).map_err(|_| {
"Invalid discrete log group parameters provided in command-line arguments".to_string()
})?;
let ec_params =
GroupParams::<RistrettoPoint>::from_str(&opt.curve.to_string()).map_err(|_| {
"Invalid elliptic curve group parameters provided in command-line arguments".to_string()
})?;

// Displays initial client information.
println!("🔥 Starting ZK_PASS server 🔥");
Expand All @@ -182,7 +186,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Secret generation for Discrete Log implementation.
//let x = hash_string::<BigUint>(opt.secret);
// Executes the protocol.
execute_protocol::<DiscreteLogChaumPedersen, _, _,>(
execute_protocol::<DiscreteLogChaumPedersen, _, _>(
&dl_params,
&x,
&opt.user,
Expand All @@ -195,7 +199,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let x = Scalar::from(3u32);

// Executes the protocol.
execute_protocol::<EllipticCurveChaumPedersen, _, _,>(
execute_protocol::<EllipticCurveChaumPedersen, _, _>(
&ec_params,
&x,
&opt.user,
Expand Down
4 changes: 1 addition & 3 deletions src/chaum_pedersen/curve25519.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::chaum_pedersen::{ChaumPedersen, GroupParams};
use curve25519_dalek::RistrettoPoint;
use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::RistrettoPoint;
use rand::rngs::OsRng;

/// A struct representing the Chaum-Pedersen protocol specialized for elliptic curve groups.
Expand Down Expand Up @@ -121,7 +121,6 @@ impl ChaumPedersen for EllipticCurveChaumPedersen {
}
}


#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -226,5 +225,4 @@ mod test {
// Asserting that the received point is equal to the original compressed point.
assert_eq!(received_point, compressed_point);
}

}
10 changes: 5 additions & 5 deletions src/chaum_pedersen/discretelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ impl ChaumPedersen for DiscreteLogChaumPedersen {

/// Defines the group parameters specific to discrete logarithm groups as `GroupParams<BigUint>`.
type GroupParameters = GroupParams<BigUint>;

/// Defines the type of parameters returned during the commitment phase.
/// These include two values representing the commitment and two values representing the randomness.
type CommitParameters = (BigUint, BigUint, BigUint, BigUint);

/// Calculates the commitment for the given secret `x` using the provided group parameters.
///
///
/// # Arguments
/// * `params`: Group parameters which include the base points `g` and `h`, and the moduli `p` and `q`.
/// * `x`: The secret value for which the commitment is being calculated.
Expand All @@ -57,7 +57,7 @@ impl ChaumPedersen for DiscreteLogChaumPedersen {

/// Generates a random challenge for the protocol within the group's range.
/// This challenge is used as part of the verification process.
///
///
/// # Arguments
/// * `params`: Group parameters used to define the range within which the challenge is generated.
///
Expand All @@ -70,7 +70,7 @@ impl ChaumPedersen for DiscreteLogChaumPedersen {

/// Generates a random challenge for the protocol within the group's range.
/// This challenge is used as part of the verification process.
///
///
/// # Arguments
/// * `params`: Group parameters used to define the range within which the challenge is generated.
///
Expand All @@ -92,7 +92,7 @@ impl ChaumPedersen for DiscreteLogChaumPedersen {

/// Verifies the response against the given commitment, challenge, and group parameters.
/// The function checks if the response is valid based on the protocol's criteria.
///
///
/// # Arguments
/// * `params`: Group parameters used in the verification.
/// * `s`: The response to be verified.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pub mod chaum_pedersen;
pub mod client;
pub mod cmdutil;
pub mod conversion;
pub mod rand;
mod repository;
pub mod service;
pub mod rand;
8 changes: 4 additions & 4 deletions src/rand.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use num_bigint::BigUint;
use curve25519_dalek::Scalar;
use crate::conversion::ByteConvertible;
use curve25519_dalek::RistrettoPoint;
use curve25519_dalek::Scalar;
use num_bigint::BigUint;
use rand::RngCore;
use crate::conversion::ByteConvertible;

pub trait RandomGenerator<T> {
fn generate_random() -> Result<T, Box<dyn std::error::Error>>;
Expand Down Expand Up @@ -33,4 +33,4 @@ impl RandomGenerator<RistrettoPoint> for RistrettoPoint {
rng.fill_bytes(&mut bytes);
RistrettoPoint::from_bytes(&bytes)
}
}
}
6 changes: 3 additions & 3 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use zkp_auth::{

/// A struct representing the zero-knowledge authentication service.
/// It supports different types of Chaum-Pedersen protocols.
///
///
/// # Type Parameters
///
///
/// * `C`: Represents the type of Chaum-Pedersen protocol.
/// * `T`: The type used for group elements.
/// * `S`: The type used for scalar values.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl ZkAuth<EllipticCurveChaumPedersen, RistrettoPoint, Scalar> {

/// Implementation of the `Auth` trait for `ZkAuth`.
///
/// This implementation provides the necessary methods for user registration,
/// This implementation provides the necessary methods for user registration,
/// creating authentication challenges, and verifying authentication answers.
/// It uses generic parameters `C`, `T`, and `S` to work with different cryptographic protocols and data types.
///
Expand Down

0 comments on commit c21a030

Please sign in to comment.