From 651bd08065a08ba0619ffe4a1c1303bae088eadf Mon Sep 17 00:00:00 2001 From: "J. Ayo Akinyele" Date: Sun, 6 May 2018 21:50:37 -0400 Subject: [PATCH] more updates --- .idea/libraries/Cargo__libbolt_.xml | 35 --------------- .idea/vcs.xml | 6 --- docs/bolt_design.tex | 11 ++--- src/clsigs.rs | 11 +++++ src/lib.rs | 70 ++++++++++++++++++++++++++++- 5 files changed, 85 insertions(+), 48 deletions(-) delete mode 100644 .idea/libraries/Cargo__libbolt_.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/libraries/Cargo__libbolt_.xml b/.idea/libraries/Cargo__libbolt_.xml deleted file mode 100644 index d3fb7a5..0000000 --- a/.idea/libraries/Cargo__libbolt_.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/docs/bolt_design.tex b/docs/bolt_design.tex index ebc6673..9d392c2 100644 --- a/docs/bolt_design.tex +++ b/docs/bolt_design.tex @@ -259,7 +259,7 @@ The unidirectional payment construction only supports payments from a customer t \item ${\sf Setup}(1^\lambda) \rightarrow {\sf PP}$. On input $\lambda$, optionally generate CRS parameters for (1) a secure commitment scheme (see Section~\ref{sec:commit}), (2) a non-interactive zero knowledge proof system (see Section~\ref{sec:nizkp}). Output all of these as ${\sf PP}$. % Key generation description -${\sf KeyGen}({\sf PP}) \rightarrow (pk, sk)$. +\item ${\sf KeyGen}({\sf PP}) \rightarrow (pk, sk)$. \begin{itemize} \item Compute $(pk, sk) \leftarrow \prod_{\sf sig}.{\sf SigKeygen}(1^\lambda)$. %Note that $pk$ can be derived from the $sk$. \end{itemize} @@ -275,7 +275,7 @@ ${\sf KeyGen}({\sf PP}) \rightarrow (pk, sk)$. \end{itemize} % Init algorithm description -${\sf Init_{M}}({\sf PP}, \BC, \BM, pk_m, sk_m) \rightarrow {\sf T}_m, csk_m$. On input a keypair $(pk_m, sk_m)$, perform the following: +\item ${\sf Init_{M}}({\sf PP}, \BC, \BM, pk_m, sk_m) \rightarrow {\sf T}_m, csk_m$. On input a keypair $(pk_m, sk_m)$, perform the following: \begin{itemize} \item Output ${\sf T}_m = pk_m$ and $csk_m = (sk_m, \BM)$. @@ -396,11 +396,12 @@ The bidirectional payment construction enables compact closure and compact walle \item ${\sf Setup}(1^\lambda) \rightarrow {\sf PP}$. On input $\lambda$, optionally generate CRS parameters for (1) a secure commitment scheme (see Section~\ref{sec:commit}), (2) a non-interactive zero knowledge proof system (see Section~\ref{sec:nizkp}). Output all of these as ${\sf PP}$. % Key generation description -${\sf KeyGen}({\sf PP}) \rightarrow (pk, sk)$. +\item ${\sf KeyGen}({\sf PP}) \rightarrow (pk, sk)$. \begin{itemize} \item Compute $(pk, sk) \leftarrow \prod_{\sf sig}.{\sf SigKeygen}(1^\lambda)$. %Note that $pk$ can be derived from the $sk$. \end{itemize} +% Init algorithm for customer \medskip \noindent \item ${\sf Init_{C}}({\sf PP}, {\sf cID}, \BC, \BM, pk_c, sk_c) \rightarrow ({\sf T}_{C}, csk_{C})$. On input a keypair $(pk_c, sk_c)$, perform the following: @@ -412,8 +413,8 @@ ${\sf KeyGen}({\sf PP}) \rightarrow (pk, sk)$. \item Output ${\sf T}_c = ({\sf wCom}, pk_c)$ and $csk_c = (sk_c, {\sf cID}, wpk, wsk, r, \BC)$. \end{itemize} -% Init algorithm description -${\sf Init_{M}}({\sf PP}, \BC, \BM, pk_m, sk_m) \rightarrow {\sf T}_m, csk_m$. On input a keypair $(pk_m, sk_m)$, perform the following: +% Init algorithm description for merchant +\item ${\sf Init_{M}}({\sf PP}, \BC, \BM, pk_m, sk_m) \rightarrow {\sf T}_m, csk_m$. On input a keypair $(pk_m, sk_m)$, perform the following: \begin{itemize} \item Output ${\sf T}_m = pk_m$ and $csk_m = (sk_m, \BM)$. diff --git a/src/clsigs.rs b/src/clsigs.rs index e426b42..d382922 100644 --- a/src/clsigs.rs +++ b/src/clsigs.rs @@ -125,3 +125,14 @@ pub fn verify(mpk: &PublicParams, pk: &PublicKey, m: Fr, sig: &Signature) -> boo let rhs2 = pairing(mpk.g, sig.c); return (lhs1 == rhs1) && (lhs2 == rhs2); } + +pub fn gen_blind(sig: &Signature) -> Signature { + let rng = &mut rand::thread_rng(); + let r = Fr::random(rng); + let r1 = Fr::random(rng); + let a = sig.a * r; + let b = sig.b * r; + let c = (sig.c * r) * r1; + let bsig = Signature { a: a, b: b, c:c }; + return bsig; +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 13b3e2d..d90d4c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -444,6 +444,7 @@ pub fn print(g: &G1) -> String { ////////////////////////////////// CL Sigs ///////////////////////////////////// +// refund message #[derive(Clone)] pub struct RefundMessage<'a> { prefix: &'a str, // string prefix for the prefix @@ -485,6 +486,32 @@ impl<'a> RefundMessage<'a> { } } +// spend message +#[derive(Clone)] +pub struct SpendMessage<'a> { + prefix: &'a str, + j: i32, + s: G1, + u: G1, + pi: Proof, + ck: SymKey +} + +impl<'a> SpendMessage<'a> { + pub fn new(_j: i32, _s: G1, _u: G1, _pi: Proof, _ck: SymKey) -> SpendMessage<'a> { + SpendMessage { + prefix: "spend", j: _j, s: _s, u: _u, pi: _pi, ck: _ck, + } + } + + pub fn hash(&self) -> Fr { + // hash into a Fr element + } +} + +// coin message + + ////////////////////////////////// CL Sigs ///////////////////////////////////// ////////////////////////////////// COMMITMENT ////////////////////////////////// @@ -535,6 +562,42 @@ impl Message { ////////////////////////////////// COMMITMENT ////////////////////////////////// +////////////////////////////////// NIZKP ////////////////////////////////// + +#[derive(Copy, Clone)] +pub struct Proof { + T: G1, + c: Fr, + s1: Fr, + s2: Fr +} + +pub fn hash(g: &G1, h: &G1, X: &G1, Y: &G1, ) -> Fr { + let g_vec: Vec = encode(&g, Infinite).unwrap(); + +} + +pub fn create_nizk_proof_one(pp: &PublicParams, pk: &PublicKey, sk: &SecretKey) -> Proof { + let rng = &mut rand::thread_rng(); + + let t1 = Fr::random(rng); + let t2 = Fr::random(rng); + + let T = (pk.g * t1) + (pk.h * t2); + + let c = hash(pp.g, pp.h, pk.X, pk.Y, T); + + let s1 = (sk.x * c) + t1; + let s2 = (sk.y * c) + t2; + + return Proof { T: T, c: c, s1: s1, s2: s2 }; +} + +pub fn verify_nizk_proof_one(proof: &Proof) -> bool { + // how do we verify the proof? +} +////////////////////////////////// NIZKP ////////////////////////////////// + pub mod unidirectional { use std::fmt; use rand; @@ -628,16 +691,19 @@ pub mod unidirectional { } // TODO: requires NIZK proof system - pub fn establish_customer_send(pp: &PublicParams, t_m: &clsigs::PublicKey, csk_c: &CustSecretKey) { + pub fn establish_customer(pp: &PublicParams, t_m: &clsigs::PublicKey, csk_c: &CustSecretKey) { println ! ("Run establish_customer algorithm..."); // set sk_0 to random bytes of length l // let sk_0 = random_bytes(pp.l); let buf_len: usize = pp.l_bits as usize; let mut sk0 = vec![0; buf_len]; randombytes::randombytes_into(&mut sk0); + + let pi1 = create_nizk_proof_one(csk_c.sk, csk_c.k1, csk_c.k2, ); } - pub fn estalibsh_mercahnt_send() { + // the merchant calls this method after obtaining + pub fn estalibsh_merchant() { }