From 805233cdab8558b75b7d950d33d5cf79e90aa138 Mon Sep 17 00:00:00 2001 From: Darnell Andries Date: Wed, 21 Aug 2024 17:34:24 -0700 Subject: [PATCH] Merge anonymous-credentials cxx/lib crates --- .../anonymous_credentials/rs/cxx/Cargo.toml | 13 ---- .../anonymous_credentials/rs/lib/BUILD.gn | 29 --------- .../{rs => rust}/.gitignore | 0 .../{rs/cxx => rust}/BUILD.gn | 13 ++-- .../{rs/lib => rust}/Cargo.toml | 6 +- .../{rs/lib => rust}/README.md | 6 -- .../{rs/lib => rust}/src/data.rs | 0 .../{rs/lib => rust}/src/join.rs | 0 .../{rs/cxx => rust}/src/lib.rs | 61 ++++++++++++++++--- .../lib/src/lib.rs => rust/src/manager.rs} | 44 ++----------- .../{rs/lib => rust}/src/sign.rs | 0 .../{rs/lib => rust}/src/util.rs | 0 script/brave_license_helper.py | 2 - .../v0_1/README.chromium | 8 --- .../rust/chromium_crates_io/Cargo.lock | 11 +--- .../rust/chromium_crates_io/Cargo.toml | 8 +-- 16 files changed, 74 insertions(+), 127 deletions(-) delete mode 100644 components/web_discovery/browser/anonymous_credentials/rs/cxx/Cargo.toml delete mode 100644 components/web_discovery/browser/anonymous_credentials/rs/lib/BUILD.gn rename components/web_discovery/browser/anonymous_credentials/{rs => rust}/.gitignore (100%) rename components/web_discovery/browser/anonymous_credentials/{rs/cxx => rust}/BUILD.gn (74%) rename components/web_discovery/browser/anonymous_credentials/{rs/lib => rust}/Cargo.toml (85%) rename components/web_discovery/browser/anonymous_credentials/{rs/lib => rust}/README.md (58%) rename components/web_discovery/browser/anonymous_credentials/{rs/lib => rust}/src/data.rs (100%) rename components/web_discovery/browser/anonymous_credentials/{rs/lib => rust}/src/join.rs (100%) rename components/web_discovery/browser/anonymous_credentials/{rs/cxx => rust}/src/lib.rs (70%) rename components/web_discovery/browser/anonymous_credentials/{rs/lib/src/lib.rs => rust/src/manager.rs} (85%) rename components/web_discovery/browser/anonymous_credentials/{rs/lib => rust}/src/sign.rs (100%) rename components/web_discovery/browser/anonymous_credentials/{rs/lib => rust}/src/util.rs (100%) delete mode 100644 third_party/rust/anonymous_credentials_cxx/v0_1/README.chromium diff --git a/components/web_discovery/browser/anonymous_credentials/rs/cxx/Cargo.toml b/components/web_discovery/browser/anonymous_credentials/rs/cxx/Cargo.toml deleted file mode 100644 index 83a371436ccd..000000000000 --- a/components/web_discovery/browser/anonymous_credentials/rs/cxx/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "anonymous-credentials-cxx" -version = "0.1.0" -edition = "2021" -license = "MPL-2.0" - -[dependencies] -anonymous-credentials = { version = "0.1", path = "../lib" } -cxx = "1" - -[lib] -name = "anonymous_credentials_cxx" -crate-type = ["rlib"] diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/BUILD.gn b/components/web_discovery/browser/anonymous_credentials/rs/lib/BUILD.gn deleted file mode 100644 index 03e10c4e4a16..000000000000 --- a/components/web_discovery/browser/anonymous_credentials/rs/lib/BUILD.gn +++ /dev/null @@ -1,29 +0,0 @@ -# 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/. - -import("//build/rust/rust_static_library.gni") - -rust_static_library("rust_lib") { - crate_name = "anonymous_credentials" - crate_root = "src/lib.rs" - sources = [ - "src/data.rs", - "src/join.rs", - "src/lib.rs", - "src/sign.rs", - "src/util.rs", - ] - - visibility = [ - "//brave/components/web_discovery/browser/anonymous_credentials/rs/cxx:*", - ] - - deps = [ - "//brave/third_party/rust/brave_miracl/v0_1:lib", - "//brave/third_party/rust/lazy_static/v1:lib", - "//brave/third_party/rust/rand/v0_8:lib", - "//brave/third_party/rust/thiserror/v1:lib", - ] -} diff --git a/components/web_discovery/browser/anonymous_credentials/rs/.gitignore b/components/web_discovery/browser/anonymous_credentials/rust/.gitignore similarity index 100% rename from components/web_discovery/browser/anonymous_credentials/rs/.gitignore rename to components/web_discovery/browser/anonymous_credentials/rust/.gitignore diff --git a/components/web_discovery/browser/anonymous_credentials/rs/cxx/BUILD.gn b/components/web_discovery/browser/anonymous_credentials/rust/BUILD.gn similarity index 74% rename from components/web_discovery/browser/anonymous_credentials/rs/cxx/BUILD.gn rename to components/web_discovery/browser/anonymous_credentials/rust/BUILD.gn index 03dbf10acfda..030b5da1e389 100644 --- a/components/web_discovery/browser/anonymous_credentials/rs/cxx/BUILD.gn +++ b/components/web_discovery/browser/anonymous_credentials/rust/BUILD.gn @@ -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" ] } diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/Cargo.toml b/components/web_discovery/browser/anonymous_credentials/rust/Cargo.toml similarity index 85% rename from components/web_discovery/browser/anonymous_credentials/rs/lib/Cargo.toml rename to components/web_discovery/browser/anonymous_credentials/rust/Cargo.toml index 1efc85f2de2f..bc6bac0c1053 100644 --- a/components/web_discovery/browser/anonymous_credentials/rs/lib/Cargo.toml +++ b/components/web_discovery/browser/anonymous_credentials/rust/Cargo.toml @@ -5,11 +5,11 @@ edition = "2021" authors = ["Darnell Andries "] 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"] } @@ -17,3 +17,7 @@ thiserror = "1.0" [dev-dependencies] hex = "0.4" + +[lib] +name = "anonymous_credentials" +crate-type = ["rlib"] diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/README.md b/components/web_discovery/browser/anonymous_credentials/rust/README.md similarity index 58% rename from components/web_discovery/browser/anonymous_credentials/rs/lib/README.md rename to components/web_discovery/browser/anonymous_credentials/rust/README.md index da0fa655154f..2bde17b366fc 100644 --- a/components/web_discovery/browser/anonymous_credentials/rs/lib/README.md +++ b/components/web_discovery/browser/anonymous_credentials/rust/README.md @@ -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). diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/src/data.rs b/components/web_discovery/browser/anonymous_credentials/rust/src/data.rs similarity index 100% rename from components/web_discovery/browser/anonymous_credentials/rs/lib/src/data.rs rename to components/web_discovery/browser/anonymous_credentials/rust/src/data.rs diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/src/join.rs b/components/web_discovery/browser/anonymous_credentials/rust/src/join.rs similarity index 100% rename from components/web_discovery/browser/anonymous_credentials/rs/lib/src/join.rs rename to components/web_discovery/browser/anonymous_credentials/rust/src/join.rs diff --git a/components/web_discovery/browser/anonymous_credentials/rs/cxx/src/lib.rs b/components/web_discovery/browser/anonymous_credentials/rust/src/lib.rs similarity index 70% rename from components/web_discovery/browser/anonymous_credentials/rs/cxx/src/lib.rs rename to components/web_discovery/browser/anonymous_credentials/rust/src/lib.rs index 27ee45a287f0..7079d49508c0 100644 --- a/components/web_discovery/browser/anonymous_credentials/rs/cxx/src/lib.rs +++ b/components/web_discovery/browser/anonymous_credentials/rust/src/lib.rs @@ -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 = std::result::Result; #[cxx::bridge(namespace = "anonymous_credentials")] mod ffi { diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/src/lib.rs b/components/web_discovery/browser/anonymous_credentials/rust/src/manager.rs similarity index 85% rename from components/web_discovery/browser/anonymous_credentials/rs/lib/src/lib.rs rename to components/web_discovery/browser/anonymous_credentials/rust/src/manager.rs index 15effca276dd..f364f5ff38c5 100644 --- a/components/web_discovery/browser/anonymous_credentials/rs/lib/src/lib.rs +++ b/components/web_discovery/browser/anonymous_credentials/rust/src/manager.rs @@ -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 = std::result::Result; +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. diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/src/sign.rs b/components/web_discovery/browser/anonymous_credentials/rust/src/sign.rs similarity index 100% rename from components/web_discovery/browser/anonymous_credentials/rs/lib/src/sign.rs rename to components/web_discovery/browser/anonymous_credentials/rust/src/sign.rs diff --git a/components/web_discovery/browser/anonymous_credentials/rs/lib/src/util.rs b/components/web_discovery/browser/anonymous_credentials/rust/src/util.rs similarity index 100% rename from components/web_discovery/browser/anonymous_credentials/rs/lib/src/util.rs rename to components/web_discovery/browser/anonymous_credentials/rust/src/util.rs diff --git a/script/brave_license_helper.py b/script/brave_license_helper.py index 98c665a0e296..61d8fe044a3e 100644 --- a/script/brave_license_helper.py +++ b/script/brave_license_helper.py @@ -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', diff --git a/third_party/rust/anonymous_credentials_cxx/v0_1/README.chromium b/third_party/rust/anonymous_credentials_cxx/v0_1/README.chromium deleted file mode 100644 index f20c1192a5fe..000000000000 --- a/third_party/rust/anonymous_credentials_cxx/v0_1/README.chromium +++ /dev/null @@ -1,8 +0,0 @@ -Name: anonymous-credentials-cxx -URL: https://crates.io/crates/anonymous-credentials-cxx -Description: -Version: 0.1.0 -Security Critical: yes -Shipped: yes -License: Mozilla Public License 2.0 -License File: diff --git a/third_party/rust/chromium_crates_io/Cargo.lock b/third_party/rust/chromium_crates_io/Cargo.lock index e64b6cc803b8..9d951b56ce23 100644 --- a/third_party/rust/chromium_crates_io/Cargo.lock +++ b/third_party/rust/chromium_crates_io/Cargo.lock @@ -106,19 +106,12 @@ name = "anonymous-credentials" version = "0.1.4" dependencies = [ "brave-miracl", + "cxx", "lazy_static", "rand 0.8.5", "thiserror", ] -[[package]] -name = "anonymous-credentials-cxx" -version = "0.1.0" -dependencies = [ - "anonymous-credentials", - "cxx", -] - [[package]] name = "ansi_term" version = "0.12.1" @@ -407,7 +400,7 @@ name = "chromium" version = "0.1.0" dependencies = [ "adblock-cxx", - "anonymous-credentials-cxx", + "anonymous-credentials", "brave-news-cxx", "brave_wallet", "challenge-bypass-ristretto-cxx", diff --git a/third_party/rust/chromium_crates_io/Cargo.toml b/third_party/rust/chromium_crates_io/Cargo.toml index 53401b5471d8..7729a986d81c 100644 --- a/third_party/rust/chromium_crates_io/Cargo.toml +++ b/third_party/rust/chromium_crates_io/Cargo.toml @@ -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" @@ -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"