Skip to content

Commit bd37deb

Browse files
authored
Merge pull request facebook#75 from huitseeker/tls
Rebase TLS on master
2 parents c7f6abb + 6deddbe commit bd37deb

File tree

17 files changed

+1491
-666
lines changed

17 files changed

+1491
-666
lines changed

benches/oprf.rs

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
extern crate criterion;
88

99
use criterion::Criterion;
10-
use curve25519_dalek::edwards::EdwardsPoint;
11-
use curve25519_dalek::ristretto::RistrettoPoint;
10+
use curve25519_dalek::{edwards::EdwardsPoint, ristretto::RistrettoPoint};
1211
use generic_array::arr;
1312
use opaque_ke::{
1413
group::Group,
15-
oprf::{generate_oprf1_shim, generate_oprf2_shim, generate_oprf3_shim, OprfClientBytes},
14+
oprf::{blind_shim, evaluate_shim, unblind_and_finalize_shim},
1615
};
1716
use rand::{prelude::ThreadRng, thread_rng};
1817
use sha2::Sha256;
@@ -21,12 +20,9 @@ fn oprf1(c: &mut Criterion) {
2120
let mut csprng: ThreadRng = thread_rng();
2221
let input = b"hunter2";
2322

24-
c.bench_function("generate_oprf1 with Ristretto", move |b| {
23+
c.bench_function("blind with Ristretto", move |b| {
2524
b.iter(|| {
26-
let OprfClientBytes {
27-
alpha: _alpha,
28-
blinding_factor: _blinding_factor,
29-
} = generate_oprf1_shim::<_, RistrettoPoint>(&input[..], None, &mut csprng).unwrap();
25+
blind_shim::<_, RistrettoPoint>(&input[..], &mut csprng).unwrap();
3026
})
3127
});
3228
}
@@ -35,12 +31,9 @@ fn oprf1_edwards(c: &mut Criterion) {
3531
let mut csprng: ThreadRng = thread_rng();
3632
let input = b"hunter2";
3733

38-
c.bench_function("generate_oprf1 with Edwards", move |b| {
34+
c.bench_function("blind with Edwards", move |b| {
3935
b.iter(|| {
40-
let OprfClientBytes {
41-
alpha: _alpha,
42-
blinding_factor: _blinding_factor,
43-
} = generate_oprf1_shim::<_, EdwardsPoint>(&input[..], None, &mut csprng).unwrap();
36+
blind_shim::<_, EdwardsPoint>(&input[..], &mut csprng).unwrap();
4437
})
4538
});
4639
}
@@ -49,19 +42,16 @@ fn oprf2(c: &mut Criterion) {
4942
let mut csprng: ThreadRng = thread_rng();
5043
let input = b"hunter2";
5144

52-
let OprfClientBytes {
53-
alpha,
54-
blinding_factor: _blinding_factor,
55-
} = generate_oprf1_shim::<_, RistrettoPoint>(&input[..], None, &mut csprng).unwrap();
45+
let (_, alpha) = blind_shim::<_, RistrettoPoint>(&input[..], &mut csprng).unwrap();
5646
let salt_bytes = arr![
5747
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
5848
24, 25, 26, 27, 28, 29, 30, 31, 32,
5949
];
6050
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
6151

62-
c.bench_function("generate_oprf2 with Ristretto", move |b| {
52+
c.bench_function("evaluate with Ristretto", move |b| {
6353
b.iter(|| {
64-
let _beta = generate_oprf2_shim::<RistrettoPoint>(alpha, &salt).unwrap();
54+
let _beta = evaluate_shim::<RistrettoPoint>(alpha, &salt).unwrap();
6555
})
6656
});
6757
}
@@ -70,19 +60,16 @@ fn oprf2_edwards(c: &mut Criterion) {
7060
let mut csprng: ThreadRng = thread_rng();
7161
let input = b"hunter2";
7262

73-
let OprfClientBytes {
74-
alpha,
75-
blinding_factor: _blinding_factor,
76-
} = generate_oprf1_shim::<_, EdwardsPoint>(&input[..], None, &mut csprng).unwrap();
63+
let (_, alpha) = blind_shim::<_, EdwardsPoint>(&input[..], &mut csprng).unwrap();
7764
let salt_bytes = arr![
7865
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
7966
24, 25, 26, 27, 28, 29, 30, 31, 32,
8067
];
8168
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
8269

83-
c.bench_function("generate_oprf2 with Edwards", move |b| {
70+
c.bench_function("evaluate with Edwards", move |b| {
8471
b.iter(|| {
85-
let _beta = generate_oprf2_shim::<EdwardsPoint>(alpha, &salt).unwrap();
72+
let _beta = evaluate_shim::<EdwardsPoint>(alpha, &salt).unwrap();
8673
})
8774
});
8875
}
@@ -91,21 +78,17 @@ fn oprf3(c: &mut Criterion) {
9178
let mut csprng: ThreadRng = thread_rng();
9279
let input = b"hunter2";
9380

94-
let OprfClientBytes {
95-
alpha,
96-
blinding_factor,
97-
} = generate_oprf1_shim::<_, RistrettoPoint>(&input[..], None, &mut csprng).unwrap();
81+
let (token, alpha) = blind_shim::<_, RistrettoPoint>(&input[..], &mut csprng).unwrap();
9882
let salt_bytes = arr![
9983
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
10084
24, 25, 26, 27, 28, 29, 30, 31, 32,
10185
];
10286
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
103-
let beta = generate_oprf2_shim::<RistrettoPoint>(alpha, &salt).unwrap();
87+
let beta = evaluate_shim::<RistrettoPoint>(alpha, &salt).unwrap();
10488

105-
c.bench_function("generate_oprf3 with Ristretto", move |b| {
89+
c.bench_function("unblind_and_finalize with Ristretto", move |b| {
10690
b.iter(|| {
107-
let _res = generate_oprf3_shim::<RistrettoPoint, Sha256>(input, beta, &blinding_factor)
108-
.unwrap();
91+
let _res = unblind_and_finalize_shim::<RistrettoPoint, Sha256>(&token, beta).unwrap();
10992
})
11093
});
11194
}
@@ -114,21 +97,17 @@ fn oprf3_edwards(c: &mut Criterion) {
11497
let mut csprng: ThreadRng = thread_rng();
11598
let input = b"hunter2";
11699

117-
let OprfClientBytes {
118-
alpha,
119-
blinding_factor,
120-
} = generate_oprf1_shim::<_, EdwardsPoint>(&input[..], None, &mut csprng).unwrap();
100+
let (token, alpha) = blind_shim::<_, EdwardsPoint>(&input[..], &mut csprng).unwrap();
121101
let salt_bytes = arr![
122102
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
123103
24, 25, 26, 27, 28, 29, 30, 31, 32,
124104
];
125105
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
126-
let beta = generate_oprf2_shim::<EdwardsPoint>(alpha, &salt).unwrap();
106+
let beta = evaluate_shim::<EdwardsPoint>(alpha, &salt).unwrap();
127107

128-
c.bench_function("generate_oprf3 with Edwards", move |b| {
108+
c.bench_function("unblind_and_finalize with Edwards", move |b| {
129109
b.iter(|| {
130-
let _res =
131-
generate_oprf3_shim::<EdwardsPoint, Sha256>(input, beta, &blinding_factor).unwrap();
110+
let _res = unblind_and_finalize_shim::<EdwardsPoint, Sha256>(&token, beta).unwrap();
132111
})
133112
});
134113
}

examples/simple_login.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ fn account_registration(
5656
) -> Vec<u8> {
5757
let mut client_rng = OsRng;
5858
let (r1, client_state) =
59-
ClientRegistration::<Default>::start(password.as_bytes(), Some(b"pepper"), &mut client_rng)
60-
.unwrap();
61-
let r1_bytes = r1.to_bytes();
59+
ClientRegistration::<Default>::start(password.as_bytes(), &mut client_rng).unwrap();
60+
let r1_bytes = r1.serialize();
6261

6362
// Client sends r1_bytes to server
6463

@@ -68,7 +67,7 @@ fn account_registration(
6867
&mut server_rng,
6968
)
7069
.unwrap();
71-
let r2_bytes = r2.to_bytes();
70+
let r2_bytes = r2.serialize();
7271

7372
// Server sends r2_bytes to client
7473

@@ -79,7 +78,7 @@ fn account_registration(
7978
&mut client_rng,
8079
)
8180
.unwrap();
82-
let r3_bytes = r3.to_bytes();
81+
let r3_bytes = r3.serialize();
8382

8483
// Client sends r3_bytes to server
8584

@@ -97,9 +96,8 @@ fn account_login(
9796
) -> bool {
9897
let mut client_rng = OsRng;
9998
let (l1, client_state) =
100-
ClientLogin::<Default>::start(password.as_bytes(), Some(b"pepper"), &mut client_rng)
101-
.unwrap();
102-
let l1_bytes = l1.to_bytes();
99+
ClientLogin::<Default>::start(password.as_bytes(), &mut client_rng).unwrap();
100+
let l1_bytes = l1.serialize();
103101

104102
// Client sends l1_bytes to server
105103

@@ -112,7 +110,7 @@ fn account_login(
112110
&mut server_rng,
113111
)
114112
.unwrap();
115-
let l2_bytes = l2.to_bytes();
113+
let l2_bytes = l2.serialize();
116114

117115
// Server sends l2_bytes to client
118116

@@ -127,7 +125,7 @@ fn account_login(
127125
return false;
128126
}
129127
let (l3, client_shared_secret, _) = result.unwrap();
130-
let l3_bytes = l3.to_bytes();
128+
let l3_bytes = l3.serialize();
131129

132130
// Client sends l3_bytes to server
133131

src/elligator/field.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
//! Field arithmetic modulo \\(p = 2\^{255} - 19\\), using \\(64\\)-bit
88
//! limbs with \\(128\\)-bit products.
99
10-
use core::fmt::Debug;
11-
use core::ops::Neg;
12-
use core::ops::{Add, AddAssign};
13-
use core::ops::{Mul, MulAssign};
14-
15-
use subtle::Choice;
16-
use subtle::ConditionallyNegatable;
17-
use subtle::ConditionallySelectable;
18-
use subtle::ConstantTimeEq;
10+
use core::{
11+
fmt::Debug,
12+
ops::{Add, AddAssign, Mul, MulAssign, Neg},
13+
};
14+
15+
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};
1916

2017
use zeroize::Zeroize;
2118

0 commit comments

Comments
 (0)