pub mod identification;
use std::str::FromStr;
pub use identification::*;
pub mod signature;
use serde::{Deserialize, Serialize};
pub use signature::*;
use num_bigint::BigUint;
pub trait Hash {
fn hash<T: AsRef<[u8]>>(value: T) -> Vec<u8>;
}
pub trait Sig {
fn sign<T: AsRef<[u8]>>(value: T) -> Vec<u8>;
fn verify<T: AsRef<[u8]>>(value: T, signature: &[u8]) -> bool;
}
pub trait Rand {
fn random_number(module: &BigUint) -> BigUint;
}
pub type Identity = BigUint;
#[derive(Clone, Serialize, Deserialize)]
pub(crate) struct SchnorrGroup {
p: BigUint,
q: BigUint,
a: BigUint,
}
impl SchnorrGroup {
pub(crate) fn from_str(p: &str, q: &str, a: &str) -> Option<Self> {
let p = BigUint::from_str(p).ok()?;
let q = BigUint::from_str(q).ok()?;
let a = BigUint::from_str(a).ok()?;
if a.modpow(&q, &p) != BigUint::from(1u32) {
return None;
}
Some(Self { p, q, a })
}
}