Skip to content

Commit

Permalink
Merge anonymous-credentials cxx/lib crates
Browse files Browse the repository at this point in the history
  • Loading branch information
DJAndries committed Sep 17, 2024
1 parent 8d4144d commit 95da73e
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 127 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
import("//build/rust/rust_static_library.gni")

rust_static_library("rust_lib") {
crate_name = "anonymous_credentials_cxx"
crate_name = "anonymous_credentials"
crate_root = "src/lib.rs"
allow_unsafe = true

edition = "2021"
sources = [ "src/lib.rs" ]
sources = [
"src/data.rs",
"src/join.rs",
"src/lib.rs",
"src/manager.rs",
"src/sign.rs",
"src/util.rs",
]

visibility = [ "//brave/components/web_discovery/browser:*" ]

cxx_bindings = [ "src/lib.rs" ]

deps = [ "//brave/components/web_discovery/browser/anonymous_credentials/rs/lib:rust_lib" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ edition = "2021"
authors = ["Darnell Andries <dandries@brave.com>"]
description = "Implementation of Direct Anonymous Attestation for the Web Discovery Project"
license = "MPL-2.0"
repository = "https://github.com/brave-experiments/anonymous-credentials-rs"
keywords = ["daa", "credentials", "bn254"]
categories = ["cryptography"]

[dependencies]
cxx = "1"
lazy_static = "1.4"
rand = "0.8"
brave-miracl = { version = "0.1", features = ["std"] }
thiserror = "1.0"

[dev-dependencies]
hex = "0.4"

[lib]
name = "anonymous_credentials"
crate-type = ["rlib"]
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# anonymous-credentials

[![Crates.io](https://img.shields.io/crates/v/anonymous-credentials?style=for-the-badge)](https://crates.io/crates/anonymous-credentials)

Partial implementation of Direct Anonymous Attestation (DAA) for the Web Discovery Project. Only signer functions are available. Performs the same elliptic curve operations as the [original C library](https://github.com/whotracksme/anonymous-credentials).

bn254 is the only supported curve for this library.

## License

This project is licensed under the terms of the [Mozilla Public License 2.0](LICENSE).
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

use anonymous_credentials::{
CredentialBIG as InternalCredentialBIG, CredentialManager as InternalCredentialManager,
GroupPublicKey as InternalGroupPublicKey, JoinResponse as InternalJoinResponse, Result,
UserCredentials as InternalUserCredentials,
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

//! Partial implementation of Direct Anonymous Attestation (DAA) for the Web Discovery Project.
//! Only signer functions are available. Performs the same elliptic curve operations as the [original C library](https://github.com/whotracksme/anonymous-credentials).
//!
//! bn254 is the only supported curve for this library.

mod data;
mod join;
mod manager;
mod sign;
mod util;

use crate::data::{
BIG_SIZE, ECP2_COMPAT_SIZE, ECP_PROOF_SIZE, ECP_SIZE, GROUP_PUBLIC_KEY_SIZE,
JOIN_RESPONSE_SIZE, USER_CREDENTIALS_SIZE,
};
use thiserror::Error;

use crate::data::{
CredentialBIG as InternalCredentialBIG, GroupPublicKey as InternalGroupPublicKey,
JoinResponse as InternalJoinResponse, UserCredentials as InternalUserCredentials,
};
use crate::manager::CredentialManager as InternalCredentialManager;

#[derive(Error, Debug)]
pub enum CredentialError {
#[error("ECP should be {0} bytes", ECP_SIZE)]
BadECP,
#[error("ECP2 should be {0} bytes", ECP2_COMPAT_SIZE)]
BadECP2,
#[error("BIG should be {0} bytes", BIG_SIZE)]
BadBIG,
#[error("ECP proof should be {0} bytes", ECP_PROOF_SIZE)]
BadECPProof,
#[error("User credentials should be {0} bytes", USER_CREDENTIALS_SIZE)]
BadUserCredentials,
#[error("Join response should be {0} bytes", JOIN_RESPONSE_SIZE)]
BadJoinResponse,
#[error("Group public key should be {0} bytes", GROUP_PUBLIC_KEY_SIZE)]
GroupPublicKeyLength,
#[error("Join response validation failed")]
JoinResponseValidation,
#[error("Private key and/or credentials not set")]
CredentialsNotSet,
#[error("Group public key verification failed")]
BadGroupPublicKey,
}

pub type Result<T> = std::result::Result<T, CredentialError>;

#[cxx::bridge(namespace = "anonymous_credentials")]
mod ffi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,13 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

//! Partial implementation of Direct Anonymous Attestation (DAA) for the Web Discovery Project.
//! Only signer functions are available. Performs the same elliptic curve operations as the [original C library](https://github.com/whotracksme/anonymous-credentials).
//!
//! bn254 is the only supported curve for this library.

mod data;
mod join;
mod sign;
mod util;

use brave_miracl::rand::RAND;
use rand::{rngs::OsRng, RngCore};
use thiserror::Error;

pub use self::data::*;
use self::join::{finish_join, start_join};
use self::sign::sign;

#[derive(Error, Debug)]
pub enum CredentialError {
#[error("ECP should be {0} bytes", ECP_SIZE)]
BadECP,
#[error("ECP2 should be {0} bytes", ECP2_COMPAT_SIZE)]
BadECP2,
#[error("BIG should be {0} bytes", BIG_SIZE)]
BadBIG,
#[error("ECP proof should be {0} bytes", ECP_PROOF_SIZE)]
BadECPProof,
#[error("User credentials should be {0} bytes", USER_CREDENTIALS_SIZE)]
BadUserCredentials,
#[error("Join response should be {0} bytes", JOIN_RESPONSE_SIZE)]
BadJoinResponse,
#[error("Group public key should be {0} bytes", GROUP_PUBLIC_KEY_SIZE)]
GroupPublicKeyLength,
#[error("Join response validation failed")]
JoinResponseValidation,
#[error("Private key and/or credentials not set")]
CredentialsNotSet,
#[error("Group public key verification failed")]
BadGroupPublicKey,
}

pub type Result<T> = std::result::Result<T, CredentialError>;
use crate::data::*;
use crate::join::{finish_join, start_join};
use crate::sign::sign;
use crate::{CredentialError, Result};

/// Creates and manages Direct Anonymous Attestation credentials
/// using the bn254 curve.
Expand Down
2 changes: 0 additions & 2 deletions script/brave_license_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def AddBraveCredits(root, prune_paths, special_cases, prune_dirs,
# Rust code written by Brave and under the same license as the browser.
os.path.join('brave', 'third_party', 'rust', 'adblock_cxx'),
os.path.join('brave', 'third_party', 'rust', 'anonymous_credentials'),
os.path.join('brave', 'third_party', 'rust',
'anonymous_credentials_cxx'),
os.path.join('brave', 'third_party', 'rust', 'brave_news_cxx'),
os.path.join('brave', 'third_party', 'rust', 'brave_wallet'),
os.path.join('brave', 'third_party', 'rust',
Expand Down

This file was deleted.

11 changes: 2 additions & 9 deletions third_party/rust/chromium_crates_io/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions third_party/rust/chromium_crates_io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ adblock-cxx = { version = "1" }
constellation-cxx = "0.1"
challenge-bypass-ristretto-cxx = "1"
zcash = "1"
anonymous-credentials-cxx = "0.1"
anonymous-credentials = "0.1"

[patch.crates-io.futures-retry_v0_5]
path = "../futures_retry/v0_5/crate"
Expand Down Expand Up @@ -81,13 +81,9 @@ path = "../../../components/challenge_bypass_ristretto/rust/cxx"
package = "challenge-bypass-ristretto-cxx"

[patch.crates-io.anonymous-credentials_v0_1]
path = "../../../components/web_discovery/browser/anonymous_credentials/rs/lib"
path = "../../../components/web_discovery/browser/anonymous_credentials/rust"
package = "anonymous-credentials"

[patch.crates-io.anonymous-credentials-cxx_v0_1]
path = "../../../components/web_discovery/browser/anonymous_credentials/rs/cxx"
package = "anonymous-credentials-cxx"

[patch.crates-io.aho_corasick_v1]
path = "../../../../third_party/rust/chromium_crates_io/vendor/aho-corasick-1.1.3"
package = "aho-corasick"
Expand Down

0 comments on commit 95da73e

Please sign in to comment.