This commit is contained in:
EvilMuffinHa 2023-05-27 00:04:40 -04:00
parent 6413513ee9
commit 1f51923832
3 changed files with 39 additions and 4 deletions

View File

@ -7,6 +7,8 @@ edition = "2021"
[dependencies] [dependencies]
tiny-keccak = { version = "2.0", features = ["shake"] } tiny-keccak = { version = "2.0", features = ["shake"] }
aes = { version = "0.8.2" }
rand = { version = "0.8.5" }
nalgebra = { version = "0.32.2", optional = true } nalgebra = { version = "0.32.2", optional = true }
[features] [features]

View File

@ -1,4 +1,7 @@
use crate::sig::KeyGen; use crate::sig::KeyGen;
use aes::Aes128;
use rand::RngCore;
use tiny_keccak::{Shake, Xof};
pub struct SigParams { pub struct SigParams {
m: u16, m: u16,
@ -10,12 +13,40 @@ pub struct SigParams {
pk_seed_bytes: u8, pk_seed_bytes: u8,
} }
// sk_seed_bytes = salt_bytes
// R_bytes = salt_bytes
// O_bytes = ceil((n - o)(o)/2)
// v_bytes = ceil((n - o)/2)
// P1_bytes = m*binom((n - o + 1), 2) / 2
// P2_bytes = m * (n - o) * o / 2
// P3_bytes = m * binom((o + 1), 2) / 2
// L_bytes = m * (n - o) * o / 2
// csk_bytes = salt_bytes
// esk_bytes = salt_bytes + O_bytes + P1_bytes + L_bytes
// cpk_bytes = pk_seed_bytes + P3_bytes
// epk_bytes = P1_bytes + P2_bytes + P3_bytes
// sig_bytes = ceil(nk / 2) + salt_bytes
pub struct SigningKey { pub struct SigningKey {
v: VerifyKey, v: VerifyKey,
} }
pub struct VerifyKey {} pub struct VerifyKey {}
impl KeyGen<SigParams> for SigningKey { impl<'a> KeyGen<'a, SigParams> for SigningKey {
fn gen(params: SigParams) -> Self {} fn gen(params: SigParams, rand: &'a mut dyn RngCore) -> Self {
let sk_seed_bytes = params.salt_bytes as usize;
// Pick seed_sk at random
let mut seed_sk: Vec<u8> = vec![0; sk_seed_bytes];
rand.fill_bytes(&mut seed_sk);
// Derive seed_pk and O from seed_sk
let mut shake = Shake::v256();
let O_bytes = ((((params.n - params.o) as usize) * (params.o as usize)) + 1) / 2;
let mut S = vec![0; params.pk_seed_bytes as usize + O_bytes];
shake.squeeze(&mut S);
SigningKey { v: VerifyKey {} }
}
} }

View File

@ -1,5 +1,7 @@
pub trait KeyGen<P> { use rand::RngCore;
fn gen(params: P) -> Self;
pub trait KeyGen<'a, P> {
fn gen(params: P, rand: &'a mut dyn RngCore) -> Self;
} }
pub trait Signer<S> { pub trait Signer<S> {