Conform to voprf spec (#71)

This commit is contained in:
Kevin Lewi
2020-11-02 20:15:08 -05:00
committed by François Garillot
parent 28645a7cea
commit c8cbf56336
6 changed files with 238 additions and 237 deletions
+19 -39
View File
@@ -11,7 +11,7 @@ use curve25519_dalek::{edwards::EdwardsPoint, ristretto::RistrettoPoint};
use generic_array::arr;
use opaque_ke::{
group::Group,
oprf::{generate_oprf1_shim, generate_oprf2_shim, generate_oprf3_shim, OprfClientBytes},
oprf::{blind_shim, evaluate_shim, unblind_and_finalize_shim},
};
use rand::{prelude::ThreadRng, thread_rng};
use sha2::Sha256;
@@ -20,12 +20,9 @@ fn oprf1(c: &mut Criterion) {
let mut csprng: ThreadRng = thread_rng();
let input = b"hunter2";
c.bench_function("generate_oprf1 with Ristretto", move |b| {
c.bench_function("blind with Ristretto", move |b| {
b.iter(|| {
let OprfClientBytes {
alpha: _alpha,
blinding_factor: _blinding_factor,
} = generate_oprf1_shim::<_, RistrettoPoint>(&input[..], None, &mut csprng).unwrap();
blind_shim::<_, RistrettoPoint>(&input[..], &mut csprng).unwrap();
})
});
}
@@ -34,12 +31,9 @@ fn oprf1_edwards(c: &mut Criterion) {
let mut csprng: ThreadRng = thread_rng();
let input = b"hunter2";
c.bench_function("generate_oprf1 with Edwards", move |b| {
c.bench_function("blind with Edwards", move |b| {
b.iter(|| {
let OprfClientBytes {
alpha: _alpha,
blinding_factor: _blinding_factor,
} = generate_oprf1_shim::<_, EdwardsPoint>(&input[..], None, &mut csprng).unwrap();
blind_shim::<_, EdwardsPoint>(&input[..], &mut csprng).unwrap();
})
});
}
@@ -48,19 +42,16 @@ fn oprf2(c: &mut Criterion) {
let mut csprng: ThreadRng = thread_rng();
let input = b"hunter2";
let OprfClientBytes {
alpha,
blinding_factor: _blinding_factor,
} = generate_oprf1_shim::<_, RistrettoPoint>(&input[..], None, &mut csprng).unwrap();
let (_, alpha) = blind_shim::<_, RistrettoPoint>(&input[..], &mut csprng).unwrap();
let salt_bytes = arr![
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32,
];
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
c.bench_function("generate_oprf2 with Ristretto", move |b| {
c.bench_function("evaluate with Ristretto", move |b| {
b.iter(|| {
let _beta = generate_oprf2_shim::<RistrettoPoint>(alpha, &salt).unwrap();
let _beta = evaluate_shim::<RistrettoPoint>(alpha, &salt).unwrap();
})
});
}
@@ -69,19 +60,16 @@ fn oprf2_edwards(c: &mut Criterion) {
let mut csprng: ThreadRng = thread_rng();
let input = b"hunter2";
let OprfClientBytes {
alpha,
blinding_factor: _blinding_factor,
} = generate_oprf1_shim::<_, EdwardsPoint>(&input[..], None, &mut csprng).unwrap();
let (_, alpha) = blind_shim::<_, EdwardsPoint>(&input[..], &mut csprng).unwrap();
let salt_bytes = arr![
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32,
];
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
c.bench_function("generate_oprf2 with Edwards", move |b| {
c.bench_function("evaluate with Edwards", move |b| {
b.iter(|| {
let _beta = generate_oprf2_shim::<EdwardsPoint>(alpha, &salt).unwrap();
let _beta = evaluate_shim::<EdwardsPoint>(alpha, &salt).unwrap();
})
});
}
@@ -90,21 +78,17 @@ fn oprf3(c: &mut Criterion) {
let mut csprng: ThreadRng = thread_rng();
let input = b"hunter2";
let OprfClientBytes {
alpha,
blinding_factor,
} = generate_oprf1_shim::<_, RistrettoPoint>(&input[..], None, &mut csprng).unwrap();
let (token, alpha) = blind_shim::<_, RistrettoPoint>(&input[..], &mut csprng).unwrap();
let salt_bytes = arr![
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32,
];
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
let beta = generate_oprf2_shim::<RistrettoPoint>(alpha, &salt).unwrap();
let beta = evaluate_shim::<RistrettoPoint>(alpha, &salt).unwrap();
c.bench_function("generate_oprf3 with Ristretto", move |b| {
c.bench_function("unblind_and_finalize with Ristretto", move |b| {
b.iter(|| {
let _res = generate_oprf3_shim::<RistrettoPoint, Sha256>(input, beta, &blinding_factor)
.unwrap();
let _res = unblind_and_finalize_shim::<RistrettoPoint, Sha256>(&token, beta).unwrap();
})
});
}
@@ -113,21 +97,17 @@ fn oprf3_edwards(c: &mut Criterion) {
let mut csprng: ThreadRng = thread_rng();
let input = b"hunter2";
let OprfClientBytes {
alpha,
blinding_factor,
} = generate_oprf1_shim::<_, EdwardsPoint>(&input[..], None, &mut csprng).unwrap();
let (token, alpha) = blind_shim::<_, EdwardsPoint>(&input[..], &mut csprng).unwrap();
let salt_bytes = arr![
u8; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32,
];
let salt = RistrettoPoint::from_scalar_slice(&salt_bytes).unwrap();
let beta = generate_oprf2_shim::<EdwardsPoint>(alpha, &salt).unwrap();
let beta = evaluate_shim::<EdwardsPoint>(alpha, &salt).unwrap();
c.bench_function("generate_oprf3 with Edwards", move |b| {
c.bench_function("unblind_and_finalize with Edwards", move |b| {
b.iter(|| {
let _res =
generate_oprf3_shim::<EdwardsPoint, Sha256>(input, beta, &blinding_factor).unwrap();
let _res = unblind_and_finalize_shim::<EdwardsPoint, Sha256>(&token, beta).unwrap();
})
});
}