Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/t218 bls sig arkworks #223

Merged
merged 25 commits into from
Apr 5, 2023
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5dc6d75
Skeleton of code compiling
philippecamacho Mar 29, 2023
dd40098
Fix type errors
philippecamacho Mar 29, 2023
c7b36f7
Merge branch 'main' into feat/t218-bls-sig-arkworks
philippecamacho Mar 29, 2023
c566707
Fix trait errors
philippecamacho Mar 29, 2023
17c4ab5
Key pair generation
philippecamacho Mar 29, 2023
52b45ef
Fix clippy error.
philippecamacho Mar 29, 2023
ff4ecbc
Sketch for hash to curve.
philippecamacho Mar 30, 2023
2ba50b4
Remove type parameter P:Pairing.
philippecamacho Mar 31, 2023
d25d39d
Revert "Remove type parameter P:Pairing."
philippecamacho Apr 3, 2023
6f86ed3
Revert "Revert "Remove type parameter P:Pairing.""
philippecamacho Apr 3, 2023
5192c55
First version of hash and pray function for Bn254 curve.
philippecamacho Apr 3, 2023
b9f6038
Signature trait tests passing.
philippecamacho Apr 3, 2023
b53f097
Take into account the algorithm id
philippecamacho Apr 3, 2023
c16c1d8
Remove commented code.
philippecamacho Apr 3, 2023
9ca2f68
Fix ID of signature algorithm.
philippecamacho Apr 3, 2023
5160bea
Serde tests
philippecamacho Apr 3, 2023
203af5e
Parametrize `hash_to_curve` with the hash function for mapping bytes …
philippecamacho Apr 4, 2023
ba4825b
Add some comments / todos.
philippecamacho Apr 4, 2023
af922fe
Document hash_to_curve function.
philippecamacho Apr 4, 2023
4491b3c
Misc improvements, renaming.
philippecamacho Apr 4, 2023
60df9d0
Merge branch 'main' into feat/t218-bls-sig-arkworks
philippecamacho Apr 4, 2023
18f5243
Add `Copy` trait to `VerKey` and remove superfluous use of `clone()`.
philippecamacho Apr 5, 2023
bc53944
Simplify code for computing initial field element x.
philippecamacho Apr 5, 2023
ac95111
Better ciphersuite identifier for BLS signature scheme over BN254 curve.
philippecamacho Apr 5, 2023
a07c229
Test for long messages.
philippecamacho Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Key pair generation
philippecamacho committed Mar 29, 2023
commit 17c4ab5109150c5e95ace2062816b9414fcf2494
66 changes: 17 additions & 49 deletions primitives/src/signatures/bls_arkwors.rs
Original file line number Diff line number Diff line change
@@ -214,6 +214,7 @@ pub struct KeyPair<P>
where
P: Pairing,
{
phantom: PhantomData<P>,
sk: SignKey<P>,
vk: VerKey<P>,
}
@@ -274,20 +275,28 @@ where

impl<P> KeyPair<P>
where
P: Pairing + Default,
P: Pairing,
{
/// Key-pair generation algorithm
pub fn generate<R: Rng>(prng: &mut R) -> KeyPair<P> {
let sk = SignKey::generate(prng);
let vk = VerKey::from(&sk);
KeyPair { sk, vk }
KeyPair {
phantom: Default::default(),
sk,
vk,
}
}

/// Key pair generation using a particular sign key secret `sk`
pub fn generate_with_sign_key(sk: P::ScalarField) -> Self {
let sk = SignKey(sk);
let vk = VerKey::from(&sk);
KeyPair { sk, vk }
KeyPair {
phantom: Default::default(),
sk,
vk,
}
}

/// Get reference to verification key
@@ -321,18 +330,6 @@ impl<P: Pairing> SignKey<P> {
}
}

// impl<P> From<&SignKey<P::Fp>> for VerKey<P>
// where
// P: Config,
// {
// fn from(
// sk: &SignKey<P::Fp>) -> Self {
// // TODO
// // VerKey(G2Projective::<P>::generator().clone() * sk.0.clone())
// VerKey(G2Projective::<P>::generator() * sk.0)
// }
// }

impl<P> From<&SignKey<P>> for VerKey<P>
where
P: Pairing,
@@ -364,44 +361,15 @@ where
}
}

// impl<P> VerKey<P>
// where
// P: Config<BaseField = F>,
// {
// // TODO: this function should be generic w.r.t. hash functions
// // Fixme after the hash-api PR is merged.
// #[allow(non_snake_case)]
// fn challenge<B: AsRef<[u8]>>(&self, R: &Projective<P>, msg: &[F], csid:
// B) -> P::ScalarField { // is the domain separator always an Fr? If so
// how about using Fr as domain // separator rather than bytes?
// let instance_description = F::from_be_bytes_mod_order(csid.as_ref());
// let mut challenge_input = {
// let vk_affine = self.0.into_affine();
// let R_affine = R.into_affine();
// vec![
// instance_description,
// vk_affine.x,
// vk_affine.y,
// R_affine.x,
// R_affine.y,
// ]
// };
// challenge_input.extend(msg);
// let challenge_fq = VariableLengthRescueCRHF::<F,
// 1>::evaluate(challenge_input).unwrap()[0]; // safe unwrap
//
// // this masking will drop the last byte, and the resulting
// // challenge will be 248 bits
// fq_to_fr_with_mask(&challenge_fq)
// }
// }

#[cfg(test)]
mod tests {
use crate::signatures::bls_arkwors::KeyPair;
use ark_bn254::Bn254;

#[test]
fn test() {
assert!(true);
fn test_bls_signature() {
let mut rng = jf_utils::test_rng();
let _key_pair = KeyPair::<Bn254>::generate(&mut rng);
}

// use super::*;