diff --git a/Cargo.lock b/Cargo.lock index f12505604178..776a63ee1cd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -886,19 +886,20 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "clubcard" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d413adde685b0ec7e867186296768474efc2aa952063f40a5198baf760ca983" +checksum = "8ec3fe691cfeac642b45d2acee55f4c745fe9eed548380fd41d1fb7daf54297c" dependencies = [ "serde", ] [[package]] name = "clubcard-crlite" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85947de44196eb8effe46a2af1ac43e9309b7add92d805b411b7b98254935c9" +checksum = "dd2c6f668aeaab6cf4c9637400ce5bc1f7ab1cf9b424dd0125273f16bd26ca25" dependencies = [ + "base64 0.21.3", "bincode", "clubcard", "serde", diff --git a/security/manager/ssl/cert_storage/Cargo.toml b/security/manager/ssl/cert_storage/Cargo.toml index a6ad8a4e04fd..7d0bea262216 100644 --- a/security/manager/ssl/cert_storage/Cargo.toml +++ b/security/manager/ssl/cert_storage/Cargo.toml @@ -8,7 +8,7 @@ license = "MPL-2.0" base64 = "0.21.0" byteorder = "1.2.7" clubcard = "0.3" -clubcard-crlite = "0.2" +clubcard-crlite = "0.3" crossbeam-utils = "0.8" cstr = "0.2" firefox-on-glean = { path = "../../../../toolkit/components/glean/api" } diff --git a/security/manager/ssl/cert_storage/src/lib.rs b/security/manager/ssl/cert_storage/src/lib.rs index 32803cc503b2..93dce8d65608 100644 --- a/security/manager/ssl/cert_storage/src/lib.rs +++ b/security/manager/ssl/cert_storage/src/lib.rs @@ -315,6 +315,7 @@ impl Filter { } } Filter::Clubcard(clubcard) => { + let crlite_key = clubcard_crlite::CRLiteKey::new(issuer_spki_hash.as_ref(), serial); let timestamps = timestamps .iter() .map(|timestamp| { @@ -324,7 +325,7 @@ impl Filter { .map(|log_id| (log_id, timestamp.timestamp)) }) .flatten(); - match clubcard.contains(issuer_spki_hash.as_ref(), serial, timestamps) { + match clubcard.contains(&crlite_key, timestamps) { CRLiteStatus::Good => nsICertStorage::STATE_UNSET, CRLiteStatus::NotCovered => nsICertStorage::STATE_NOT_COVERED, CRLiteStatus::NotEnrolled => nsICertStorage::STATE_NOT_ENROLLED, diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 6756dcdb8843..1df413ebf609 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -52,6 +52,22 @@ start = "2021-06-21" end = "2024-04-21" notes = "No unsafe code, rather straight-forward parser." +[[wildcard-audits.clubcard]] +who = "John M. Schanck " +criteria = "safe-to-deploy" +user-id = 175410 # John Schanck (jschanck) +start = "2024-10-01" +end = "2025-10-01" +notes = "Maintained by the CryptoEng team at Mozilla." + +[[wildcard-audits.clubcard-crlite]] +who = "John M. Schanck " +criteria = "safe-to-deploy" +user-id = 175410 # John Schanck (jschanck) +start = "2024-10-01" +end = "2025-10-01" +notes = "Maintained by the CryptoEng team at Mozilla." + [[wildcard-audits.cocoa]] who = "Bobby Holley " criteria = "safe-to-deploy" diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index d93aa93752d8..67941ae3729d 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -135,6 +135,20 @@ user-id = 6743 user-login = "epage" user-name = "Ed Page" +[[publisher.clubcard]] +version = "0.3.2" +when = "2024-10-08" +user-id = 175410 +user-login = "jschanck" +user-name = "John Schanck" + +[[publisher.clubcard-crlite]] +version = "0.3.0" +when = "2024-10-14" +user-id = 175410 +user-login = "jschanck" +user-name = "John Schanck" + [[publisher.core-foundation]] version = "0.9.3" when = "2022-02-07" diff --git a/third_party/rust/clubcard-crlite/.cargo-checksum.json b/third_party/rust/clubcard-crlite/.cargo-checksum.json index 21d7b4b42889..a3b2ee8d54a5 100644 --- a/third_party/rust/clubcard-crlite/.cargo-checksum.json +++ b/third_party/rust/clubcard-crlite/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"2e4c5d706d89b5698d11925df54df4049f3f501af31154fd2dcc2411c4fd3307","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","src/builder.rs":"616f7aa1ea6e88bdc0c939c24b0e432e40fa553535ff88098fb8967d32b339a5","src/lib.rs":"d939278e06b1dca0bf827d491213d7ebadc7be6cc89bc53c608af42872e3378d","src/query.rs":"aceac54c20c384f54fe5d345af3e59acb4c7a59552e197f033969fab505db0b0"},"package":"a85947de44196eb8effe46a2af1ac43e9309b7add92d805b411b7b98254935c9"} \ No newline at end of file +{"files":{"Cargo.lock":"8f68f70084f64ceb9e6171033963b987ce34826ac873322fead61159ea7183bd","Cargo.toml":"59a923c9e3896fe1f516228ff6b7d915cd7d87a896f2760220be0bcc28962618","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","examples/inspect.rs":"e8406a230da643e9dc45260ac496926eaddec4c1f606fb69c566409019e3b20e","examples/query.rs":"6bb7386a032a3c0ed9d31fdc4a4443c90ba52347ea972427cc36a5c798ffeed4","src/builder.rs":"23450a3465cfba6daef0bec643ea1cfbc52c16e3e820c7d795988f5d50c7eec6","src/lib.rs":"3788c6d816abd13f41b17c2134ac47ebacf8d9d6413adf6847925a3194a9ca03","src/query.rs":"9898913516f75c64ee85560571fe131d550db3a046057ab50dced3db87b1db45"},"package":"dd2c6f668aeaab6cf4c9637400ce5bc1f7ab1cf9b424dd0125273f16bd26ca25"} \ No newline at end of file diff --git a/third_party/rust/clubcard-crlite/Cargo.lock b/third_party/rust/clubcard-crlite/Cargo.lock new file mode 100644 index 000000000000..59d90b102b38 --- /dev/null +++ b/third_party/rust/clubcard-crlite/Cargo.lock @@ -0,0 +1,653 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "asn1-rs" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5493c3bedbacf7fd7382c6346bbd66687d12bbaad3a89a2d2c303ee6cf20b048" +dependencies = [ + "asn1-rs-derive", + "asn1-rs-impl", + "displaydoc", + "nom", + "num-traits", + "rusticata-macros", + "thiserror", + "time", +] + +[[package]] +name = "asn1-rs-derive" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "asn1-rs-impl" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clubcard" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ec3fe691cfeac642b45d2acee55f4c745fe9eed548380fd41d1fb7daf54297c" +dependencies = [ + "rand", + "serde", +] + +[[package]] +name = "clubcard-crlite" +version = "0.3.0" +dependencies = [ + "base64", + "bincode", + "clubcard", + "rand", + "serde", + "serde_json", + "sha2", + "x509-parser", +] + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "der-parser" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cd0a5c643689626bec213c4d8bd4d96acc8ffdb4ad4bb6bc16abf27d5f4b553" +dependencies = [ + "asn1-rs", + "displaydoc", + "nom", + "num-bigint", + "num-traits", + "rusticata-macros", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "oid-registry" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d8034d9489cdaf79228eb9f6a3b8d7bb32ba00d6645ebd48eef4077ceb5bd9" +dependencies = [ + "asn1-rs", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys", +] + +[[package]] +name = "rusticata-macros" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632" +dependencies = [ + "nom", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "x509-parser" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcbc162f30700d6f3f82a24bf7cc62ffe7caea42c0b2cba8bf7f3ae50cf51f69" +dependencies = [ + "asn1-rs", + "data-encoding", + "der-parser", + "lazy_static", + "nom", + "oid-registry", + "ring", + "rusticata-macros", + "thiserror", + "time", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/third_party/rust/clubcard-crlite/Cargo.toml b/third_party/rust/clubcard-crlite/Cargo.toml index 8c3a70526477..f7c4d35d12d5 100644 --- a/third_party/rust/clubcard-crlite/Cargo.toml +++ b/third_party/rust/clubcard-crlite/Cargo.toml @@ -12,15 +12,32 @@ [package] edition = "2021" name = "clubcard-crlite" -version = "0.2.1" +version = "0.3.0" authors = ["John M. Schanck "] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "An instantiation of Clubcard for use in CRLite" +readme = false license = "MPL-2.0" repository = "https://github.com/mozilla/clubcard-crlite/" +[lib] +name = "clubcard_crlite" +path = "src/lib.rs" + +[[example]] +name = "inspect" +path = "examples/inspect.rs" + +[[example]] +name = "query" +path = "examples/query.rs" + [dependencies.base64] -version = "0.22" -optional = true +version = "0.21" [dependencies.bincode] version = "1.3" @@ -49,10 +66,13 @@ version = "0.8" [dev-dependencies.sha2] version = "0.10" +[dev-dependencies.x509-parser] +version = "0.16" +features = ["verify"] + [features] builder = [ "dep:rand", - "dep:base64", "dep:serde_json", "clubcard/builder", ] diff --git a/third_party/rust/clubcard-crlite/examples/inspect.rs b/third_party/rust/clubcard-crlite/examples/inspect.rs new file mode 100644 index 000000000000..3bcf2d749a8b --- /dev/null +++ b/third_party/rust/clubcard-crlite/examples/inspect.rs @@ -0,0 +1,35 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +use clubcard_crlite::CRLiteClubcard; +use std::env::args; +use std::path::PathBuf; +use std::process::ExitCode; + +fn parse_args() -> Option { + let mut args = args().map(PathBuf::from); + let _name = args.next()?; + Some(args.next()?) +} + +fn main() -> std::process::ExitCode { + let Some(filter_path) = parse_args() else { + eprintln!("Usage: {} ", args().next().unwrap()); + return ExitCode::FAILURE; + }; + + let Ok(filter_bytes) = std::fs::read(&filter_path) else { + eprintln!("Could not read filter"); + return ExitCode::FAILURE; + }; + + let Ok(filter) = CRLiteClubcard::from_bytes(&filter_bytes) else { + eprintln!("Could not parse filter"); + return ExitCode::FAILURE; + }; + + println!("{}", filter); + + ExitCode::SUCCESS +} diff --git a/third_party/rust/clubcard-crlite/examples/query.rs b/third_party/rust/clubcard-crlite/examples/query.rs new file mode 100644 index 000000000000..0a8c8040f6b4 --- /dev/null +++ b/third_party/rust/clubcard-crlite/examples/query.rs @@ -0,0 +1,99 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +use clubcard_crlite::{CRLiteClubcard, CRLiteKey, CRLiteStatus}; +use sha2::{Digest, Sha256}; +use std::env::args; +use std::path::PathBuf; +use std::process::ExitCode; +use x509_parser::prelude::*; + +fn read_as_der(path: &PathBuf) -> Result, std::io::Error> { + let bytes = std::fs::read(&path)?; + match parse_x509_pem(&bytes) { + Ok((_, pem)) => Ok(pem.contents), + _ => Ok(bytes), + } +} + +fn parse_args() -> Option<(PathBuf, PathBuf, PathBuf)> { + let mut args = args().map(PathBuf::from); + let _name = args.next()?; + Some((args.next()?, args.next()?, args.next()?)) +} + +fn main() -> std::process::ExitCode { + let Some((filter_path, issuer_cert_path, end_entity_cert_path)) = parse_args() else { + eprintln!( + "Usage: {} ", + args().next().unwrap() + ); + return ExitCode::FAILURE; + }; + + let Ok(filter_bytes) = std::fs::read(&filter_path) else { + eprintln!("Could not read filter"); + return ExitCode::FAILURE; + }; + + let Ok(filter) = CRLiteClubcard::from_bytes(&filter_bytes) else { + eprintln!("Could not parse filter"); + return ExitCode::FAILURE; + }; + + let Ok(issuer_bytes) = read_as_der(&issuer_cert_path) else { + eprintln!("Could not read issuer certificate"); + return ExitCode::FAILURE; + }; + + let Ok((_, issuer)) = X509Certificate::from_der(&issuer_bytes) else { + eprintln!("Could not parse issuer certificate"); + return ExitCode::FAILURE; + }; + + let Ok(cert_bytes) = read_as_der(&end_entity_cert_path) else { + eprintln!("Could not read end-entity certificate"); + return ExitCode::FAILURE; + }; + + let Ok((_, cert)) = X509Certificate::from_der(&cert_bytes) else { + eprintln!("Could not parse end-entity certificate"); + return ExitCode::FAILURE; + }; + + if cert.verify_signature(Some(issuer.public_key())).is_err() { + eprintln!("Invalid signature (wrong issuer certificate?)"); + return ExitCode::FAILURE; + } + + if !cert.tbs_certificate.validity.is_valid() { + eprintln!("End-entity certificate is expired"); + return ExitCode::FAILURE; + } + + let Ok(Some(sct_extension)) = cert + .tbs_certificate + .get_extension_unique(&x509_parser::oid_registry::OID_CT_LIST_SCT) + else { + eprintln!("End entity certificate has no SCTs"); + return ExitCode::FAILURE; + }; + + let ParsedExtension::SCT(scts) = sct_extension.parsed_extension() else { + eprintln!("End entity certificate has no SCTs"); + return ExitCode::FAILURE; + }; + + let issuer_spki_hash: [u8; 32] = Sha256::digest(issuer.tbs_certificate.subject_pki.raw).into(); + let serial = cert.tbs_certificate.raw_serial(); + let key = CRLiteKey::new(&issuer_spki_hash, &serial); + + match filter.contains(&key, scts.iter().map(|sct| (sct.id.key_id, sct.timestamp))) { + CRLiteStatus::Good => println!("Good"), + CRLiteStatus::Revoked => println!("Revoked"), + CRLiteStatus::NotEnrolled | CRLiteStatus::NotCovered => println!("Unknown"), + }; + + ExitCode::SUCCESS +} diff --git a/third_party/rust/clubcard-crlite/src/builder.rs b/third_party/rust/clubcard-crlite/src/builder.rs index b27995d5da42..76b55e9b21c9 100644 --- a/third_party/rust/clubcard-crlite/src/builder.rs +++ b/third_party/rust/clubcard-crlite/src/builder.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use crate::query::{CRLiteCoverage, CRLiteQuery}; +use crate::query::{CRLiteCoverage, CRLiteKey, CRLiteQuery}; use clubcard::{AsQuery, Equation, Filterable}; use serde::Deserialize; use std::collections::HashMap; @@ -101,19 +101,11 @@ impl CRLiteBuilderItem { } } -impl<'a> From<&'a CRLiteBuilderItem> for CRLiteQuery<'a> { - fn from(item: &'a CRLiteBuilderItem) -> Self { - Self { - issuer: &item.issuer, - serial: &item.serial, - log_timestamp: None, - } - } -} - impl AsQuery<4> for CRLiteBuilderItem { fn as_query(&self, m: usize) -> Equation<4> { - CRLiteQuery::from(self).as_query(m) + let crlite_key = CRLiteKey::new(&self.issuer, &self.serial); + let crlite_query = CRLiteQuery::new(&crlite_key, None); + crlite_query.as_query(m) } fn block(&self) -> &[u8] { @@ -216,12 +208,8 @@ mod tests { let issuer = [i as u8; 32]; for j in 0..universe_size { let serial = j.to_le_bytes(); - let item = CRLiteQuery { - issuer: &issuer, - serial: &serial, - log_timestamp: None, - }; - if clubcard.unchecked_contains(&item) { + let key = CRLiteKey::new(&issuer, &serial); + if clubcard.unchecked_contains(&CRLiteQuery::new(&key, None)) { included += 1; } else { excluded += 1; @@ -235,61 +223,43 @@ mod tests { // Test that querying a serial from a never-before-seen issuer results in a non-member return. let issuer = [subset_sizes.len() as u8; 32]; let serial = 0usize.to_le_bytes(); - let item = CRLiteQuery { - issuer: &issuer, - serial: &serial, - log_timestamp: None, - }; - assert!(!clubcard.unchecked_contains(&item)); + let key = CRLiteKey::new(&issuer, &serial); + assert!(!clubcard.unchecked_contains(&CRLiteQuery::new(&key, None))); assert!(subset_sizes.len() > 0 && subset_sizes[0] > 0 && subset_sizes[0] < universe_size); let issuer = [0u8; 32]; let revoked_serial = 0usize.to_le_bytes(); let nonrevoked_serial = (universe_size - 1).to_le_bytes(); - // Test that calling contains() a without a timestamp results in a NotInUniverse return - let item = CRLiteQuery { - issuer: &issuer, - serial: &revoked_serial, - log_timestamp: None, - }; + // Test that calling contains() without a timestamp results in a NotInUniverse return + let revoked_serial_key = CRLiteKey::new(&issuer, &revoked_serial); + let query = CRLiteQuery::new(&revoked_serial_key, None); assert!(matches!( - clubcard.contains(&item), + clubcard.contains(&query), Membership::NotInUniverse )); - // Test that calling contains() without a timestamp in a covered interval results in a + // Test that calling contains() with a timestamp in a covered interval results in a // Member return. let log_id = [0u8; 32]; let timestamp = (&log_id, 100); - let item = CRLiteQuery { - issuer: &issuer, - serial: &revoked_serial, - log_timestamp: Some(timestamp), - }; - assert!(matches!(clubcard.contains(&item), Membership::Member)); + let query = CRLiteQuery::new(&revoked_serial_key, Some(timestamp)); + assert!(matches!(clubcard.contains(&query), Membership::Member)); // Test that calling contains() without a timestamp in a covered interval results in a // Member return. let timestamp = (&log_id, 100); - let item = CRLiteQuery { - issuer: &issuer, - serial: &nonrevoked_serial, - log_timestamp: Some(timestamp), - }; - assert!(matches!(clubcard.contains(&item), Membership::Nonmember)); + let nonrevoked_serial_key = CRLiteKey::new(&issuer, &nonrevoked_serial); + let query = CRLiteQuery::new(&nonrevoked_serial_key, Some(timestamp)); + assert!(matches!(clubcard.contains(&query), Membership::Nonmember)); // Test that calling contains() without a timestamp in a covered interval results in a // Member return. let log_id = [1u8; 32]; let timestamp = (&log_id, 100); - let item = CRLiteQuery { - issuer: &issuer, - serial: &revoked_serial, - log_timestamp: Some(timestamp), - }; + let query = CRLiteQuery::new(&revoked_serial_key, Some(timestamp)); assert!(matches!( - clubcard.contains(&item), + clubcard.contains(&query), Membership::NotInUniverse )); } diff --git a/third_party/rust/clubcard-crlite/src/lib.rs b/third_party/rust/clubcard-crlite/src/lib.rs index ab55f866123c..3db49b12bf03 100644 --- a/third_party/rust/clubcard-crlite/src/lib.rs +++ b/third_party/rust/clubcard-crlite/src/lib.rs @@ -6,4 +6,4 @@ pub mod builder; mod query; -pub use query::{CRLiteClubcard, CRLiteCoverage, CRLiteQuery, CRLiteStatus}; +pub use query::{CRLiteClubcard, CRLiteCoverage, CRLiteKey, CRLiteQuery, CRLiteStatus}; diff --git a/third_party/rust/clubcard-crlite/src/query.rs b/third_party/rust/clubcard-crlite/src/query.rs index 3f9c8b23b775..f3c29ddc9c7f 100644 --- a/third_party/rust/clubcard-crlite/src/query.rs +++ b/third_party/rust/clubcard-crlite/src/query.rs @@ -2,7 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use clubcard::{ApproximateSizeOf, AsQuery, Clubcard, Equation, Membership, Queryable}; +use base64::Engine; +use clubcard::{ + ApproximateSizeOf, AsQuery, Clubcard, ClubcardIndex, Equation, Membership, Queryable, +}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::cmp::max; @@ -20,41 +23,50 @@ type TimestampInterval = (Timestamp, Timestamp); #[derive(Serialize, Deserialize)] pub struct CRLiteCoverage(pub(crate) HashMap); -#[derive(Clone, Debug)] -pub struct CRLiteQuery<'a> { +#[derive(Debug)] +pub struct CRLiteKey<'a> { pub(crate) issuer: &'a IssuerSpkiHash, pub(crate) serial: &'a [u8], + pub(crate) issuer_serial_hash: [u8; 32], +} + +impl<'a> CRLiteKey<'a> { + pub fn new(issuer: &'a IssuerSpkiHash, serial: &'a [u8]) -> CRLiteKey<'a> { + let mut issuer_serial_hash = [0u8; 32]; + let mut hasher = Sha256::new(); + hasher.update(issuer); + hasher.update(serial); + hasher.finalize_into((&mut issuer_serial_hash).into()); + CRLiteKey { + issuer, + serial, + issuer_serial_hash, + } + } +} + +#[derive(Clone, Debug)] +pub struct CRLiteQuery<'a> { + pub(crate) key: &'a CRLiteKey<'a>, pub(crate) log_timestamp: Option<(&'a LogId, Timestamp)>, } impl<'a> CRLiteQuery<'a> { - pub fn new( - issuer: &'a IssuerSpkiHash, - serial: &'a [u8], - log_timestamp: Option<(&'a LogId, u64)>, - ) -> CRLiteQuery<'a> { - CRLiteQuery { - issuer, - serial, - log_timestamp, - } + pub fn new(key: &'a CRLiteKey<'a>, log_timestamp: Option<(&'a LogId, u64)>) -> CRLiteQuery<'a> { + CRLiteQuery { key, log_timestamp } } } impl<'a> AsQuery for CRLiteQuery<'a> { fn block(&self) -> &[u8] { - self.issuer.as_ref() + self.key.issuer.as_ref() } fn as_query(&self, m: usize) -> Equation { - let mut digest = [0u8; 32]; - let mut hasher = Sha256::new(); - hasher.update(self.issuer); - hasher.update(self.serial); - hasher.finalize_into((&mut digest).into()); - let mut a = [0u64; 4]; - for (i, x) in digest + for (i, x) in self + .key + .issuer_serial_hash .chunks_exact(8) // TODO: use array_chunks::<8>() when stable .map(|x| TryInto::<[u8; 8]>::try_into(x).unwrap()) .map(u64::from_le_bytes) @@ -63,12 +75,12 @@ impl<'a> AsQuery for CRLiteQuery<'a> { a[i] = x; } a[0] |= 1; - let s = (a[3] as usize) % max(1, m); + let s = (a[3] % (max(1, m) as u64)) as usize; Equation::homogeneous(s, a) } fn discriminant(&self) -> &[u8] { - self.serial + self.key.serial } } @@ -135,7 +147,59 @@ impl AsRef> for CRLiteClubcard { impl std::fmt::Display for CRLiteClubcard { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) + writeln!(f, "{}", self.0)?; + writeln!(f, "{:=^80}", " Coverage ")?; + writeln!( + f, + "{: ^46} {: >16}{: >16}", + "CT Log ID", "Min Time", "Max Time" + )?; + writeln!(f, "{:-<80}", "")?; + let mut coverage_data = self + .universe() + .0 + .iter() + .map(|(log_id, (low, high))| { + (base64::prelude::BASE64_STANDARD.encode(log_id), *low, *high) + }) + .collect::>(); + coverage_data.sort_by_key(|x| u64::MAX - x.2); + for (log_id, low, high) in coverage_data { + writeln!(f, "{: >46},{: >16},{: >16}", log_id, low, high)?; + } + writeln!(f)?; + writeln!(f, "{:=^80}", " Index ")?; + writeln!( + f, + "{: ^46}{: >10}{: >10}{: >14}", + "Issuer ID", "Exceptions", "Rank", "Bits" + )?; + writeln!(f, "{:-<80}", "")?; + let mut index_data = self + .0 + .index() + .iter() + .map(|(block, entry)| { + let filter_size = + entry.approx_filter_m * entry.approx_filter_rank + entry.exact_filter_m; + ( + base64::prelude::BASE64_URL_SAFE.encode(block), + entry.approx_filter_rank, + entry.exceptions.len(), + filter_size, + ) + }) + .collect::>(); + index_data.sort_by_key(|x| usize::MAX - x.3); + + for (issuer, rank, exceptions, filter_size) in &index_data { + writeln!( + f, + "{: >46},{: >9},{: >9},{: >13}", + issuer, exceptions, rank, filter_size + )?; + } + Ok(()) } } @@ -168,15 +232,22 @@ impl CRLiteClubcard { .map_err(|_| ClubcardError::Deserialize) } + pub fn universe(&self) -> &CRLiteCoverage { + self.0.universe() + } + + pub fn index(&self) -> &ClubcardIndex { + self.0.index() + } + pub fn contains<'a>( &self, - issuer_spki_hash: &'a IssuerSpkiHash, - serial: &'a [u8], + key: &'a CRLiteKey<'a>, timestamps: impl Iterator, ) -> CRLiteStatus { for (log_id, timestamp) in timestamps { - let crlite_key = CRLiteQuery::new(issuer_spki_hash, serial, Some((log_id, timestamp))); - let status = self.0.contains(&crlite_key).into(); + let crlite_query = CRLiteQuery::new(key, Some((log_id, timestamp))); + let status = self.0.contains(&crlite_query).into(); if status == CRLiteStatus::NotCovered { continue; } diff --git a/third_party/rust/clubcard/.cargo-checksum.json b/third_party/rust/clubcard/.cargo-checksum.json index 61391783a88f..2ab824496793 100644 --- a/third_party/rust/clubcard/.cargo-checksum.json +++ b/third_party/rust/clubcard/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"f171458a2a360bb0386b23346bc42b16ce372fe2b90c8844cebc83a3e0b72ed3","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"cb41e528a187cc241c4d7a27a77fc49416f74ee16fd1a576cdb173e0155ce384","src/builder.rs":"36043cdf45e77b93c9ac0f8573cdc9d584fb3159ea78e77b425001ab210df279","src/clubcard.rs":"f0b12ed08f0625d46a31377b44275c854c4a98f27c42f71aee37d51e39f57e45","src/equation.rs":"00c8b782a3398a296281acaa942e29d2fa89cafda525ba1ff2cc7142fe6780bf","src/lib.rs":"79701c7179054a801800576868d7eb3a812ca87c4a345b092d16790f92364764","src/query.rs":"23c397a4e20f8009716e7fc5081f3f1473294a49d16713c44087c229eabc4412"},"package":"3d413adde685b0ec7e867186296768474efc2aa952063f40a5198baf760ca983"} \ No newline at end of file +{"files":{"Cargo.lock":"17c365f9dce6301dd7aaa47f4fd13de08b952789f7fca4fec9bacc9f1720a6a2","Cargo.toml":"ca58492dfe5151abc97e002b7dd32b891de16fe257460aa10d7190492002714b","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"cb41e528a187cc241c4d7a27a77fc49416f74ee16fd1a576cdb173e0155ce384","examples/uint_no_partition/2000_nums.in":"a7e6da56ec72abdc807406137a957e0663935dede2fb9b1a542b067ab4b50157","examples/uint_no_partition/generate_test.py":"944a061d3fbe9e01b651c2bf848ad91d90bff371821573ce680d9e00a6d152a2","examples/uint_no_partition/main.rs":"582887b9e98001df7fd1605f0ed062f158dba9233e5b4e9c912842b0a79a75ed","src/builder.rs":"b4fe5fc2131443a18cc09eaa26416627eef9cca76bb55910392084d8b4dd6aa4","src/clubcard.rs":"2bab32f0f0b12ad976b0ef4cbff67fa1586cce68560da008a5b4527de02aad0e","src/equation.rs":"00c8b782a3398a296281acaa942e29d2fa89cafda525ba1ff2cc7142fe6780bf","src/lib.rs":"1135583c2e74ae82c194fd49c07f4a685034ff516ddaa6fa897740e3f4b38b49","src/query.rs":"23c397a4e20f8009716e7fc5081f3f1473294a49d16713c44087c229eabc4412"},"package":"8ec3fe691cfeac642b45d2acee55f4c745fe9eed548380fd41d1fb7daf54297c"} \ No newline at end of file diff --git a/third_party/rust/clubcard/Cargo.lock b/third_party/rust/clubcard/Cargo.lock new file mode 100644 index 000000000000..1431f7f0508e --- /dev/null +++ b/third_party/rust/clubcard/Cargo.lock @@ -0,0 +1,233 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clubcard" +version = "0.3.2" +dependencies = [ + "rand", + "serde", + "sha2", +] + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "syn" +version = "2.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/third_party/rust/clubcard/Cargo.toml b/third_party/rust/clubcard/Cargo.toml index 84d7f81ab802..4782b8d3c813 100644 --- a/third_party/rust/clubcard/Cargo.toml +++ b/third_party/rust/clubcard/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2021" name = "clubcard" -version = "0.3.1" +version = "0.3.2" authors = ["John M. Schanck "] description = "Clubcard is an exact membership query filter for static sets" readme = "README.md" @@ -27,5 +27,8 @@ optional = true version = "1.0" features = ["derive"] +[dev-dependencies.sha2] +version = "0.10" + [features] builder = ["dep:rand"] diff --git a/third_party/rust/clubcard/examples/uint_no_partition/2000_nums.in b/third_party/rust/clubcard/examples/uint_no_partition/2000_nums.in new file mode 100644 index 000000000000..a8d5a649c72b --- /dev/null +++ b/third_party/rust/clubcard/examples/uint_no_partition/2000_nums.in @@ -0,0 +1,2000 @@ +7526533 +12380776 +10514794 +15763961 +13665503 +14727989 +16380705 +12016051 +14087834 +2743067 +16717707 +4678733 +275773 +2359521 +8512949 +10956075 +6877382 +10930304 +11977505 +16662720 +10729831 +8302553 +4045879 +3642497 +6158746 +9683244 +6941308 +12837972 +6023572 +2053406 +192193 +16607204 +10656785 +10099488 +3099576 +7416988 +4222248 +8958688 +7128258 +7445941 +5357333 +6143271 +1932639 +13270469 +2993514 +14277378 +6216932 +3797812 +13712215 +6710569 +6309278 +15677579 +74488 +13030532 +15238730 +12339358 +2801664 +7519106 +116505 +9176215 +7767630 +4708108 +4274538 +330100 +7263077 +7752517 +13894103 +3853706 +5137557 +9331651 +7466675 +615897 +3559198 +5717287 +10292681 +11079534 +9530492 +9577080 +14217387 +87113 +2460274 +905385 +1593121 +7894868 +6368026 +15712261 +11642814 +12017124 +8019981 +16650239 +15145950 +3972577 +4042031 +9860817 +1923359 +1130505 +3685490 +13214099 +10143607 +1938740 +14018942 +1166372 +7313996 +3282324 +11137659 +2025432 +3268498 +7734300 +7983614 +11960950 +16356564 +14892585 +3697468 +6861430 +14074240 +12845769 +13966947 +4217639 +15873396 +12361189 +12180043 +13420739 +792894 +7899852 +6523210 +1764788 +9936772 +2440006 +5493201 +15042289 +897893 +14364492 +11384996 +10537579 +8036021 +5302542 +7016238 +10130893 +970833 +2110664 +280065 +13515081 +3512886 +12271968 +12422341 +8313604 +6573239 +5374877 +2424613 +1028777 +8703283 +7451584 +14137668 +16767928 +6066314 +9855946 +10459064 +1537724 +2640564 +13937689 +2028973 +15546377 +8890549 +527040 +11347049 +13132572 +2377120 +783259 +3010229 +15880635 +652109 +5996129 +14756953 +1970617 +14260293 +4346127 +13798891 +3891333 +4880936 +7924817 +13247841 +3065647 +8821282 +13547498 +10513125 +12871191 +12203354 +11944922 +8224379 +3658369 +1098172 +5202903 +15556699 +14970233 +16549093 +8435812 +9294750 +7290928 +13048343 +15576083 +13065072 +12070827 +455515 +691109 +16116357 +9459157 +1537030 +12493330 +12566986 +393552 +11395186 +16075388 +2753482 +6192152 +570097 +5136314 +15785279 +2755698 +13089558 +809574 +11483803 +12158132 +12520599 +1329750 +2604653 +12637763 +9303629 +16720219 +10736487 +5100418 +1702648 +16341944 +15558127 +1327163 +14121840 +11232782 +7291372 +7629890 +1194485 +11355926 +16204172 +12912991 +7019623 +13014640 +9402232 +144225 +3731272 +2777256 +2950990 +14538467 +10817802 +1537721 +15670764 +7856929 +5982138 +1023007 +15822027 +7047118 +4729254 +13281942 +16046190 +989249 +14181260 +4106465 +16693245 +13671664 +2947168 +6920376 +16685255 +16750735 +11016513 +14719738 +347524 +7997234 +998258 +3726096 +9532413 +11771975 +10780685 +13261952 +3605470 +15309026 +15473068 +14645561 +5476300 +9729581 +6180494 +4181116 +4105262 +5855272 +15725530 +15044347 +3971176 +12973469 +7003327 +360521 +15010016 +478134 +10970950 +15538316 +8543720 +11115643 +1319596 +16355559 +9067533 +13873841 +2652731 +5976751 +13233863 +13733286 +971686 +3331642 +7221367 +110954 +5165043 +8551027 +2280016 +15133362 +9759700 +6123222 +14643244 +1380079 +16371204 +518558 +13460070 +13279655 +15110976 +15156679 +1203285 +13068803 +6643968 +8446434 +13309049 +8211554 +1992 +3487975 +13513944 +6795155 +9935992 +4268098 +16517713 +15730098 +6581915 +4657495 +11558289 +11993477 +1938642 +15780645 +5445721 +4262277 +3278375 +12780770 +13608377 +13579092 +7009093 +922853 +16648465 +761652 +12184002 +12998133 +920021 +16143642 +13823985 +646500 +7149546 +12078888 +4724739 +8840591 +591708 +2284318 +1807858 +12419354 +10667451 +12848320 +9162254 +13427825 +16740565 +16140379 +8098295 +2691864 +6298028 +12571931 +12868752 +7045557 +8298114 +16049551 +3164727 +2471687 +8882477 +11974204 +16235668 +3180316 +6102423 +3427641 +13204466 +12125851 +412350 +14875772 +13647056 +11516487 +494888 +14541918 +8777645 +14745197 +7609252 +7709196 +11349102 +109179 +8015990 +4623608 +8346698 +10559734 +10600845 +8352810 +4984260 +2531729 +5549884 +14826658 +852055 +1710537 +14525204 +14307261 +7675602 +1930053 +11658189 +5933159 +10628092 +5551998 +9449160 +11759968 +12372234 +9941978 +1261652 +14495616 +13374953 +4089439 +16030306 +11197578 +14695319 +5821063 +12890872 +3540585 +14548240 +639530 +11784174 +10784845 +10837465 +5239045 +3549916 +5257919 +2600573 +1781004 +14941627 +9054712 +9426976 +5708934 +6750427 +10480052 +12734109 +12080725 +5015261 +15284425 +16572504 +14755597 +9437660 +16708542 +67168 +3527589 +13103246 +5731840 +5497787 +11877292 +8517843 +10016516 +2971516 +11323350 +1897688 +14253281 +12836263 +15332101 +12409243 +14897874 +10595782 +10104651 +3458715 +4939320 +8748179 +8475392 +1846592 +1562237 +12670229 +409704 +13646590 +753738 +10307392 +10381181 +1304305 +7506175 +10032869 +14840327 +7752526 +1817557 +7143978 +9098209 +952260 +14031522 +1466047 +1499338 +12757792 +1941836 +9703423 +15938639 +4661838 +13168610 +11359153 +15855823 +12031660 +7842138 +4180457 +8897656 +15177359 +14155169 +9247121 +12442775 +12210249 +10125 +4613908 +9451313 +5864914 +74562 +1565092 +1711559 +4229883 +5304162 +11513342 +855959 +14942600 +587425 +9163792 +16349495 +8110253 +1278140 +9767381 +12244165 +9440318 +4779628 +14677231 +14997837 +6987988 +408702 +14507022 +3354688 +5367115 +13803734 +8663749 +2850966 +9422876 +14212756 +490423 +7344484 +736204 +1310053 +4825204 +14558617 +6262300 +7385621 +3895414 +2435900 +12120472 +4201119 +6579657 +15632716 +8929168 +4895476 +9362450 +5239530 +12577127 +7160670 +2957643 +11356415 +7683638 +9292486 +12283107 +2950492 +3975253 +9870830 +9982601 +14208264 +4396391 +86904 +13905744 +5971229 +11469430 +3603484 +16459932 +1928658 +7971823 +7021794 +9020756 +9439207 +10557548 +9248357 +7791358 +337642 +6592358 +5842323 +4864053 +309651 +12083414 +1566214 +10281351 +11162710 +2445109 +8162781 +13951991 +1179189 +7153608 +5425301 +540788 +15045722 +5314764 +7416867 +12087522 +2191003 +6274064 +5083743 +4812309 +9945177 +8996068 +11413480 +7211009 +4480223 +13815332 +6139400 +3503416 +6856133 +16457834 +12519929 +3085373 +12015055 +1289836 +2498808 +12276576 +4996157 +1147156 +2781675 +3498125 +8255859 +1674889 +11471134 +16621519 +15630075 +14374987 +3056726 +8125041 +7012099 +10006560 +4897351 +3191546 +10844613 +4932260 +6561295 +842567 +6182120 +902386 +6756115 +15022138 +16633263 +12716231 +742901 +16556483 +9115281 +638462 +5113536 +10084481 +33709 +10770456 +8236051 +16337996 +8840135 +12702764 +1261483 +630818 +11901039 +9527257 +12151703 +3671302 +4112222 +14935790 +4786061 +7801258 +4979776 +11810325 +13434893 +15375158 +10539198 +1394368 +12694753 +16596405 +6781158 +12651509 +4977730 +10887856 +15595344 +3283335 +298405 +1723029 +6839846 +7748865 +3089612 +15835861 +13642562 +10060165 +10322054 +5012132 +2795549 +6695058 +6916051 +10633934 +13179142 +14634063 +4985628 +12661850 +3581300 +6284237 +14385918 +15369600 +10032084 +7213870 +585404 +2217419 +1413083 +4796776 +1915873 +8081337 +3711335 +10431571 +8228726 +10442600 +5056910 +9071296 +13349893 +5928201 +16408909 +3817496 +2524017 +15199881 +2474111 +9741704 +8168893 +7622946 +8948743 +13459987 +1290290 +3044234 +16032542 +8999969 +13597678 +5890035 +6810657 +14009270 +12663813 +10948797 +14929248 +9673786 +4231670 +13599421 +8340249 +6126443 +4592150 +9153069 +9763008 +3331374 +5482085 +13204584 +10127801 +3622776 +15995594 +8460763 +14766632 +15542117 +5049544 +15395152 +14624916 +13782479 +4591460 +12340886 +2566 +10412209 +4996104 +8256573 +9688633 +6758234 +13942154 +16235571 +5270514 +2482448 +7657524 +3191348 +2504084 +3856676 +6825119 +2130710 +12355438 +7416043 +1324964 +13758085 +3921322 +11096693 +5340195 +217868 +2310816 +10601004 +10768538 +16365291 +553772 +5974542 +16152885 +8396393 +8189308 +6733972 +14405799 +13210771 +2108345 +10748723 +16699332 +7582245 +12725889 +4933516 +4148877 +4367404 +904007 +8267410 +3322759 +13740367 +11581629 +14969044 +14455726 +2800907 +11069534 +15752875 +8140558 +604136 +2827720 +13489014 +16539004 +3431310 +5892700 +14732023 +10120820 +16410614 +14120085 +7699033 +9899988 +8524191 +14349658 +14588290 +9240475 +11480350 +8887683 +11203834 +389637 +12137551 +11966657 +2940618 +12424295 +7441399 +10490797 +1746190 +6563348 +2543167 +1319287 +6039669 +12429790 +15405832 +1362984 +1176367 +13313204 +13729139 +15655677 +10596086 +5807715 +1497710 +10579438 +328853 +3709285 +7647983 +7459330 +3864339 +14108429 +581100 +12653524 +2296403 +14907342 +6811272 +12832837 +9372674 +15563039 +16224744 +6875299 +6259409 +5283713 +11776152 +15308034 +9786917 +16616815 +10991233 +5134947 +15631705 +8748132 +16147046 +9337454 +6244536 +12585377 +10223863 +981254 +12010093 +5040383 +6378734 +14727148 +2515013 +7339657 +2416909 +4982098 +12498431 +5729067 +1428566 +13801519 +965592 +11820460 +6032672 +14439503 +11566305 +11250818 +4065608 +7347734 +16095343 +6220622 +4906724 +2189294 +11092039 +9581259 +2343446 +12963319 +4112666 +10525011 +12090972 +9371313 +3033070 +9692219 +9584994 +13665350 +6710216 +5536067 +10187381 +13508490 +619394 +10595823 +5941268 +5364626 +5833340 +3515364 +15494619 +387531 +5464083 +16718769 +11398805 +14503371 +11152041 +4459725 +10233112 +3716958 +11102904 +736014 +3687601 +1645230 +14666383 +1463029 +16034763 +12793639 +16464275 +13339301 +9505004 +6597336 +14721151 +2338223 +10099725 +13438216 +13385093 +10830645 +5011765 +7730597 +2948550 +7278575 +8596853 +8384675 +12088433 +14861032 +3106566 +2038960 +13911582 +15409117 +4869412 +3143181 +221444 +7020049 +9954050 +6118535 +7566430 +3452698 +3742627 +2039315 +12487483 +8381618 +2224047 +8408502 +16320031 +9138432 +13467997 +1652218 +2403476 +11457495 +10271031 +9040902 +10141 +5694274 +13939467 +11758547 +12662900 +5702313 +4349580 +14563572 +1768986 +13418849 +8516962 +6331125 +14927893 +14148379 +10901773 +102320 +3449370 +13120845 +5637436 +8384598 +16036537 +15461972 +1593284 +8490324 +4898427 +2608002 +15196020 +14096601 +8654556 +435050 +5864881 +12805807 +1128948 +5292229 +10171299 +12799538 +15058722 +4388316 +2447001 +10734792 +5150840 +702201 +1338501 +12853198 +8859234 +5237057 +6707417 +7286047 +806453 +11365563 +3911752 +15003262 +978773 +4857010 +2658915 +1643690 +9221563 +14176703 +16438255 +417178 +3267332 +10876678 +6979138 +15653463 +14330098 +8634673 +3041747 +10646518 +12379428 +2931518 +6331709 +11807228 +8359786 +12915228 +14100185 +1220320 +10892467 +15704738 +10656851 +14294311 +4671627 +16585702 +3206204 +5150182 +3096907 +11696190 +4953380 +14820911 +2678164 +3861959 +14626932 +12525598 +5575328 +12539090 +14291039 +1055532 +895917 +7946222 +8378229 +7869718 +8611940 +6120186 +6300425 +4080483 +13173893 +12802320 +3925137 +5404764 +9741433 +2223341 +5365373 +894759 +14630106 +16046891 +10137554 +12507648 +9081776 +13163953 +13409779 +4090813 +2762572 +16144219 +680618 +12074449 +13028165 +1794953 +9356257 +1874044 +2486102 +11131456 +5102824 +13320341 +7794542 +3996978 +14149575 +14050720 +5087306 +11904819 +3576899 +3772012 +4282421 +10740655 +8631258 +1511365 +14459598 +5624430 +587742 +5949572 +5162007 +5951128 +9834353 +16673148 +12009290 +5020398 +14308906 +14382545 +7361051 +14171639 +6667797 +8382680 +12085689 +3105082 +4702816 +10175392 +12433378 +7208071 +12196958 +15175788 +1802950 +12316216 +15552156 +2243570 +139983 +6340694 +1373856 +14771655 +10567951 +12263416 +14737882 +9614368 +8123228 +9303226 +11587088 +1868686 +7522030 +1981688 +4585103 +10898805 +866968 +14755233 +3716656 +9224731 +10631708 +8110985 +6419107 +1997362 +7273331 +1089290 +13253926 +16003433 +6651018 +6021539 +16640541 +1794034 +7413168 +266500 +6699903 +13330602 +11591334 +14781455 +576869 +7662529 +13050638 +1789194 +11637120 +15969448 +13698928 +6254690 +9907115 +14658170 +14459338 +10946952 +13093540 +16392096 +1641468 +6603843 +13463881 +12209561 +7613474 +655640 +4861674 +8623013 +11981630 +7199517 +8574885 +4694830 +14570222 +16569455 +5857706 +15736965 +5420162 +2801609 +4419998 +9992089 +14641304 +8081118 +15195279 +11316161 +1653106 +15922534 +6605709 +1579825 +11024486 +9757718 +12986865 +3448826 +3238084 +2374229 +36425 +4999217 +11384401 +8645806 +10185979 +14873202 +3056011 +4043742 +13712348 +6770368 +12593072 +5819905 +6283313 +11763192 +11860374 +7592399 +15083595 +5105876 +2965332 +315799 +4934607 +4516576 +1098131 +2346648 +8674469 +14582200 +2438101 +5568480 +3085784 +2282786 +6699929 +11976046 +984646 +845179 +2771684 +7886944 +12412154 +10151782 +4867151 +6697721 +4383742 +11821338 +16341426 +1016458 +1175100 +5719626 +5336982 +5119432 +14986399 +4794790 +10774874 +15049204 +13512308 +10081175 +14765907 +1767467 +10339506 +7962725 +12481186 +12777225 +7272720 +9881260 +16407748 +15774944 +11046423 +14441780 +10695573 +16336800 +14624655 +439734 +232219 +3478292 +4488123 +275394 +12507772 +16613107 +14413507 +5666483 +3112858 +12626007 +11271049 +6268322 +7440888 +4771369 +1734521 +15785029 +14830350 +2543992 +5012211 +13022376 +1066067 +5187620 +13824624 +2603364 +14174923 +11139848 +2945313 +4102264 +7937050 +6134775 +14377668 +16536749 +7261973 +8997498 +8670225 +14753966 +5326704 +9828101 +4759034 +14099495 +5875218 +8876668 +14929347 +9411115 +14526749 +10334495 +13573319 +6295686 +14712644 +11485739 +10006317 +2187593 +10084543 +6757616 +7415683 +4254691 +4822912 +11914205 +8695813 +9050142 +13965289 +3754286 +16113877 +4427605 +13967359 +10665407 +10274753 +8975527 +423562 +14250957 +3034911 +6106605 +7838609 +8153308 +12548976 +4499245 +11228396 +1969821 +1679033 +8251675 +13783478 +10104380 +10973556 +2176312 +2992516 +10735957 +12650491 +3360018 +10999101 +5807116 +5943359 +10454876 +3294643 +11048328 +11163431 +12759477 +9848127 +13612571 +619854 +12060571 +633535 +12713836 +9888083 +7395327 +7516309 +15903815 +2452089 +14950380 +9018073 +3824096 +10990383 +5629416 +2404004 +16603942 +12313682 +726765 +7645152 +6850396 +10280038 +8358501 +3546501 +1765303 +10750382 +2032566 +11336928 +8184211 +14574166 +8488236 +15572596 +2045228 +520444 +7370638 +4451709 +13372806 +1200516 +8370671 +11385142 +9546445 +3068793 +5249423 +3392585 +2967038 +5636851 +10286672 +10589104 +8120856 +9294815 +13214067 +7224450 +5293130 +650079 +3810724 +1577030 +64924 +11064759 +2819425 +7176539 +14470567 +9862657 +2982655 +16667597 +5520159 +1883766 +14777173 +3467822 +8168831 +1678533 +2595737 +8871620 +4112266 +2838306 +7876550 +4792354 +1002626 +1536734 +16247298 +15958731 +700395 +13076408 +2763749 +4579466 +11455051 +10536161 +7977525 +1762747 +15780302 +9356875 +10853833 +11268831 +6351718 +12979818 +1192236 +10355833 +11665362 +11606629 +1482297 +10128153 +9019884 +1790716 +543075 +6655184 +13681783 +11704326 +3160296 +3391971 +10147459 +10266207 +3708532 +15130936 +1858683 +6951736 +313340 +10968282 +15825990 +13787468 +2721444 +4938527 +13177161 +10464583 +4824371 +14967626 +2454078 +16621996 +10248146 +10724212 +14453894 +13776118 +3726140 +222931 +9874023 +5762517 +5273170 +6814273 +382180 +9114408 +16116143 +14801873 +1953138 +2498178 +16682522 +7198862 +743650 +6126543 +13443237 +10618527 +10839606 +6281491 +13909463 +16748505 +15225580 +9339308 +9348584 +1499845 +7089557 +10190584 +15587797 +2291378 +15436500 +15271708 +5387112 +7655083 +5682815 +14148223 +15845303 +11580415 +2373803 +4342197 +15547161 +12611557 +13463470 +15539272 +13477260 +2928809 +9384172 +1258576 +14642816 +7145079 +10849272 +11253187 +6809672 +3165038 +4490328 +15576555 +1855510 +1128354 +16214090 +9918034 +11643808 +227448 +6659215 +6659339 +15069076 +7282715 +7042877 +13571556 +2296909 +12099895 +11986799 +4446325 +2514087 +5296233 +67601 +15600975 +2698306 +8790962 +8822518 +16565229 +11591768 +3184769 +15534740 +3655845 +12616916 +2669864 +5606755 +2013469 +14893127 +16358906 +11099819 +15697107 +11718286 +8304657 +14636309 +9451383 +16345626 +8688604 +15004358 +9005265 +2264356 +7847177 +6806724 +12794642 +15482847 +15263111 +816274 +12566890 +7438331 +7243777 +2640005 +5811476 +1747971 +9135963 +463668 +12035136 +11343 +1582344 +4694042 +7943662 +14280956 +10105070 +11558815 +9605283 +13537588 +879586 +8854728 +14898480 +13465144 +3053879 +2414840 +9698473 +9466946 +8655573 +2833286 +8102241 +2878322 +8561747 +10981673 +11766998 +11307517 +14082102 +310065 +3965194 +10697972 +8537450 +12020005 +2960939 +939422 +10987346 +11535712 +498200 +150953 +9458584 +12943422 +3505101 +300878 +7066798 +11802785 +7441721 +15615994 +9509241 +13891249 +16553903 +6912302 +15303979 +14450177 +10079378 +13262460 +10059573 +9606733 +16646865 +4908537 +14357902 +4334989 +8306884 +88016 +211675 +13580302 +2254556 +607951 +9195297 +13989519 +5785635 +652822 +5466414 +15768564 +12676608 +16773321 +4778239 +14352985 +2326367 +15565462 +16724582 +1287877 +7542580 +4778699 +9913950 +5893073 +12153205 +2585840 +13885225 +11714550 +7979385 +3973797 +1535439 +13957514 +16666132 +8216876 +1885784 +15215180 +12402098 +6880348 +2257414 +7019116 +12644695 +15768922 +12102619 +5877532 +8296511 +6200023 +10734632 +2646398 +1516458 +6342503 +987995 +5664664 +16490182 +1055004 +3474519 +14825216 +5843738 +10480400 +3549222 +13607176 +9737300 +13394330 +4012881 +270960 +9551964 +12577181 +16399769 +14387253 +12767897 +11643144 +9404471 +15879872 +942627 +10862247 +11471960 +16153925 +11709603 +12874977 +946450 +5986766 +2874570 +7308869 +4019533 +901235 +1199908 +8848228 +9335362 +8605367 +12828289 +1728584 +7004694 +9568779 +2772066 +9222399 +14182584 +5483926 +6755484 +11347391 +2377444 +6512351 +8608146 +13444858 +11017248 +14227013 +15375333 +9367710 +13487125 +9723235 +7377255 +8059866 +14544858 +1950135 +8055517 +14835230 +9143501 +8710800 +12720731 +1421048 +10290701 +6435515 +11604786 +14669169 +8358416 +16064269 +7541177 +12717933 +13727023 +10080921 +5784392 +4911300 +16039810 +14333203 +7538301 +14897815 +10471136 +5301106 +14038503 +940310 +13122596 +11926917 +7295345 +7881920 +3397897 +4533242 +14792321 +3544652 +16471109 +7433775 +1331770 +8659064 +13237795 +9748699 +6205738 +6487640 +5727727 +3021550 +15157080 +7367624 +8592720 +15689290 +5150200 +324891 +15295198 +2853330 +5649370 +12005641 +5957674 +12102682 +14317587 +13373339 +2979874 +14918374 +14655877 +5428446 +17362 +4823223 +6472536 +1008933 +8935857 +1630183 +9839899 +143477 +9985951 +9606850 +9290512 +6142205 +6157197 +12030577 +13326147 +10026395 +10785209 +5122807 +8623469 +720935 +2400372 +1938935 +12972194 +7904245 +5344792 +10219804 +10473408 +1861580 +4824344 +8621530 +6336361 +11893901 +5367437 +15132563 +13379169 +1068479 +4924354 +1354757 +10130218 +1412812 +9215048 +9072453 +5207590 +8959460 +5772454 +16270646 +10740724 +6744007 +2909454 +2196154 +10531202 +7832037 +3817884 +10071214 +4930033 +478299 +7460507 +11674176 +12341841 +10850905 +1903744 +1192942 +15704179 +5199634 +5091619 +16083965 +11883102 +9572459 +11111678 +15813769 +6480234 +3780192 diff --git a/third_party/rust/clubcard/examples/uint_no_partition/generate_test.py b/third_party/rust/clubcard/examples/uint_no_partition/generate_test.py new file mode 100644 index 000000000000..2ae7ef680b22 --- /dev/null +++ b/third_party/rust/clubcard/examples/uint_no_partition/generate_test.py @@ -0,0 +1,17 @@ +import sys +from numpy.random import randint; + +ARGV = sys.argv +FILENAME = ARGV[1] if len(ARGV) >= 2 else "input.txt" + +MAX = (1 << 24) +LEN = 2000 + +file = open(FILENAME, "w") +file.write(str(LEN) + "\n") +for num in range(LEN): + file.write(str(randint(0, MAX)) + "\n") + +file.close() + +print("Generate {} numbers within range [0, {}].".format(LEN, MAX)) diff --git a/third_party/rust/clubcard/examples/uint_no_partition/main.rs b/third_party/rust/clubcard/examples/uint_no_partition/main.rs new file mode 100644 index 000000000000..fce4c156477c --- /dev/null +++ b/third_party/rust/clubcard/examples/uint_no_partition/main.rs @@ -0,0 +1,157 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +/// Compress a set of u32 integers and output the (approximate) size of compressed bytes. +/// # Arguments +/// +/// * `filepath` - The input file containing integers in range [0, max(a_i)]. +/// ```txt +/// a_1 \n +/// ... +/// a_n \n +/// ``` +/// The universe size will be the maximum value of the input file. +/// +/// # Usage +/// +/// To run this example, use the following command: +/// ```bash +/// cargo run --features builder --example uint_no_partition +/// ``` +/// + +use clubcard::*; +use sha2::{Digest, Sha256}; +use std::cmp::max; +use std::collections::HashSet; +use std::{env, fs, io, process}; +use std::io::BufRead; +use clubcard::builder::{ApproximateRibbon, ClubcardBuilder, ExactRibbon}; + +struct Universe { + bound: u32, +} +const W: usize = 4; +const BLOCK: [u8; 0] = []; + +struct Int { + val: [u8; 4], // u32 + included: bool, // whether it's in the subset +} + +impl Int { + fn new(num: u32, included: bool) -> Int { + Int { + val: num.to_le_bytes(), + included, + } + } +} + +impl ApproximateSizeOf for Universe {} + +impl AsQuery for Int { + fn as_query(&self, m: usize) -> Equation { + let mut digest = [0u8; 32]; + let mut hasher = Sha256::new(); + hasher.update(&self.val); + hasher.finalize_into((&mut digest).into()); + + let mut a = [0u64; W]; // block of columns + for (i, x) in digest + .chunks_exact(8) + .map(|x| TryInto::<[u8; 8]>::try_into(x).unwrap()) + .map(u64::from_le_bytes) + .enumerate() + { + a[i] = x; + } + + a[0] |= 1; + let s = (a[W - 1] as usize) % max(1, m); // + let b = if self.included { 0 } else { 1 }; + Equation::inhomogeneous(s, a, b) + } + + fn block(&self) -> &[u8] { + &BLOCK + } + + fn discriminant(&self) -> &[u8] { + &self.val + } +} + +impl Filterable for Int { + fn included(&self) -> bool { + self.included + } +} + +impl Queryable for Int { + type UniverseMetadata = Universe; + type PartitionMetadata = (); + + fn in_universe(&self, meta: &Self::UniverseMetadata) -> bool { + u32::from_le_bytes(self.val) < meta.bound + } +} + +// Parse the file into a set of integers, return the hash set and maximum element + 1 in set +fn parse_args() -> (u32, HashSet) { + let args: Vec = env::args().collect(); + + if args.len() < 2 { + println!("Please specify the name of input file."); + process::exit(1); + } + let file_path = &args[1]; + let file = fs::File::open(file_path).expect("Error opening the file."); + let mut lines = io::BufReader::new(file).lines(); + + let mut numbers = HashSet::new(); + let mut max_val = 0; + + while let Some(Ok(line)) = lines.next() { + let number = line.trim().parse::().expect("Failed to parse 32-bit integer"); + if number > max_val { + max_val = number; + } + numbers.insert(number); + } + + (max_val + 1, numbers) +} + +fn main() { + let (universe_size, numbers) = parse_args(); + + let mut clubcard_builder = ClubcardBuilder::new(); + let mut approx_builder = clubcard_builder.new_approx_builder(&BLOCK); + + // Build approx filter + for num in &numbers { + let int = Int::new(num.clone(), true); + approx_builder.insert(int) + } + approx_builder.set_universe_size(universe_size.try_into().unwrap()); + clubcard_builder.collect_approx_ribbons(vec![ApproximateRibbon::from(approx_builder)]); + + // Build exact filter + let mut exact_builder = clubcard_builder.new_exact_builder(&BLOCK); + for num in 0..universe_size { + let int = Int::new(num.clone(), numbers.contains(&num)); + exact_builder.insert(int); + } + clubcard_builder.collect_exact_ribbons(vec![ExactRibbon::from(exact_builder)]); + + let clubcard = clubcard_builder.build::( + Universe { bound: universe_size }, + (), + ); + + println!("Generated {}", clubcard); + println!("The size of compressed set (of {} elements) with max value {} is {} bytes.", + numbers.len(), universe_size - 1, clubcard.approximate_size_of()); +} \ No newline at end of file diff --git a/third_party/rust/clubcard/src/builder.rs b/third_party/rust/clubcard/src/builder.rs index 5e251e65dd5a..296e7a7527ae 100644 --- a/third_party/rust/clubcard/src/builder.rs +++ b/third_party/rust/clubcard/src/builder.rs @@ -388,14 +388,22 @@ impl, ApproxOrExact> From 1 { + // randomizing the tail increases the odds that the solutions will be distinct + tail.push(thread_rng().gen::()); + } for j in (0..blocks.len()).rev() { if blocks[j].rank > i { tail = blocks[j].solve(&tail); } } + while let Some(0) = tail.last() { + tail.pop(); + } solution.push(tail); } diff --git a/third_party/rust/clubcard/src/clubcard.rs b/third_party/rust/clubcard/src/clubcard.rs index 5a4cadace0d3..3e4424438369 100644 --- a/third_party/rust/clubcard/src/clubcard.rs +++ b/third_party/rust/clubcard/src/clubcard.rs @@ -75,12 +75,12 @@ impl fmt::Display .sum::(); writeln!( f, - "Clubcard of size {} ({} + {})", + "Clubcard of size {} ({} + {}) with {} exceptions", approx_size + exact_size, approx_size, - exact_size - )?; - writeln!(f, "- exceptions: {}", exceptions) + exact_size, + exceptions + ) } } @@ -154,6 +154,10 @@ impl pub fn partition(&self) -> &PartitionMetadata { &self.partition } + + pub fn index(&self) -> &ClubcardIndex { + &self.index + } } /// Helper trait for (approximate) heap memory usage analysis in Firefox @@ -184,7 +188,9 @@ where self.universe.approximate_size_of() + self.partition.approximate_size_of() + self.index.approximate_size_of() - + self.approx_filter.iter().map(|x| x.len()).sum::() - + self.exact_filter.len() + + size_of::>>() + + 8 * self.approx_filter.iter().map(|x| x.len()).sum::() + + size_of::>() + + 8 * self.exact_filter.len() } } diff --git a/third_party/rust/clubcard/src/lib.rs b/third_party/rust/clubcard/src/lib.rs index 79034aebf0ca..25f80b88b584 100644 --- a/third_party/rust/clubcard/src/lib.rs +++ b/third_party/rust/clubcard/src/lib.rs @@ -44,7 +44,7 @@ pub mod builder; mod clubcard; -pub use clubcard::{ApproximateSizeOf, Clubcard, ClubcardIndexEntry, Membership}; +pub use clubcard::{ApproximateSizeOf, Clubcard, ClubcardIndex, ClubcardIndexEntry, Membership}; mod equation; pub use equation::Equation;