-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from raphaelrobert/batched_p384
Add batched P384 variant
- Loading branch information
Showing
32 changed files
with
1,570 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
); | ||
}); | ||
} |
Oops, something went wrong.