Forráskód Böngészése

The Credential struct need not have a hardcoded number of attributes

Ian Goldberg 4 éve
szülő
commit
f2bb30d9a7
1 módosított fájl, 25 hozzáadás és 32 törlés
  1. 25 32
      src/ggm.rs

+ 25 - 32
src/ggm.rs

@@ -93,14 +93,13 @@ impl Issuer {
 }
 
 #[derive(Debug)]
-pub struct Credential5 {
+pub struct Credential {
     P: RistrettoPoint,
     Q: RistrettoPoint,
-    m1: Scalar,
-    m2: Scalar,
-    m3: Scalar,
-    m4: Scalar,
-    m5: Scalar,
+    // For numbering consistency with the Hyphae paper, the attributes
+    // are stored in m[1], m[2], ... ; the m[0] element is set to the
+    // dummy value 0.
+    m: Vec<Scalar>,
 }
 
 // A submodule for issuing credentials with 5 attributes, none of which
@@ -115,7 +114,7 @@ pub mod issue_nonblind_5 {
     use zkp::ProofError;
     use zkp::Transcript;
 
-    use super::{CMZ_A,CMZ_B,CMZ_B_TABLE,Issuer,IssuerPubKey,Credential5};
+    use super::{CMZ_A,CMZ_B,CMZ_B_TABLE,Issuer,IssuerPubKey,Credential};
 
     #[derive(Debug)]
     pub struct CredentialRequest {
@@ -234,7 +233,7 @@ pub mod issue_nonblind_5 {
 
     pub fn verify(state: CredentialRequestState,
             resp: CredentialResponse, pubkey: &IssuerPubKey)
-            -> Result<Credential5, ProofError> {
+            -> Result<Credential, ProofError> {
         let A : &RistrettoPoint = &CMZ_A;
         let B : &RistrettoPoint = &CMZ_B;
 
@@ -263,14 +262,11 @@ pub mod issue_nonblind_5 {
                 P5: &(&state.m5 * &resp.P).compress(),
             }
         )?;
-        Ok(Credential5 {
+        Ok(Credential {
             P: resp.P,
             Q: resp.Q,
-            m1: state.m1,
-            m2: state.m2,
-            m3: state.m3,
-            m4: state.m4,
-            m5: state.m5,
+            m: vec![Scalar::zero(), state.m1, state.m2,
+                    state.m3, state.m4, state.m5],
         })
     }
 }
@@ -296,7 +292,7 @@ pub mod issue_blind124_5 {
     use zkp::Transcript;
 
     use super::{CMZ_A,CMZ_B,CMZ_A_TABLE,CMZ_B_TABLE};
-    use super::{Issuer,IssuerPubKey,Credential5};
+    use super::{Issuer,IssuerPubKey,Credential};
 
     // Example of a 5-attribute credential where the issuer sees attributes
     // 3 and 5, but attributes 1, 2, and 4 are blinded.
@@ -538,7 +534,7 @@ pub mod issue_blind124_5 {
 
     pub fn verify(state: CredentialRequestState,
             resp: CredentialResponse, pubkey: &IssuerPubKey)
-            -> Result<Credential5, ProofError> {
+            -> Result<Credential, ProofError> {
         let A : &RistrettoPoint = &CMZ_A;
         let B : &RistrettoPoint = &CMZ_B;
 
@@ -580,14 +576,11 @@ pub mod issue_blind124_5 {
         // Decrypt EncQ
         let Q = &resp.EncQ.1 - (state.d * &resp.EncQ.0);
 
-        Ok(Credential5 {
+        Ok(Credential {
             P: resp.P,
             Q: Q,
-            m1: state.m1,
-            m2: state.m2,
-            m3: state.m3,
-            m4: state.m4,
-            m5: state.m5,
+            m: vec![Scalar::zero(), state.m1, state.m2,
+                    state.m3, state.m4, state.m5],
         })
     }
 }
@@ -604,7 +597,7 @@ pub mod show_blind345_5 {
     use zkp::ProofError;
     use zkp::Transcript;
 
-    use super::{CMZ_A,CMZ_A_TABLE,Issuer,IssuerPubKey,Credential5};
+    use super::{CMZ_A,CMZ_A_TABLE,Issuer,IssuerPubKey,Credential};
 
     // A typo in the Hyphae paper (Section 4.4): P must also be sent to
     // the issuer in the credential presentation message.
@@ -644,7 +637,7 @@ pub mod show_blind345_5 {
         V = (z3*X3 + z4*X4 + z5*X5 + negzQ*A)
     }
 
-    pub fn show(cred: &Credential5, pubkey: &IssuerPubKey)
+    pub fn show(cred: &Credential, pubkey: &IssuerPubKey)
             -> ShowMessage {
         let A : &RistrettoPoint = &CMZ_A;
         let Atable : &RistrettoBasepointTable = &CMZ_A_TABLE;
@@ -659,9 +652,9 @@ pub mod show_blind345_5 {
         let z3: Scalar = Scalar::random(&mut rng);
         let z4: Scalar = Scalar::random(&mut rng);
         let z5: Scalar = Scalar::random(&mut rng);
-        let Cm3: RistrettoPoint = &cred.m3 * &P + &z3 * Atable;
-        let Cm4: RistrettoPoint = &cred.m4 * &P + &z4 * Atable;
-        let Cm5: RistrettoPoint = &cred.m5 * &P + &z5 * Atable;
+        let Cm3: RistrettoPoint = &cred.m[3] * &P + &z3 * Atable;
+        let Cm4: RistrettoPoint = &cred.m[4] * &P + &z4 * Atable;
+        let Cm5: RistrettoPoint = &cred.m[5] * &P + &z5 * Atable;
 
         // Form a Pedersen commitment to the MAC Q
         // We flip the sign of zQ from that of the Hyphae paper so that
@@ -689,9 +682,9 @@ pub mod show_blind345_5 {
                 X3: &pubkey.X[3],
                 X4: &pubkey.X[4],
                 X5: &pubkey.X[5],
-                m3: &cred.m3,
-                m4: &cred.m4,
-                m5: &cred.m5,
+                m3: &cred.m[3],
+                m4: &cred.m[4],
+                m5: &cred.m[5],
                 z3: &z3,
                 z4: &z4,
                 z5: &z5,
@@ -700,8 +693,8 @@ pub mod show_blind345_5 {
 
         ShowMessage {
             P,
-            m1: cred.m1,
-            m2: cred.m2,
+            m1: cred.m[1],
+            m2: cred.m[2],
             Cm3, Cm4, Cm5, CQ, piCredShow
         }
     }