From bd9e51831ff4b6a6eea14ad52eccbc8c9baec429 Mon Sep 17 00:00:00 2001 From: AmirSaber Sharifi Date: Mon, 1 Nov 2021 11:54:41 -0500 Subject: [PATCH] Bump ristretto (#62) --- .github/workflows/audit.yml | 17 +++ .github/workflows/ci.yml | 29 ++++ .github/workflows/clippy.yml | 23 +++ Cargo.lock | 261 ++++++++++++----------------------- Cargo.toml | 10 +- src/lib.rs | 81 +++-------- 6 files changed, 181 insertions(+), 240 deletions(-) create mode 100644 .github/workflows/audit.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/clippy.yml diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 0000000..f788876 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,17 @@ +name: Cargo audit +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + security_audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/audit-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..af5ebe7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: "CI" + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + ci: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + components: rustfmt, clippy + - name: Install dependencies + run: cargo install --force cargo-audit cbindgen + - name: Build & Test + run: cargo build && cargo test \ No newline at end of file diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..c31cbbf --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,23 @@ +on: + push: + branches: + - master + pull_request: + branches: + - master + +name: Clippy check +jobs: + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + override: true + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: -- -D warnings -A clippy::missing_safety_doc \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 0661e59..b30bfe8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,10 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +version = 3 [[package]] name = "base64" @@ -17,38 +13,20 @@ dependencies = [ ] [[package]] -name = "bitflags" -version = "1.2.1" +name = "base64" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "block-buffer" -version = "0.7.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", - "byte-tools", - "byteorder", "generic-array", ] -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", -] - -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - [[package]] name = "byteorder" version = "1.4.2" @@ -61,13 +39,19 @@ version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "challenge-bypass-ristretto" -version = "1.0.0-pre.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38890f7cb7e8640554535274bdd16748eb882cce132a944da79f916e40e63f37" +checksum = "a439d42c1cc301fb1a248114b56388e447ac1a9afed7bfb1424ae2f4c26f92c7" dependencies = [ - "base64", + "base64 0.13.0", "clear_on_drop", "crypto-mac", "curve25519-dalek", @@ -75,13 +59,15 @@ dependencies = [ "hmac", "rand", "rand_chacha", + "rand_core", + "subtle", ] [[package]] name = "challenge-bypass-ristretto-ffi" -version = "1.0.0-pre.2" +version = "1.0.0-pre.4" dependencies = [ - "base64", + "base64 0.9.3", "challenge-bypass-ristretto", "hmac", "rand", @@ -98,72 +84,72 @@ dependencies = [ ] [[package]] -name = "cloudabi" -version = "0.0.3" +name = "cpufeatures" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" dependencies = [ - "bitflags", + "libc", ] [[package]] name = "crypto-mac" -version = "0.7.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a" dependencies = [ "generic-array", - "subtle 1.0.0", + "subtle", ] [[package]] name = "curve25519-dalek" -version = "1.2.6" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d59fed08e452f286b251f88b2fc64a01f50a7b263aa09557ad7285d9e7fa" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", - "clear_on_drop", "digest", - "rand_core 0.3.1", - "subtle 2.4.0", + "rand_core", + "subtle", + "zeroize", ] [[package]] name = "digest" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ "generic-array", ] [[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" +name = "generic-array" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] [[package]] -name = "generic-array" -version = "0.12.4" +name = "getrandom" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "typenum", + "cfg-if", + "libc", + "wasi", ] [[package]] name = "hmac" -version = "0.7.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ "crypto-mac", "digest", @@ -171,129 +157,61 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.87" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" +checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" [[package]] name = "opaque-debug" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "ppv-lite86" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" [[package]] name = "rand" -version = "0.6.5" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "autocfg", + "getrandom", "libc", "rand_chacha", - "rand_core 0.4.2", + "rand_core", "rand_hc", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi", ] [[package]] name = "rand_chacha" -version = "0.1.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "autocfg", - "rand_core 0.3.1", + "ppv-lite86", + "rand_core", ] [[package]] name = "rand_core" -version = "0.3.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "rand_core 0.4.2", + "getrandom", ] -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_hc" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", + "rand_core", ] [[package]] @@ -304,22 +222,17 @@ checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" [[package]] name = "sha2" -version = "0.8.2" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer", + "cfg-if", + "cpufeatures", "digest", - "fake-simd", "opaque-debug", ] -[[package]] -name = "subtle" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" - [[package]] name = "subtle" version = "2.4.0" @@ -333,23 +246,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] -name = "winapi" -version = "0.3.9" +name = "version_check" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "zeroize" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "bf68b08513768deaa790264a7fac27a58cbf2705cfcdc9448362229217d7e970" diff --git a/Cargo.toml b/Cargo.toml index 3b9eabd..bee1c5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,14 @@ [package] authors = ["eV "] name = "challenge-bypass-ristretto-ffi" -version = "1.0.0-pre.3" +version = "1.0.0-pre.4" [dependencies] base64 = "0.9.3" -challenge-bypass-ristretto = { version = "1.0.0-pre.0", features = ["base64"] } -hmac = "0.7" -rand = "0.6.0" -sha2 = "0.8" +challenge-bypass-ristretto = { version = "1.0.0", features = ["base64"] } +hmac = "0.10" +rand = "0.7" +sha2 = "0.9" [lib] crate-type = [ diff --git a/src/lib.rs b/src/lib.rs index c3d4830..df32cd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,16 +121,9 @@ impl_base64!( /// done with it. #[no_mangle] pub unsafe extern "C" fn token_random() -> *mut Token { - match OsRng::new() { - Ok(mut rng) => { - let token = Token::random::(&mut rng); - Box::into_raw(Box::new(token)) - } - Err(err) => { - update_last_error(err); - ptr::null_mut() - } - } + let mut rng = OsRng; + let token = Token::random::(&mut rng); + Box::into_raw(Box::new(token)) } /// Destroy a `Token` once you are done with it. @@ -310,16 +303,9 @@ impl_base64!( /// done with it. #[no_mangle] pub unsafe extern "C" fn signing_key_random() -> *mut SigningKey { - match OsRng::new() { - Ok(mut rng) => { - let key = SigningKey::random(&mut rng); - Box::into_raw(Box::new(key)) - } - Err(err) => { - update_last_error(err); - ptr::null_mut() - } - } + let mut rng = OsRng; + let key = SigningKey::random(&mut rng); + Box::into_raw(Box::new(key)) } /// Destroy a `SigningKey` once you are done with it. @@ -416,21 +402,10 @@ pub unsafe extern "C" fn dleq_proof_new( key: *const SigningKey, ) -> *mut DLEQProof { if !blinded_token.is_null() && !signed_token.is_null() && !key.is_null() { - match OsRng::new() { - Ok(mut rng) => { - match DLEQProof::new::( - &mut rng, - &*blinded_token, - &*signed_token, - &*key, - ) { - Ok(proof) => return Box::into_raw(Box::new(proof)), - Err(err) => update_last_error(err), - } - } - Err(err) => { - update_last_error(err); - } + let mut rng = OsRng; + match DLEQProof::new::(&mut rng, &*blinded_token, &*signed_token, &*key) { + Ok(proof) => return Box::into_raw(Box::new(proof)), + Err(err) => update_last_error(err), } return ptr::null_mut(); } @@ -514,30 +489,18 @@ pub unsafe extern "C" fn batch_dleq_proof_new( key: *const SigningKey, ) -> *mut BatchDLEQProof { if !blinded_tokens.is_null() && !signed_tokens.is_null() && !key.is_null() { - match OsRng::new() { - Ok(mut rng) => { - let blinded_tokens: &[*const BlindedToken] = - slice::from_raw_parts(blinded_tokens, tokens_length as usize); - let blinded_tokens: Vec = - blinded_tokens.iter().map(|p| **p).collect(); - let signed_tokens: &[*const SignedToken] = - slice::from_raw_parts(signed_tokens, tokens_length as usize); - let signed_tokens: Vec = signed_tokens.iter().map(|p| **p).collect(); - - match BatchDLEQProof::new::( - &mut rng, - &blinded_tokens, - &signed_tokens, - &*key, - ) { - Ok(proof) => return Box::into_raw(Box::new(proof)), - Err(err) => update_last_error(err), - } - } - Err(err) => { - update_last_error(err); - return ptr::null_mut(); - } + let mut rng = OsRng; + let blinded_tokens: &[*const BlindedToken] = + slice::from_raw_parts(blinded_tokens, tokens_length as usize); + let blinded_tokens: Vec = blinded_tokens.iter().map(|p| **p).collect(); + let signed_tokens: &[*const SignedToken] = + slice::from_raw_parts(signed_tokens, tokens_length as usize); + let signed_tokens: Vec = signed_tokens.iter().map(|p| **p).collect(); + + match BatchDLEQProof::new::(&mut rng, &blinded_tokens, &signed_tokens, &*key) + { + Ok(proof) => return Box::into_raw(Box::new(proof)), + Err(err) => update_last_error(err), } } update_last_error("Pointer to blinded tokens, signed tokens or signing key was null");