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

WIP: Generic ec #551

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ flamer = { version = "0.3", optional = true }
generic-array = "0.14"
hex = "0.4"
k256 = { version = "0.13", features = ["arithmetic", "sha256", "ecdsa", "serde"] }
generic-ec = { version = "0.4.2", features = ["curve-secp256k1"] }
lazy_static = "1"

# libpaillier depends on `unknown_order` which in turn depends on `rug`.
Expand Down
20 changes: 17 additions & 3 deletions src/presign/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ use crate::{
zkp::{
piaffg::{PiAffgInput, PiAffgProof, PiAffgSecret},
pienc::{PiEncInput, PiEncProof, PiEncSecret},
pilog::{CommonInput, PiLogProof, ProverSecret},
pilog::{CommonInput, PiLogProof, ProverSecret, SerdePoint},
Proof, ProofContext,
},
Identifier,
};
use generic_ec::curves::Secp256k1;
use libpaillier::unknown_order::BigNumber;
use merlin::Transcript;
use rand::{CryptoRng, RngCore};
Expand Down Expand Up @@ -1040,6 +1041,17 @@ impl PresignKeyShareAndInfo {

let g = CurvePoint::GENERATOR;
let Gamma = g.multiply_by_bignum(&sender_r1_priv.gamma)?;
// create SerdePoint from Gamma
//let serdeGamma = SerdePoint::<generic_ec::curves::Secp256k1> {
//point: generic_ec::curves::Secp256k1::point::from_bytes(Gamma.to_bytes()),
//point: <generic_ec_curves::rust_crypto::RustCryptoCurve<Secp256k1,
// ExpandMsgXmd<CoreWrapper<CtVariableCoreWrapper<Sha256VarCore,
// UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>,
// OidSha256>>>> as Example>::point::from_bytes(Gamma.to_bytes()),
//};
//let serdeGamma = SerdePoint::new(point_from_bytes(Gamma.to_bytes()));
let serdeGamma = SerdePoint::from_curve_point(Gamma);
let serdeg: SerdePoint<Secp256k1> = SerdePoint::from_curve_point(g);

// Generate the proofs.
let mut transcript = Transcript::new(b"PiAffgProof");
Expand Down Expand Up @@ -1081,7 +1093,7 @@ impl PresignKeyShareAndInfo {
let psi_prime = PiLogProof::prove(
CommonInput::new(
&sender_r1_priv.G,
&Gamma,
&serdeGamma,
receiver_aux_info.params().scheme(),
self.aux_info_public.pk(),
&g,
Expand Down Expand Up @@ -1166,6 +1178,8 @@ impl PresignKeyShareAndInfo {
}

let Delta = Gamma.multiply_by_bignum(&sender_r1_priv.k)?;
let serdeDelta = SerdePoint::from_curve_point(Delta);
let serdeGamma: SerdePoint<Secp256k1> = SerdePoint::from_curve_point(Gamma);

let delta_scalar = bn_to_scalar(&delta)?;
let chi_scalar = bn_to_scalar(&chi)?;
Expand All @@ -1176,7 +1190,7 @@ impl PresignKeyShareAndInfo {
let psi_double_prime = PiLogProof::prove(
CommonInput::new(
&sender_r1_priv.K,
&Delta,
&serdeDelta,
round_three_input.auxinfo_public.params().scheme(),
self.aux_info_public.pk(),
&Gamma,
Expand Down
8 changes: 5 additions & 3 deletions src/presign/round_three.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use crate::{
},
utils::CurvePoint,
zkp::{
pilog::{CommonInput, PiLogProof},
pilog::{CommonInput, PiLogProof, SerdePoint},
Proof,
},
};
use generic_ec::curves::Secp256k1;
use k256::{elliptic_curve::PrimeField, Scalar};
use libpaillier::unknown_order::BigNumber;
use merlin::Transcript;
Expand Down Expand Up @@ -65,7 +66,7 @@ impl Debug for Private {
pub(crate) struct Public {
pub delta: Scalar,
pub Delta: CurvePoint,
pub psi_double_prime: PiLogProof,
pub psi_double_prime: PiLogProof<Secp256k1>,
/// Gamma value included for convenience
pub Gamma: CurvePoint,
}
Expand All @@ -82,9 +83,10 @@ impl Public {
prover_r1_public_broadcast: &RoundOnePublicBroadcast,
) -> Result<()> {
let mut transcript = Transcript::new(b"PiLogProof");
let deltaSerde = SerdePoint::from_curve_point(self.Delta);
let psi_double_prime_input = CommonInput::new(
&prover_r1_public_broadcast.K,
&self.Delta,
&deltaSerde,
verifier_auxinfo_public.params().scheme(),
prover_auxinfo_public.pk(),
&self.Gamma,
Expand Down
8 changes: 5 additions & 3 deletions src/presign/round_two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use crate::{
utils::CurvePoint,
zkp::{
piaffg::{PiAffgInput, PiAffgProof},
pilog::{CommonInput, PiLogProof},
pilog::{CommonInput, PiLogProof, SerdePoint},
Proof,
},
};
use generic_ec::curves::Secp256k1;
use libpaillier::unknown_order::BigNumber;
use merlin::Transcript;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -59,7 +60,7 @@ pub(crate) struct Public {
pub Gamma: CurvePoint,
pub psi: PiAffgProof,
pub psi_hat: PiAffgProof,
pub psi_prime: PiLogProof,
pub psi_prime: PiLogProof<Secp256k1>,
}

impl Public {
Expand Down Expand Up @@ -106,9 +107,10 @@ impl Public {
.verify(psi_hat_input, context, &mut transcript)?;

// Verify the psi_prime proof
let Gamma = SerdePoint::from_curve_point(self.Gamma);
let psi_prime_input = CommonInput::new(
&prover_r1_public_broadcast.G,
&self.Gamma,
&Gamma,
verifier_auxinfo_public.params().scheme(),
prover_auxinfo_public.pk(),
&g,
Expand Down
10 changes: 10 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ impl AsRef<CurvePoint> for CurvePoint {
}

impl CurvePoint {
// new
pub fn new(value: k256::ProjectivePoint) -> Self {
Self(value)
}

// return the wrapped point
pub fn inner_value(&self) -> k256::ProjectivePoint {
self.0
}

pub fn x_affine(&self) -> FieldBytes {
self.0.to_affine().x()
}
Expand Down
Loading
Loading