Просмотр исходного кода

Fix up lox_creds and update cmz import

onyinyang 1 неделя назад
Родитель
Сommit
bc1c547979
5 измененных файлов с 46 добавлено и 29 удалено
  1. 1 25
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 19 0
      src/lib.rs
  4. 4 3
      src/lox_creds.rs
  5. 21 0
      src/proto/errors.rs

+ 1 - 25
Cargo.lock

@@ -237,28 +237,10 @@ dependencies = [
  "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",
+ "subtle",
 ]
 
 [[package]]
@@ -370,12 +352,6 @@ 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"

+ 1 - 1
Cargo.toml

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

+ 19 - 0
src/lib.rs

@@ -0,0 +1,19 @@
+use curve25519_dalek::scalar::Scalar;
+use subtle::ConstantTimeEq;
+
+pub mod lox_creds;
+pub mod proto {
+    pub mod errors;
+}
+
+// Try to extract a u32 from a Scalar
+pub fn scalar_u32(s: &Scalar) -> Option<u32> {
+    // Check that the top 28 bytes of the Scalar are 0
+    let sbytes: &[u8; 32] = s.as_bytes();
+    if sbytes[4..].ct_eq(&[0u8; 28]).unwrap_u8() == 0 {
+        return None;
+    }
+    Some(u32::from_le_bytes(sbytes[..4].try_into().unwrap()))
+}
+
+//pub mod open_invite;

+ 4 - 3
src/lox_creds.rs

@@ -1,8 +1,9 @@
 // The various credentials used by the system.
 
-use cmz::{CMZMac, CMZ};
+use cmz::*;
 use curve25519_dalek::ristretto::RistrettoPoint as G;
-use group::Group;
+use group::{ff, Group};
+use rand::RngCore;
 
 // A migration credential.
 //
@@ -13,7 +14,7 @@ use group::Group;
 // for blockage migrations (moving buckets because the from_bucket has
 // been blocked).
 // Annotated to "M"
-CMZ! { Migration<G>:
+CMZ! { Migration:
     lox_id,
     from_bucket,
     to_bucket,

+ 21 - 0
src/proto/errors.rs

@@ -0,0 +1,21 @@
+use thiserror::Error;
+
+/// This error is thrown if the number of buckets/keys in the bridge table
+/// exceeds u32 MAX.It is unlikely this error will ever occur.
+#[derive(Error, Debug)]
+pub enum CredentialError {
+    #[error("time threshold for operation will not be met for {0} more days")]
+    TimeThresholdNotMet(u32),
+    #[error("credential has expired")]
+    CredentialExpired,
+    #[error("invalid field {0}: {1}")]
+    InvalidField(String, String),
+    #[error("exceeded blockages threshold")]
+    ExceededBlockagesThreshold,
+    #[error("credential has no available invitations")]
+    NoInvitationsRemaining,
+    #[error("supplied credentials do not match")]
+    CredentialMismatch,
+    #[error("CMZ Error")]
+    CMZError(cmz::CMZError),
+}