Skip to content

Commit

Permalink
Merge pull request #29 from raphaelrobert/batched_p384
Browse files Browse the repository at this point in the history
Add batched P384 variant
  • Loading branch information
raphaelrobert authored Mar 25, 2024
2 parents 5d2ab0a + 8c3d61b commit b88130a
Show file tree
Hide file tree
Showing 32 changed files with 1,570 additions and 274 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ rand = "0.8.5"
serde = "1"
sha2 = "0.10.2"
thiserror = "1"
tls_codec = "0.4.0"
tls_codec_derive = "0.4.0"
tls_codec = { version = "0.4.2-pre.1", git = "https://github.com/rustcrypto/formats" }
tls_codec_derive = "0.4.1"
voprf = { version = "0.5", features = ["serde"] }
p384 = { version = "0.13.0", default-features = false, features = [
"hash2curve",
Expand Down
120 changes: 62 additions & 58 deletions benches/batched.rs → benches/batched_p384.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::duplicate_mod)]
#[path = "../tests/batched_memory_stores.rs"]
mod batched_memory_stores;

Expand All @@ -7,43 +8,43 @@ use tokio::runtime::Runtime;
use privacypass::{auth::authenticate::TokenChallenge, TokenType};

async fn create_batched_keypair(
key_store: batched_memory_stores::MemoryKeyStore,
server: privacypass::batched_tokens::server::Server,
key_store: batched_memory_stores::MemoryKeyStoreP384,
server: privacypass::batched_tokens_p384::server::Server,
) {
let _public_key = server.create_keypair(&key_store).await.unwrap();
}

async fn issue_batched_token_response(
key_store: batched_memory_stores::MemoryKeyStore,
server: privacypass::batched_tokens::server::Server,
token_request: privacypass::batched_tokens::TokenRequest,
) -> privacypass::batched_tokens::TokenResponse {
key_store: batched_memory_stores::MemoryKeyStoreP384,
server: privacypass::batched_tokens_p384::server::Server,
token_request: privacypass::batched_tokens_p384::TokenRequest,
) -> privacypass::batched_tokens_p384::TokenResponse {
server
.issue_token_response(&key_store, token_request)
.await
.unwrap()
}

async fn redeem_batched_token(
key_store: batched_memory_stores::MemoryKeyStore,
key_store: batched_memory_stores::MemoryKeyStoreP384,
nonce_store: batched_memory_stores::MemoryNonceStore,
token: privacypass::batched_tokens::BatchedToken,
server: privacypass::batched_tokens::server::Server,
token: privacypass::batched_tokens_p384::BatchedToken,
server: privacypass::batched_tokens_p384::server::Server,
) {
server
.redeem_token(&key_store, &nonce_store, token)
.await
.unwrap();
}

pub fn criterion_batched_benchmark(c: &mut Criterion) {
pub fn criterion_batched_p384_benchmark(c: &mut Criterion) {
const NR: u16 = 100;
// Key pair generation
c.bench_function("BATCHED SERVER: Generate key pair", move |b| {
c.bench_function("BATCHED P384 SERVER: Generate key pair", move |b| {
b.to_async(FuturesExecutor).iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStore::default();
let server = privacypass::batched_tokens::server::Server::new();
let key_store = batched_memory_stores::MemoryKeyStoreP384::default();
let server = privacypass::batched_tokens_p384::server::Server::new();
(key_store, server)
},
|(key_store, server)| create_batched_keypair(key_store, server),
Expand All @@ -52,18 +53,18 @@ pub fn criterion_batched_benchmark(c: &mut Criterion) {

// Issue token request
c.bench_function(
&format!("BATCHED CLIENT: Issue token request for {NR} tokens"),
&format!("BATCHED P384 CLIENT: Issue token request for {NR} tokens"),
move |b| {
b.iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStore::default();
let server = privacypass::batched_tokens::server::Server::new();
let key_store = batched_memory_stores::MemoryKeyStoreP384::default();
let server = privacypass::batched_tokens_p384::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client = privacypass::batched_tokens::client::Client::new(public_key);
let client = privacypass::batched_tokens_p384::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::Batched,
TokenType::BatchedTokenP384,
"example.com",
None,
&["example.com".to_string()],
Expand All @@ -79,18 +80,18 @@ pub fn criterion_batched_benchmark(c: &mut Criterion) {

// Issue token response
c.bench_function(
&format!("BATCHED SERVER: Issue token response for {NR} tokens"),
&format!("BATCHED P384 SERVER: Issue token response for {NR} tokens"),
move |b| {
b.to_async(FuturesExecutor).iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStore::default();
let server = privacypass::batched_tokens::server::Server::new();
let key_store = batched_memory_stores::MemoryKeyStoreP384::default();
let server = privacypass::batched_tokens_p384::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client = privacypass::batched_tokens::client::Client::new(public_key);
let client = privacypass::batched_tokens_p384::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::Batched,
TokenType::BatchedTokenP384,
"example.com",
None,
&["example.com".to_string()],
Expand All @@ -107,50 +108,53 @@ pub fn criterion_batched_benchmark(c: &mut Criterion) {
);

// Issue token
c.bench_function(&format!("BATCHED CLIENT: Issue {NR} tokens"), move |b| {
b.iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStore::default();
let server = privacypass::batched_tokens::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client = privacypass::batched_tokens::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::Batched,
"example.com",
None,
&["example.com".to_string()],
);
let (token_request, token_states) =
client.issue_token_request(&challenge, NR).unwrap();
let token_response = rt.block_on(async {
server
.issue_token_response(&key_store, token_request)
.await
.unwrap()
});
(client, token_response, token_states)
},
|(client, token_response, token_states)| {
client.issue_tokens(&token_response, &token_states).unwrap();
},
);
});
c.bench_function(
&format!("BATCHED P384 CLIENT: Issue {NR} tokens"),
move |b| {
b.iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStoreP384::default();
let server = privacypass::batched_tokens_p384::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client = privacypass::batched_tokens_p384::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::BatchedTokenP384,
"example.com",
None,
&["example.com".to_string()],
);
let (token_request, token_states) =
client.issue_token_request(&challenge, NR).unwrap();
let token_response = rt.block_on(async {
server
.issue_token_response(&key_store, token_request)
.await
.unwrap()
});
(client, token_response, token_states)
},
|(client, token_response, token_states)| {
client.issue_tokens(&token_response, &token_states).unwrap();
},
);
},
);

// Redeem token
c.bench_function("BATCHED SERVER: Redeem token", move |b| {
c.bench_function("BATCHED P384 SERVER: Redeem token", move |b| {
b.to_async(FuturesExecutor).iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStore::default();
let key_store = batched_memory_stores::MemoryKeyStoreP384::default();
let nonce_store = batched_memory_stores::MemoryNonceStore::default();
let server = privacypass::batched_tokens::server::Server::new();
let server = privacypass::batched_tokens_p384::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client = privacypass::batched_tokens::client::Client::new(public_key);
let client = privacypass::batched_tokens_p384::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::Batched,
TokenType::BatchedTokenP384,
"example.com",
None,
&["example.com".to_string()],
Expand Down
182 changes: 182 additions & 0 deletions benches/batched_ristretto255.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#[allow(clippy::duplicate_mod)]
#[path = "../tests/batched_memory_stores.rs"]
mod batched_memory_stores;

use criterion::{async_executor::FuturesExecutor, Criterion};
use tokio::runtime::Runtime;

use privacypass::{auth::authenticate::TokenChallenge, TokenType};

async fn create_batched_keypair(
key_store: batched_memory_stores::MemoryKeyStoreRistretto255,
server: privacypass::batched_tokens_ristretto255::server::Server,
) {
let _public_key = server.create_keypair(&key_store).await.unwrap();
}

async fn issue_batched_token_response(
key_store: batched_memory_stores::MemoryKeyStoreRistretto255,
server: privacypass::batched_tokens_ristretto255::server::Server,
token_request: privacypass::batched_tokens_ristretto255::TokenRequest,
) -> privacypass::batched_tokens_ristretto255::TokenResponse {
server
.issue_token_response(&key_store, token_request)
.await
.unwrap()
}

async fn redeem_batched_token(
key_store: batched_memory_stores::MemoryKeyStoreRistretto255,
nonce_store: batched_memory_stores::MemoryNonceStore,
token: privacypass::batched_tokens_ristretto255::BatchedToken,
server: privacypass::batched_tokens_ristretto255::server::Server,
) {
server
.redeem_token(&key_store, &nonce_store, token)
.await
.unwrap();
}

pub fn criterion_batched_ristretto255_benchmark(c: &mut Criterion) {
const NR: u16 = 100;
// Key pair generation
c.bench_function("BATCHED RISTRETTO255 SERVER: Generate key pair", move |b| {
b.to_async(FuturesExecutor).iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStoreRistretto255::default();
let server = privacypass::batched_tokens_ristretto255::server::Server::new();
(key_store, server)
},
|(key_store, server)| create_batched_keypair(key_store, server),
);
});

// Issue token request
c.bench_function(
&format!("BATCHED RISTRETTO255 CLIENT: Issue token request for {NR} tokens"),
move |b| {
b.iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStoreRistretto255::default();
let server = privacypass::batched_tokens_ristretto255::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client =
privacypass::batched_tokens_ristretto255::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::BatchedTokenRistretto255,
"example.com",
None,
&["example.com".to_string()],
);
(client, challenge)
},
|(client, challenge)| {
client.issue_token_request(&challenge, NR).unwrap();
},
);
},
);

// Issue token response
c.bench_function(
&format!("BATCHED RISTRETTO255 SERVER: Issue token response for {NR} tokens"),
move |b| {
b.to_async(FuturesExecutor).iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStoreRistretto255::default();
let server = privacypass::batched_tokens_ristretto255::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client =
privacypass::batched_tokens_ristretto255::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::BatchedTokenRistretto255,
"example.com",
None,
&["example.com".to_string()],
);
let (token_request, _token_states) =
client.issue_token_request(&challenge, NR).unwrap();
(key_store, server, token_request)
},
|(key_store, server, token_request)| {
issue_batched_token_response(key_store, server, token_request)
},
);
},
);

// Issue token
c.bench_function(
&format!("BATCHED RISTRETTO255 CLIENT: Issue {NR} tokens"),
move |b| {
b.iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStoreRistretto255::default();
let server = privacypass::batched_tokens_ristretto255::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client =
privacypass::batched_tokens_ristretto255::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::BatchedTokenRistretto255,
"example.com",
None,
&["example.com".to_string()],
);
let (token_request, token_states) =
client.issue_token_request(&challenge, NR).unwrap();
let token_response = rt.block_on(async {
server
.issue_token_response(&key_store, token_request)
.await
.unwrap()
});
(client, token_response, token_states)
},
|(client, token_response, token_states)| {
client.issue_tokens(&token_response, &token_states).unwrap();
},
);
},
);

// Redeem token
c.bench_function("BATCHED RISTRETTO255 SERVER: Redeem token", move |b| {
b.to_async(FuturesExecutor).iter_with_setup(
|| {
let key_store = batched_memory_stores::MemoryKeyStoreRistretto255::default();
let nonce_store = batched_memory_stores::MemoryNonceStore::default();
let server = privacypass::batched_tokens_ristretto255::server::Server::new();
let rt = Runtime::new().unwrap();
let public_key =
rt.block_on(async { server.create_keypair(&key_store).await.unwrap() });
let client =
privacypass::batched_tokens_ristretto255::client::Client::new(public_key);
let challenge = TokenChallenge::new(
TokenType::BatchedTokenRistretto255,
"example.com",
None,
&["example.com".to_string()],
);
let (token_request, token_state) =
client.issue_token_request(&challenge, NR).unwrap();
let token_response = rt.block_on(async {
server
.issue_token_response(&key_store, token_request)
.await
.unwrap()
});
let tokens = client.issue_tokens(&token_response, &token_state).unwrap();
(key_store, nonce_store, tokens, server)
},
|(key_store, nonce_store, tokens, server)| {
redeem_batched_token(key_store, nonce_store, tokens[0].clone(), server)
},
);
});
}
Loading

0 comments on commit b88130a

Please sign in to comment.