Skip to content

Commit

Permalink
Merge branch 'main' into Schnorr-Final
Browse files Browse the repository at this point in the history
* main:
  Update src/shares.rs
  • Loading branch information
mzacho committed Dec 1, 2023
2 parents 0676345 + 17e8270 commit 5a84668
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 36 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ edition = "2021"
getrandom = { version = "0.2" }
crypto-bigint = { version = "*", features = ["rand"] }
rand = "0.8.5"
lazy_static = "*"
crypto-primes = "*"
sha2 = "*"
34 changes: 7 additions & 27 deletions src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@ pub struct GroupSpec {
}

impl GroupSpec {
/// Constructs a new group spec with security parameter k
/// TODO: Constructs a new group spec with security parameter k
/// i.e. k is the bitsize of q = M
pub fn new() -> GroupSpec {
// Generate random safe prime p = 2q + 1
// where q is a safe prime
let (p, q, alpha) = get_parameters();

let (p, q) = generate_safe_primes();
let alpha = compute_group_generator(p, q);
GroupSpec { p, q, alpha }
// GroupSpec {
// p: NonZero::new(Nat::from_u16(23)).unwrap(),
// q: NonZero::new(Nat::from_u16(11)).unwrap(),
// alpha: Nat::from_u16(2),
// }
}

/// Returns a random from Zq
Expand All @@ -36,20 +29,8 @@ impl GroupSpec {
}
}

// Generate a safe prime p = 2q + 1, where q is also a safe prime
// and a generator alpha of Zp*
fn get_parameters() -> (
NonZero<crypto_bigint::Uint<4>>,
NonZero<crypto_bigint::Uint<4>>,
crypto_bigint::Uint<4>,
) {
let (p, q) = generate_safe_primes();
let alpha = generate_group_generator(p, q);
(p, q, alpha)
}

// Generate a generator of Zp* using rejection sampling
fn generate_group_generator(
/// Generate a generator of Zp* using rejection sampling
fn compute_group_generator(
p: NonZero<crypto_bigint::Uint<4>>,
q: NonZero<crypto_bigint::Uint<4>>,
) -> crypto_bigint::Uint<4> {
Expand All @@ -58,11 +39,10 @@ fn generate_group_generator(
while pow_mod(&x, &q, &p) != Nat::ONE {
x = Nat::random_mod(&mut OsRng, &p);
}

x
}

// Generate a safe prime p = 2q + 1, where q is the associated Sophie Germain prime
/// Generate a safe prime p = 2q + 1, where q is the associated Sophie Germain prime
fn generate_safe_primes() -> (
NonZero<crypto_bigint::Uint<4>>,
NonZero<crypto_bigint::Uint<4>>,
Expand All @@ -83,7 +63,6 @@ impl Default for GroupSpec {
}
}

// Test for alpha being a generator of Zp*
#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -93,6 +72,7 @@ mod tests {
fn test_generator_from_safe_prime() {
let group = GroupSpec::new();
let alpha = group.alpha;
// Test for alpha being a generator of Zp*
let raised = pow_mod(&alpha, &group.q, &group.p);

assert_eq!(raised, Nat::ONE)
Expand Down
2 changes: 1 addition & 1 deletion src/shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
node::Node,
};

/// An additive share [s] = (x, y) where x + y mod m = s
/// An additive share [s] = (x, y) where x + y mod M = s
#[derive(Debug, Clone)]
pub struct Shares {
pub x: Nat,
Expand Down

0 comments on commit 5a84668

Please sign in to comment.