Browse Source

Use cmz macro to create Lox creds

onyinyang 10 months ago
parent
commit
f1cf699987
3 changed files with 244 additions and 90 deletions
  1. 170 0
      Cargo.lock
  2. 3 0
      Cargo.toml
  3. 71 90
      src/lox_creds.rs

+ 170 - 0
Cargo.lock

@@ -2,6 +2,18 @@
 # It is not intended for manual editing.
 version = 4
 
+[[package]]
+name = "bitvec"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
+dependencies = [
+ "funty",
+ "radium",
+ "tap",
+ "wyz",
+]
+
 [[package]]
 name = "block-buffer"
 version = "0.10.4"
@@ -23,6 +35,27 @@ version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
+[[package]]
+name = "cmz"
+version = "0.1.0"
+source = "git+ssh://gogs@git-crysp.uwaterloo.ca/SigmaProtocol/cmz.git#f9759d4f0a10201d25ce05eff875b439f7f9d278"
+dependencies = [
+ "cmzcred_derive",
+ "curve25519-dalek",
+ "ff",
+ "group",
+]
+
+[[package]]
+name = "cmzcred_derive"
+version = "0.1.0"
+source = "git+ssh://gogs@git-crysp.uwaterloo.ca/SigmaProtocol/cmz.git#f9759d4f0a10201d25ce05eff875b439f7f9d278"
+dependencies = [
+ "darling",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "cpufeatures"
 version = "0.2.17"
@@ -53,10 +86,12 @@ dependencies = [
  "curve25519-dalek-derive",
  "digest",
  "fiat-crypto",
+ "group",
  "rand_core",
  "rustc_version",
  "serde",
  "subtle",
+ "zeroize",
 ]
 
 [[package]]
@@ -70,6 +105,41 @@ dependencies = [
  "syn",
 ]
 
+[[package]]
+name = "darling"
+version = "0.20.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989"
+dependencies = [
+ "darling_core",
+ "darling_macro",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.20.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim",
+ "syn",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.20.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
+dependencies = [
+ "darling_core",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "digest"
 version = "0.10.7"
@@ -80,12 +150,35 @@ dependencies = [
  "crypto-common",
 ]
 
+[[package]]
+name = "ff"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393"
+dependencies = [
+ "bitvec",
+ "rand_core",
+ "subtle",
+]
+
 [[package]]
 name = "fiat-crypto"
 version = "0.2.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
 
+[[package]]
+name = "fnv"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
+
+[[package]]
+name = "funty"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
+
 [[package]]
 name = "generic-array"
 version = "0.14.7"
@@ -107,6 +200,23 @@ dependencies = [
  "wasi",
 ]
 
+[[package]]
+name = "group"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
+dependencies = [
+ "ff",
+ "rand_core",
+ "subtle",
+]
+
+[[package]]
+name = "ident_case"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+
 [[package]]
 name = "lazy_static"
 version = "1.5.0"
@@ -123,13 +233,34 @@ checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
 name = "lox-extensions"
 version = "0.1.0"
 dependencies = [
+ "cmz",
  "curve25519-dalek",
+ "group",
  "lazy_static",
+ "phf",
  "rand",
  "serde",
  "sha2",
 ]
 
+[[package]]
+name = "phf"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12"
+dependencies = [
+ "phf_shared",
+]
+
+[[package]]
+name = "phf_shared"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7"
+dependencies = [
+ "siphasher",
+]
+
 [[package]]
 name = "ppv-lite86"
 version = "0.2.20"
@@ -157,6 +288,12 @@ dependencies = [
  "proc-macro2",
 ]
 
+[[package]]
+name = "radium"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
+
 [[package]]
 name = "rand"
 version = "0.8.5"
@@ -233,6 +370,18 @@ dependencies = [
  "digest",
 ]
 
+[[package]]
+name = "siphasher"
+version = "0.3.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
+
+[[package]]
+name = "strsim"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+
 [[package]]
 name = "subtle"
 version = "2.6.1"
@@ -250,6 +399,12 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "tap"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
+
 [[package]]
 name = "typenum"
 version = "1.17.0"
@@ -274,6 +429,15 @@ version = "0.11.0+wasi-snapshot-preview1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
 
+[[package]]
+name = "wyz"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
+dependencies = [
+ "tap",
+]
+
 [[package]]
 name = "zerocopy"
 version = "0.7.35"
@@ -294,3 +458,9 @@ dependencies = [
  "quote",
  "syn",
 ]
+
+[[package]]
+name = "zeroize"
+version = "1.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"

+ 3 - 0
Cargo.toml

@@ -9,3 +9,6 @@ lazy_static = "1.5.0"
 rand = {version = "0.8.0", features = ["std_rng"] }
 serde = "1.0.217"
 sha2 = "0.10.8"
+cmz = {git = "ssh://gogs@git-crysp.uwaterloo.ca/SigmaProtocol/cmz.git"}
+phf = "0.8.0"
+group = "0.13"

+ 71 - 90
src/lox_creds.rs

@@ -1,106 +1,87 @@
-/*! The various credentials used by the system.
+// The various credentials used by the system.
 
-In each case, (P,Q) forms the MAC on the credential. This MAC is
-verifiable only by the issuing party, or if the issuing party issues a
-zero-knowledge proof of its correctness (as it does at issuing time).*/
+use cmz::{CMZMac, CMZ};
+use curve25519_dalek::ristretto::RistrettoPoint as G;
+use group::Group;
 
-use curve25519_dalek::ristretto::RistrettoPoint;
-use curve25519_dalek::scalar::Scalar;
-use serde::{Deserialize, Serialize};
-
-/// A migration credential.
-///
-/// This credential authorizes the holder of the Lox credential with the
-/// given id to switch from bucket from_bucket to bucket to_bucket. The
-/// migration_type attribute is 0 for trust upgrade migrations (moving
-/// from a 1-bridge untrusted bucket to a 3-bridge trusted bucket) and 1
-/// for blockage migrations (moving buckets because the from_bucket has
-/// been blocked).
-#[derive(Debug, CMZ, Serialize, Deserialize)]
+// A migration credential.
+//
+// This credential authorizes the holder of the Lox credential with the
+// given id to switch from bucket from_bucket to bucket to_bucket. The
+// migration_type attribute is 0 for trust upgrade migrations (moving
+// from a 1-bridge untrusted bucket to a 3-bridge trusted bucket) and 1
+// for blockage migrations (moving buckets because the from_bucket has
+// been blocked).
 // Annotated to "M"
-pub struct Migration {
-    pub P: RistrettoPoint,
-    pub Q: RistrettoPoint,
-    pub lox_id: Scalar,
-    pub from_bucket: Scalar,
-    pub to_bucket: Scalar,
-    pub migration_type: Scalar,
+CMZ! { Migration<G>:
+    lox_id,
+    from_bucket,
+    to_bucket,
+    migration_type
 }
 
-/// The main user credential in the Lox system.
-///
-/// Its id is jointly generated by the user and the BA (bridge
-/// authority), but known only to the user. The level_since date is the
-/// Julian date of when this user was changed to the current trust
-/// level.
-#[derive(Debug, CMZ, Serialize, Deserialize)]
+// The main user credential in the Lox system.
+//
+// Its id is jointly generated by the user and the BA (bridge
+// authority), but known only to the user. The level_since date is the
+// Julian date of when this user was changed to the current trust
+// level.
 // Annotated to "L"
-pub struct Lox {
-    pub P: RistrettoPoint,
-    pub Q: RistrettoPoint,
-    pub id: Scalar,
-    pub bucket: Scalar,
-    pub trust_level: Scalar,
-    pub level_since: Scalar,
-    pub invites_remaining: Scalar,
-    pub blockages: Scalar,
+CMZ! { Lox:
+    id,
+    bucket,
+    trust_level,
+    level_since,
+    invites_remaining,
+    blockages
 }
 
-/// The migration key credential.
-///
-/// This credential is never actually instantiated. It is an implicit
-/// credential on attributes lox_id and from_bucket. This credential
-/// type does have an associated private and public key, however. The
-/// idea is that if a user proves (in zero knowledge) that their Lox
-/// credential entitles them to migrate from one bucket to another, the
-/// BA will issue a (blinded, so the BA will not know the values of the
-/// attributes or of Q) MAC on this implicit credential. The Q value
-/// will then be used (actually, a hash of lox_id, from_bucket, and Q)
-/// to encrypt the to_bucket, P, and Q fields of a Migration credential.
-/// That way, people entitled to migrate buckets can receive a Migration
-/// credential with their new bucket, without the BA learning either
-/// their old or new buckets.
-#[derive(Debug, CMZ, Serialize, Deserialize)]
+// The migration key credential.
+//
+// This credential is never actually instantiated. It is an implicit
+// credential on attributes lox_id and from_bucket. This credential
+// type does have an associated private and public key, however. The
+// idea is that if a user proves (in zero knowledge) that their Lox
+// credential entitles them to migrate from one bucket to another, the
+// BA will issue a (blinded, so the BA will not know the values of the
+// attributes or of Q) MAC on this implicit credential. The Q value
+// will then be used (actually, a hash of lox_id, from_bucket, and Q)
+// to encrypt the to_bucket, P, and Q fields of a Migration credential.
+// That way, people entitled to migrate buckets can receive a Migration
+// credential with their new bucket, without the BA learning either
+// their old or new buckets.
 // Annotated to "K"
-pub struct MigrationKey {
-    pub P: RistrettoPoint,
-    pub Q: RistrettoPoint,
-    pub lox_id: Scalar,
-    pub from_bucket: Scalar,
+CMZ! { MigrationKey:
+    lox_id,
+    from_bucket
 }
 
-/// The Bucket Reachability credential.
-///
-/// Each day, a credential of this type is put in each bucket that has
-/// at least a (configurable) threshold number of bridges that have not
-/// been blocked as of the given date. Users can present this
-/// credential (in zero knowledge) with today's date to prove that the
-/// bridges in their bucket have not been blocked, in order to gain a
-/// trust level.
+// The Bucket Reachability credential.
+//
+// Each day, a credential of this type is put in each bucket that has
+// at least a (configurable) threshold number of bridges that have not
+// been blocked as of the given date. Users can present this
+// credential (in zero knowledge) with today's date to prove that the
+// bridges in their bucket have not been blocked, in order to gain a
+// trust level.
 // Annotated to "B"
-#[derive(Debug, CMZ, Serialize, Deserialize)]
-pub struct BucketReachability {
-    pub P: RistrettoPoint,
-    pub Q: RistrettoPoint,
-    pub date: Scalar,
-    pub bucket: Scalar,
+CMZ! { BucketReachability:
+    date,
+    bucket
 }
 
-/// The Invitation credential.
-///
-/// These credentials allow a Lox user (the inviter) of sufficient trust
-/// (level 2 or higher) to invite someone else (the invitee) to join the
-/// system. The invitee ends up at trust level 1, in the _same bucket_
-/// as the inviter, and inherits the inviter's blockages count (so that
-/// you can't clear your blockages count simply by inviting yourself).
-/// Invitations expire after some amount of time.
-#[derive(Debug, CMZ, Serialize, Deserialize)]
+// The Invitation credential.
+//
+// These credentials allow a Lox user (the inviter) of sufficient trust
+// (level 2 or higher) to invite someone else (the invitee) to join the
+// system. The invitee ends up at trust level 1, in the _same bucket_
+// as the inviter, and inherits the inviter's blockages count (so that
+// you can't clear your blockages count simply by inviting yourself).
+// Invitations expire after some amount of time.
 // Annotated to "I"
-pub struct Invitation {
-    pub P: RistrettoPoint,
-    pub Q: RistrettoPoint,
-    pub inv_id: Scalar,
-    pub date: Scalar,
-    pub bucket: Scalar,
-    pub blockages: Scalar,
+CMZ! { Invitation:
+    inv_id,
+    date,
+    bucket,
+    blockages
 }