Skip to content

Commit

Permalink
Merge pull request #2 from Cybersecurity-LINKS/test
Browse files Browse the repository at this point in the history
removed some comments
  • Loading branch information
AlbertoSvg authored Oct 24, 2023
2 parents 62d80bc + 822a669 commit d965bc1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 188 deletions.
90 changes: 1 addition & 89 deletions src/keys/bbsplus_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,92 +60,4 @@ impl BBSplusSecretKey{

Self(s)
}
}



// #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
// pub struct BBSplusKeyPair{
// private: BBSplusSecretKey,
// public: BBSplusPublicKey
// }

// impl BBSplusKeyPair {
// pub fn new(private: BBSplusSecretKey, public: BBSplusPublicKey) -> Self {
// Self{private, public}
// }

// pub fn public(&self) -> &BBSplusPublicKey{
// &self.public
// }

// pub fn private(&self) -> &BBSplusSecretKey{
// &self.private
// }



// pub fn generate_rng<R: RngCore>(rng: &mut R) -> Self {
// let sk = Scalar::random(rng);
// let pk: G2Projective = G2Affine::generator() * sk;
// // BBSplusKeyPair::new(BBSplusSecretKey(sk), BBSplusPublicKey(pk))

// Self{public: BBSplusPublicKey(pk), private: BBSplusSecretKey(sk)}
// }

// pub fn generate<T>(ikm: T, key_info: Option<&[u8]>) -> Self
// where
// T: AsRef<[u8]>
// {
// let ikm = ikm.as_ref();
// let key_info = key_info.unwrap_or(&[]);
// let init_salt = "BBS-SIG-KEYGEN-SALT-".as_bytes();

// // if ikm.len() < 32 {
// // return Err(BadParams {
// // cause: format!("Invalid ikm length. Needs to be at least 32 bytes long. Got {}", ikm.len())
// // })
// // }

// // L = ceil((3 * ceil(log2(r))) / 16)
// const L: usize = 48;
// const L_BYTES: [u8; 2] = (L as u16).to_be_bytes();

// // salt = H(salt)
// let mut hasher = Sha256::new();
// hasher.update(init_salt);
// let salt = hasher.finalize();

// // PRK = HKDF-Extract(salt, IKM || I2OSP(0, 1))
// let prk = Hkdf::<Sha256>::new(
// Some(&salt),
// &[ikm, &[0u8; 1][..]].concat()
// );

// // OKM = HKDF-Expand(PRK, key_info || I2OSP(L, 2), L)
// let mut okm = [0u8; 64];

// prk.expand(
// &[&key_info, &L_BYTES[..]].concat(),
// &mut okm[(64-L)..]
// ).expect(
// &format!("The HKDF-expand output cannot be more than {} bytes long", 255 * Sha256::output_size())
// );

// okm.reverse(); // okm is in be format
// let sk = Scalar::from_bytes_wide(&okm);
// let pk: G2Projective = G2Affine::generator() * sk;
// // let pk_affine = pk.to_affine();

// // // transform secret key from le to be
// // let mut sk_bytes = sk.to_bytes();
// // sk_bytes.reverse();

// // BBSplusKeyPair::new(BBSplusSecretKey(sk), BBSplusPublicKey(pk))

// Self{public: BBSplusPublicKey(pk), private: BBSplusSecretKey(sk)}
// }
// }



}
73 changes: 0 additions & 73 deletions src/keys/cl03_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,76 +185,3 @@ impl CL03CommitmentPublicKey {
CL03CommitmentPublicKey{N: N, h: h, g_bases: g_bases}
}
}

// #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
// pub struct CL03KeyPair {
// private: CL03SecretKey,
// public: CL03PublicKey
// }



// impl CL03KeyPair{

// pub fn new(private: CL03SecretKey, public: CL03PublicKey) -> Self{
// Self{private, public}
// }

// pub fn private(&self) -> &CL03SecretKey{
// &self.private
// }

// pub fn public(&self) -> &CL03PublicKey{
// &self.public
// }

// pub fn generate() -> Self {
// let n = 512; //SECPARAM
// let mut pprime = random_prime(n);
// let mut p = Integer::from(2) * pprime.clone() + Integer::from(1);
// loop{
// // println!("{} INT", p);
// // let digits = p.to_digits::<u8>(Order::MsfBe);
// // let bignum = BigUint::from_bytes_be(&digits);
// // println!("{} BIGNUM", bignum);
// if p.is_probably_prime(50) !=IsPrime::No {
// break;
// }
// pprime = random_prime(n);
// p = Integer::from(2) * pprime + Integer::from(1);
// }

// let mut qprime = random_prime(n);
// let mut q = Integer::from(2) * qprime.clone() + Integer::from(1);
// loop{
// // println!("{} INT", p);
// // let digits = p.to_digits::<u8>(Order::MsfBe);
// // let bignum = BigUint::from_bytes_be(&digits);
// // println!("{} BIGNUM", bignum);
// if p != q && q.is_probably_prime(100) !=IsPrime::No {
// break;
// }
// qprime = random_prime(n);
// q = Integer::from(2) * qprime + Integer::from(1);
// }

// let N = p.clone() * q.clone();

// let mut a_bases: Vec<Integer> = Vec::new();
// let a0 = random_qr(&N);

// a_bases.push(a0);

// let b = random_qr(&N);
// let c = random_qr(&N);

// let pk = CL03PublicKey::new(N, b, c, a_bases);
// let sk = CL03SecretKey::new(p, q);

// //let pair = CL03KeyPair::new(sk, pk);
// Self{public: pk, private: sk }
// // Self{public: PublicKey::new(PublicKeyData::CL03(pk)), private: PrivateKey::new(PrivateKeyData::CL03(sk)), p: PhantomData}

// }
// }

3 changes: 0 additions & 3 deletions src/keys/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,11 @@ impl <CS: BbsCiphersuite> KeyPair<BBSplus<CS>>{
pub fn generate_rng<R: RngCore>(rng: &mut R) -> Self {
let sk = Scalar::random(rng);
let pk: G2Projective = G2Affine::generator() * sk;
// BBSplusKeyPair::new(BBSplusSecretKey(sk), BBSplusPublicKey(pk))

Self{public: BBSplusPublicKey(pk), private: BBSplusSecretKey(sk)}
}

pub fn generate(ikm: Option<&[u8]>, key_info: Option<&[u8]>) -> Self
// where
// T: AsRef<[u8]>
{

let ikm = if let Some(ikm_data) = ikm {
Expand Down
23 changes: 0 additions & 23 deletions src/signatures/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,33 +227,10 @@ impl <CS: BbsCiphersuite> Signature<BBSplus<CS>> {
}

pub fn to_bytes(&self) -> [u8; 112] {
// let mut bytes = [0u8; 112];
// bytes[0..48].copy_from_slice(&self.a().to_affine().to_compressed());
// let e = self.e().to_be_bytes();
// // e.reverse();
// bytes[48..80].copy_from_slice(&e[..]);
// let s = self.s().to_be_bytes();
// // s.reverse();
// bytes[80..112].copy_from_slice(&s[..]);
// bytes

self.bbsPlusSignature().to_bytes()
}

pub fn from_bytes(data: &[u8; 112]) -> Self {
// let aa = G1Affine::from_compressed(&<[u8; 48]>::try_from(&data[0..48]).unwrap())
// .map(G1Projective::from);
// let e_bytes = <[u8; 32]>::try_from(&data[48..80]).unwrap();
// // e_bytes.reverse();
// let ee = Scalar::from_be_bytes(&e_bytes);
// let s_bytes = <[u8; 32]>::try_from(&data[80..112]).unwrap();
// // s_bytes.reverse();
// let ss = Scalar::from_be_bytes(&s_bytes);

// aa.and_then(|a| {
// ee.and_then(|e| ss.and_then(|s| CtOption::new(Self::BBSplus(BBSplusSignature{ a, e, s }), Choice::from(1))))
// })

Self::BBSplus(BBSplusSignature::from_bytes(data).unwrap())
}
}
Expand Down

0 comments on commit d965bc1

Please sign in to comment.