Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Test chacha20 encstring build artifacts #99

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 87 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ codegen-units = 1
# Stripping the binary reduces the size by ~30%, but the stacktraces won't be usable anymore.
# This is fine as long as we don't have any unhandled panics, but let's keep it disabled for now
# strip = true

[patch.crates-io]
pkcs5 = { git = "https://github.com/bitwarden/rustcrypto-formats.git", rev = "2b27c63034217dd126bbf5ed874da51b84f8c705", features = [
"rand_core",
"pbes2",
], package = "pkcs5" }
21 changes: 20 additions & 1 deletion crates/bitwarden-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,40 @@ license-file.workspace = true
keywords.workspace = true

[features]
default = []
default = ["aead-crypto"]
wasm = ["dep:tsify-next", "dep:wasm-bindgen"] # WASM support

uniffi = ["dep:uniffi"] # Uniffi bindings
no-memory-hardening = [] # Disable memory hardening features

aead-crypto = [
"dep:blake3",
"dep:chacha20",
"dep:chacha20poly1305",
"dep:poly1305",
]

[dependencies]
aes = { version = ">=0.8.2, <0.9", features = ["zeroize"] }
argon2 = { version = ">=0.5.0, <0.6", features = [
"std",
"zeroize",
], default-features = false }
base64 = ">=0.22.1, <0.23"
blake3 = { version = "1.5.5", features = ["zeroize"], optional = true }
cbc = { version = ">=0.1.2, <0.2", features = ["alloc", "zeroize"] }
chacha20 = { version = ">=0.8.2, <0.9", features = [
"zeroize",
], optional = true }
chacha20poly1305 = { version = "0.10.1", optional = true }
generic-array = { version = ">=0.14.7, <1.0", features = ["zeroize"] }
hkdf = ">=0.12.3, <0.13"
hmac = ">=0.12.1, <0.13"
log = "0.4.20"
num-bigint = ">=0.4, <0.5"
num-traits = ">=0.2.15, <0.3"
pbkdf2 = { version = ">=0.12.1, <0.13", default-features = false }
poly1305 = { version = "0.8.0", features = ["zeroize"], optional = true }
rand = ">=0.8.5, <0.9"
rayon = ">=1.8.1, <2.0"
rsa = ">=0.9.2, <0.10"
Expand Down Expand Up @@ -65,5 +79,10 @@ name = "zeroizing_allocator"
harness = false
required-features = ["no-memory-hardening"]

[[bench]]
name = "ciphers"
required-features = ["aead-crypto"]
harness = false

[lints]
workspace = true
33 changes: 33 additions & 0 deletions crates/bitwarden-crypto/benches/ciphers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use bitwarden_crypto::chacha20::{
decrypt_xchacha20_poly1305_blake3_ctx, encrypt_xchacha20_poly1305_blake3_ctx,
};
use criterion::{black_box, criterion_group, criterion_main, Criterion};

pub fn criterion_benchmark(c: &mut Criterion) {
let key = [0u8; 32];
let plaintext_secret_data = vec![0u8; 1024];
let plaintext_secret_data = plaintext_secret_data.as_slice();
let authenticated_data = vec![0u8; 256];
let authenticated_data = authenticated_data.as_slice();

c.bench_function("encrypt_xchacha20_poly1305_blake3_ctx", |b| {
b.iter(|| {
encrypt_xchacha20_poly1305_blake3_ctx(
black_box(&key),
black_box(plaintext_secret_data),
black_box(authenticated_data),
)
})
});

let encrypted =
encrypt_xchacha20_poly1305_blake3_ctx(&key, plaintext_secret_data, authenticated_data)
.unwrap();

c.bench_function("encrypt_xchacha20_poly1305_blake3_ctx", |b| {
b.iter(|| decrypt_xchacha20_poly1305_blake3_ctx(black_box(&key), black_box(&encrypted)))
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading
Loading