Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 384207a

Browse files
authoredApr 1, 2022
General Improvements (facebook#268)
* Move `elliptic-curve` implementation to points to allow `Zeroize` * Simplify `Ristretto255::random_scalar` implementation * Fix `Ristretto255` deserialization * Remove unnecessary check in `Ristretto255::random_scalar` * Base `X25519` implementation on `curve25519-dalek` * Constrain public and secret key to `Copy` * Replace manual `ZeroizeOnDrop` implementation with `derive` * Update dependencies * Add `warn(unused_crate_dependencies)` * Sync crate feature naming with `voprf` * Remove unnecessary dependency crate features * Never produce a zero scalar * Rename `OprfGroup` to `OprfCs` * Rename `TripleDH` to `TripleDh` * Remove `slow-hash` crate feature * Rename `NoOpHash` to `Identity` * Rename `SlowHash` to `Ksf` * Move `KeyExchange` type definitions down * Deserialize secret and public keys from slices * Remove `PrivateKey::from_bytes` * Rename `From/ToBytes` to `De/Serialize` * Re-export `serde_` as `serde` * Custom `De/Serialize` implementation for keys * Remove custom `De/Serialize` implementation * Run Taplo v0.6
1 parent f952a26 commit 384207a

25 files changed

+848
-1108
lines changed
 

‎.github/workflows/main.yml

+33-33
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
backend_feature:
16-
- --features ristretto255_u64,ristretto255_voprf
17-
- --features ristretto255_u32,ristretto255_voprf
18-
-
19-
- --features x25519_u64,ristretto255_u64,ristretto255_voprf
20-
- --features x25519_u32,ristretto255_u32,ristretto255_voprf
21-
- --features x25519_u64
22-
- --features x25519_u32
16+
- --features ristretto255-u64,ristretto255-voprf
17+
- --features ristretto255-u32,ristretto255-voprf
18+
-
19+
- --features x25519-u64,ristretto255-u64,ristretto255-voprf
20+
- --features x25519-u32,ristretto255-u32,ristretto255-voprf
21+
- --features x25519-u64
22+
- --features x25519-u32
2323
frontend_feature:
24-
-
25-
- --features slow-hash
24+
-
25+
- --features argon2
2626
- --features serde
2727
toolchain:
2828
- stable
@@ -61,13 +61,13 @@ jobs:
6161
# 32-bit x86
6262
- i686-unknown-linux-gnu
6363
backend_feature:
64-
- --features ristretto255_u64,ristretto255_voprf
65-
- --features ristretto255_u32,ristretto255_voprf
66-
-
67-
- x25519_u64,ristretto255_u64,ristretto255_voprf
68-
- x25519_u32,ristretto255_u64,ristretto255_voprf
69-
- x25519_u64
70-
- x25519_u32
64+
- --features ristretto255-u64,ristretto255-voprf
65+
- --features ristretto255-u32,ristretto255-voprf
66+
-
67+
- x25519-u64,ristretto255-u64,ristretto255-voprf
68+
- x25519-u32,ristretto255-u64,ristretto255-voprf
69+
- x25519-u64
70+
- x25519-u32
7171
steps:
7272
- uses: actions/checkout@v2
7373
- uses: hecrj/setup-rust-action@v1
@@ -135,15 +135,15 @@ jobs:
135135
# for any no_std target
136136
- thumbv6m-none-eabi
137137
backend_feature:
138-
- ristretto255_u64,ristretto255_voprf
139-
- ristretto255_u32,ristretto255_voprf
140-
-
141-
- x25519_u64,ristretto255_u64,ristretto255_voprf
142-
- x25519_u32,ristretto255_u32,ristretto255_voprf
143-
- x25519_u64
144-
- x25519_u32
138+
- ristretto255-u64,ristretto255-voprf
139+
- ristretto255-u32,ristretto255-voprf
140+
-
141+
- x25519-u64,ristretto255-u64,ristretto255-voprf
142+
- x25519-u32,ristretto255-u32,ristretto255-voprf
143+
- x25519-u64
144+
- x25519-u32
145145
frontend_feature:
146-
- slow-hash
146+
- argon2
147147
- serde
148148
steps:
149149
- uses: actions/checkout@v2
@@ -158,13 +158,13 @@ jobs:
158158
fail-fast: false
159159
matrix:
160160
backend_feature:
161-
- --features ristretto255_u64,ristretto255_voprf
162-
- --features ristretto255_u32,ristretto255_voprf
163-
-
164-
- --features x25519_u64,ristretto255_u64,ristretto255_voprf
165-
- --features x25519_u32,ristretto255_u32,ristretto255_voprf
166-
- --features x25519_u32
167-
- --features x25519_u32
161+
- --features ristretto255-u64,ristretto255-voprf
162+
- --features ristretto255-u32,ristretto255-voprf
163+
-
164+
- --features x25519-u64,ristretto255-u64,ristretto255-voprf
165+
- --features x25519-u32,ristretto255-u32,ristretto255-voprf
166+
- --features x25519-u32
167+
- --features x25519-u32
168168
steps:
169169
- name: Checkout sources
170170
uses: actions/checkout@v2
@@ -201,15 +201,15 @@ jobs:
201201
uses: actions-rs/cargo@v1
202202
with:
203203
command: clippy
204-
args: --all-targets --features slow-hash,std,x25519_u64 -- -D warnings
204+
args: --all-targets --features argon2,std,x25519-u64 -- -D warnings
205205

206206
- name: Run cargo doc
207207
uses: actions-rs/cargo@v1
208208
env:
209209
RUSTDOCFLAGS: -D warnings
210210
with:
211211
command: doc
212-
args: --no-deps --document-private-items --features slow-hash,std,x25519_u64
212+
args: --no-deps --document-private-items --features argon2,std,x25519-u64
213213

214214
format:
215215
name: cargo fmt

‎Cargo.toml

+18-35
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,33 @@ rust-version = "1.57"
1212
version = "2.0.0-pre.1"
1313

1414
[features]
15-
default = ["ristretto255_u64", "ristretto255_voprf", "serde"]
15+
default = ["ristretto255-u64", "ristretto255-voprf", "serde"]
1616
ristretto255 = ["curve25519-dalek", "voprf/ristretto255"]
17-
ristretto255_fiat_u32 = ["curve25519-dalek/fiat_u32_backend", "ristretto255"]
18-
ristretto255_fiat_u64 = ["curve25519-dalek/fiat_u64_backend", "ristretto255"]
19-
ristretto255_simd = ["curve25519-dalek/simd_backend", "ristretto255"]
20-
ristretto255_u32 = ["curve25519-dalek/u32_backend", "ristretto255"]
21-
ristretto255_u64 = ["curve25519-dalek/u64_backend", "ristretto255"]
22-
ristretto255_voprf = ["ristretto255", "voprf/ristretto255-ciphersuite"]
17+
ristretto255-fiat-u32 = ["curve25519-dalek/fiat_u32_backend", "ristretto255"]
18+
ristretto255-fiat-u64 = ["curve25519-dalek/fiat_u64_backend", "ristretto255"]
19+
ristretto255-simd = ["curve25519-dalek/simd_backend", "ristretto255"]
20+
ristretto255-u32 = ["curve25519-dalek/u32_backend", "ristretto255"]
21+
ristretto255-u64 = ["curve25519-dalek/u64_backend", "ristretto255"]
22+
ristretto255-voprf = ["ristretto255", "voprf/ristretto255-ciphersuite"]
2323
serde = ["serde_", "generic-array/serde", "voprf/serde"]
24-
slow-hash = ["argon2"]
25-
std = ["getrandom", "rand/std", "rand/std_rng", "voprf/std"]
26-
x25519 = ["curve25519-dalek-3"]
27-
x25519_fiat_u32 = ["x25519", "x25519-dalek/fiat_u32_backend"]
28-
x25519_fiat_u64 = ["x25519", "x25519-dalek/fiat_u64_backend"]
29-
# x25519-dalek isn't properly re-exposing `simd_backend`.
30-
x25519_simd = [
31-
"curve25519-dalek-3/simd_backend",
32-
"x25519",
33-
"x25519-dalek/nightly",
34-
]
35-
x25519_u32 = ["x25519", "x25519-dalek/u32_backend"]
36-
x25519_u64 = ["x25519", "x25519-dalek/u64_backend"]
24+
std = ["getrandom"]
25+
x25519 = ["curve25519-dalek"]
26+
x25519-fiat-u32 = ["curve25519-dalek/fiat_u32_backend", "x25519"]
27+
x25519-fiat-u64 = ["curve25519-dalek/fiat_u64_backend", "x25519"]
28+
x25519-simd = ["curve25519-dalek/simd_backend", "x25519"]
29+
x25519-u32 = ["curve25519-dalek/u32_backend", "x25519"]
30+
x25519-u64 = ["curve25519-dalek/u64_backend", "x25519"]
3731

3832
[dependencies]
39-
argon2 = { version = "0.3", default-features = false, features = [
33+
argon2 = { version = "0.4", default-features = false, features = [
4034
"alloc",
4135
], optional = true }
42-
constant_time_eq = "0.1"
4336
curve25519-dalek = { version = "=4.0.0-pre.1", default-features = false, optional = true }
44-
curve25519-dalek-3 = { version = "3", package = "curve25519-dalek", default-features = false, optional = true }
4537
derive-where = { version = "=1.0.0-rc.3", features = ["zeroize-on-drop"] }
4638
digest = "0.10"
4739
displaydoc = { version = "0.2", default-features = false }
4840
elliptic-curve = { version = "0.12.0-pre.1", features = ["hash2curve", "sec1"] }
4941
generic-array = "0.14"
50-
getrandom = { version = "0.2", optional = true }
5142
hkdf = "0.12"
5243
hmac = "0.12"
5344
rand = { version = "0.8", default-features = false }
@@ -56,20 +47,17 @@ serde_ = { version = "1", package = "serde", default-features = false, features
5647
], optional = true }
5748
subtle = { version = "2.3", default-features = false }
5849
voprf = { version = "0.3", default-features = false, features = ["danger"] }
59-
x25519-dalek = { version = "=2.0.0-pre.1", default-features = false, optional = true }
60-
zeroize = { version = "1", features = ["zeroize_derive"] }
50+
zeroize = { version = "1.5", features = ["zeroize_derive"] }
6151

6252
[target.'cfg(target_arch = "wasm32")'.dependencies]
6353
getrandom = { version = "0.2", features = ["js"], optional = true }
6454

6555
[dev-dependencies]
66-
base64 = "0.13"
6756
bincode = "1"
68-
chacha20poly1305 = "0.9"
57+
chacha20poly1305 = "=0.10.0-pre"
6958
criterion = "0.3"
7059
hex = "0.4"
7160
json = "0.12"
72-
lazy_static = "1"
7361
p256 = { version = "=0.11.0-pre.0", default-features = false, features = [
7462
"hash2curve",
7563
"voprf",
@@ -79,19 +67,14 @@ rand = "0.8"
7967
regex = "1"
8068
rustyline = "9"
8169
serde_json = "1"
82-
sha2 = "0.10"
8370

8471
[[bench]]
8572
harness = false
8673
name = "opaque"
8774

8875
[package.metadata.docs.rs]
89-
features = ["std", "slow-hash", "x25519_u64"]
76+
features = ["argon2", "std", "x25519-u64"]
9077
targets = []
9178

9279
[patch.crates-io]
93-
chacha20 = { git = "https://github.com/RustCrypto/stream-ciphers" }
94-
chacha20poly1305 = { git = "https://github.com/khonsulabs/aeads", branch = "update-dependencies" }
95-
derive-where = { git = "https://github.com/ModProg/derive-where" }
96-
poly1305 = { git = "https://github.com/RustCrypto/universal-hashes" }
9780
voprf = { git = "https://github.com/khonsulabs/voprf", branch = "v08" }

‎benches/opaque.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ use criterion::Criterion;
1212
use opaque_ke::*;
1313
use rand::rngs::OsRng;
1414

15-
#[cfg(feature = "ristretto255_u64")]
16-
static SUFFIX: &str = "ristretto255_u64";
17-
#[cfg(feature = "ristretto255_u32")]
18-
static SUFFIX: &str = "ristretto255_u32";
19-
#[cfg(feature = "ristretto255_fiat_u64")]
20-
static SUFFIX: &str = "ristretto255_fiat_u64";
21-
#[cfg(feature = "ristretto255_fiat_u32")]
22-
static SUFFIX: &str = "ristretto255_fiat_u32";
15+
#[cfg(feature = "ristretto255-u64")]
16+
static SUFFIX: &str = "ristretto255-u64";
17+
#[cfg(feature = "ristretto255-u32")]
18+
static SUFFIX: &str = "ristretto255-u32";
19+
#[cfg(feature = "ristretto255-fiat-u64")]
20+
static SUFFIX: &str = "ristretto255-fiat-u64";
21+
#[cfg(feature = "ristretto255-fiat-u32")]
22+
static SUFFIX: &str = "ristretto255-fiat-u32";
2323
#[cfg(all(not(feature = "ristretto255")))]
2424
static SUFFIX: &str = "p256";
2525

2626
struct Default;
2727

2828
#[cfg(feature = "ristretto255")]
2929
impl CipherSuite for Default {
30-
type OprfGroup = opaque_ke::Ristretto255;
30+
type OprfCs = opaque_ke::Ristretto255;
3131
type KeGroup = opaque_ke::Ristretto255;
32-
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
33-
type SlowHash = opaque_ke::slow_hash::NoOpHash;
32+
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDh;
33+
type Ksf = opaque_ke::ksf::Identity;
3434
}
3535

3636
#[cfg(not(feature = "ristretto255"))]
3737
impl CipherSuite for Default {
38-
type OprfGroup = p256::NistP256;
38+
type OprfCs = p256::NistP256;
3939
type KeGroup = p256::NistP256;
40-
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
41-
type SlowHash = opaque_ke::slow_hash::NoOpHash;
40+
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDh;
41+
type Ksf = opaque_ke::ksf::Identity;
4242
}
4343

4444
fn server_setup(c: &mut Criterion) {

‎examples/digital_locker.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ struct Default;
4949

5050
#[cfg(feature = "ristretto255")]
5151
impl CipherSuite for Default {
52-
type OprfGroup = opaque_ke::Ristretto255;
52+
type OprfCs = opaque_ke::Ristretto255;
5353
type KeGroup = opaque_ke::Ristretto255;
54-
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
55-
type SlowHash = opaque_ke::slow_hash::NoOpHash;
54+
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDh;
55+
type Ksf = opaque_ke::ksf::Identity;
5656
}
5757

5858
#[cfg(not(feature = "ristretto255"))]
5959
impl CipherSuite for Default {
60-
type OprfGroup = p256::NistP256;
60+
type OprfCs = p256::NistP256;
6161
type KeGroup = p256::NistP256;
62-
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
63-
type SlowHash = opaque_ke::slow_hash::NoOpHash;
62+
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDh;
63+
type Ksf = opaque_ke::ksf::Identity;
6464
}
6565

6666
struct Locker {

‎examples/simple_login.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ struct Default;
4343

4444
#[cfg(feature = "ristretto255")]
4545
impl CipherSuite for Default {
46-
type OprfGroup = opaque_ke::Ristretto255;
46+
type OprfCs = opaque_ke::Ristretto255;
4747
type KeGroup = opaque_ke::Ristretto255;
48-
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
49-
type SlowHash = opaque_ke::slow_hash::NoOpHash;
48+
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDh;
49+
type Ksf = opaque_ke::ksf::Identity;
5050
}
5151

5252
#[cfg(not(feature = "ristretto255"))]
5353
impl CipherSuite for Default {
54-
type OprfGroup = p256::NistP256;
54+
type OprfCs = p256::NistP256;
5555
type KeGroup = p256::NistP256;
56-
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
57-
type SlowHash = opaque_ke::slow_hash::NoOpHash;
56+
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDh;
57+
type Ksf = opaque_ke::ksf::Identity;
5858
}
5959

6060
// Password-based registration between a client and server

‎src/ciphersuite.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ use generic_array::typenum::{IsLess, IsLessOrEqual, Le, NonZero, U256};
1515
use crate::hash::{Hash, ProxyHash};
1616
use crate::key_exchange::group::KeGroup;
1717
use crate::key_exchange::traits::KeyExchange;
18-
use crate::slow_hash::SlowHash;
18+
use crate::ksf::Ksf;
1919

2020
/// Configures the underlying primitives used in OPAQUE
21-
/// * `OprfGroup`: a finite cyclic group along with a point representation,
22-
/// along with an extension trait PasswordToCurve that allows some
23-
/// customization on how to hash a password to a curve point. See
24-
/// `group::Group`.
21+
/// * `OprfCs`: A VOPRF ciphersuite, see [`voprf::CipherSuite`].
2522
/// * `KeGroup`: A `Group` used for the `KeyExchange`.
2623
/// * `KeyExchange`: The key exchange protocol to use in the login step
2724
/// * `Hash`: The main hashing function to use
28-
/// * `SlowHash`: A slow hashing function, typically used for password hashing
25+
/// * `Ksf`: A key stretching function, typically used for password hashing
2926
pub trait CipherSuite
3027
where
3128
<OprfHash<Self> as OutputSizeUser>::OutputSize:
@@ -35,17 +32,15 @@ where
3532
<<OprfHash<Self> as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
3633
Le<<<OprfHash<Self> as CoreProxy>::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
3734
{
38-
/// A finite cyclic group along with a point representation along with an
39-
/// extension trait PasswordToCurve that allows some customization on how to
40-
/// hash a password to a curve point. See `group::Group`.
41-
type OprfGroup: voprf::CipherSuite;
35+
/// A VOPRF ciphersuite, see [`voprf::CipherSuite`].
36+
type OprfCs: voprf::CipherSuite;
4237
/// A `Group` used for the `KeyExchange`.
4338
type KeGroup: KeGroup;
4439
/// A key exchange protocol
4540
type KeyExchange: KeyExchange<OprfHash<Self>, Self::KeGroup>;
46-
/// A slow hashing function, typically used for password hashing
47-
type SlowHash: SlowHash;
41+
/// A key stretching function, typically used for password hashing
42+
type Ksf: Ksf;
4843
}
4944

50-
pub(crate) type OprfGroup<CS> = <<CS as CipherSuite>::OprfGroup as voprf::CipherSuite>::Group;
51-
pub(crate) type OprfHash<CS> = <<CS as CipherSuite>::OprfGroup as voprf::CipherSuite>::Hash;
45+
pub(crate) type OprfGroup<CS> = <<CS as CipherSuite>::OprfCs as voprf::CipherSuite>::Group;
46+
pub(crate) type OprfHash<CS> = <<CS as CipherSuite>::OprfCs as voprf::CipherSuite>::Hash;

0 commit comments

Comments
 (0)
Please sign in to comment.