mirror of https://github.com/dswd/vpncloud.git
Crypto benches
This commit is contained in:
parent
b362ac676c
commit
5d3f6f3494
|
@ -4,11 +4,39 @@ use std::str::FromStr;
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
|
|
||||||
use super::udpmessage::{Options, Message, encode, decode};
|
use super::udpmessage::{Options, Message, encode, decode};
|
||||||
use super::crypto::Crypto;
|
use super::crypto::{Crypto, CryptoMethod};
|
||||||
use super::ethernet::{Frame, SwitchTable};
|
use super::ethernet::{Frame, SwitchTable};
|
||||||
use super::types::{Address, Table, Protocol};
|
use super::types::{Address, Table, Protocol};
|
||||||
use super::ip::Packet;
|
use super::ip::Packet;
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn crypto_salsa20(b: &mut Bencher) {
|
||||||
|
let mut crypto = Crypto::from_shared_key(CryptoMethod::ChaCha20, "test");
|
||||||
|
let mut payload = [0; 1500];
|
||||||
|
let header = [0; 8];
|
||||||
|
let mut nonce_bytes = [0; 12];
|
||||||
|
b.iter(|| {
|
||||||
|
let len = crypto.encrypt(&mut payload, 1400, &mut nonce_bytes, &header);
|
||||||
|
assert!(crypto.decrypt(&mut payload[..len], &nonce_bytes, &header).is_ok())
|
||||||
|
});
|
||||||
|
b.bytes = 1400;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn crypto_aes256(b: &mut Bencher) {
|
||||||
|
if !Crypto::aes256_available() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let mut crypto = Crypto::from_shared_key(CryptoMethod::AES256, "test");
|
||||||
|
let mut payload = [0; 1500];
|
||||||
|
let header = [0; 8];
|
||||||
|
let mut nonce_bytes = [0; 12];
|
||||||
|
b.iter(|| {
|
||||||
|
let len = crypto.encrypt(&mut payload, 1400, &mut nonce_bytes, &header);
|
||||||
|
assert!(crypto.decrypt(&mut payload[..len], &nonce_bytes, &header).is_ok());
|
||||||
|
});
|
||||||
|
b.bytes = 1400;
|
||||||
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn message_encode(b: &mut Bencher) {
|
fn message_encode(b: &mut Bencher) {
|
||||||
|
|
Loading…
Reference in New Issue