Skip to content

Commit

Permalink
fix(kyberlib): 🚑 disabling criterion benchmark for now
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Nov 20, 2023
1 parent 6556e12 commit bd60663
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
18 changes: 7 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ rand_core = { version = "0.6.4", default-features = false }
sha2 = { version = "0.10.8", optional = true , default-features = false }
wasm-bindgen = { version = "0.2.88", optional = true }

# Optional dev-deps, see https://github.com/rust-lang/cargo/issues/1596
criterion = { version = "0.5.1", features = ["html_reports"], optional = true }
[dev-dependencies]
criterion = "0.5.1"
rand = "0.8.5"

[dependencies.rand]
version = "0.8.5"
default-features = false
features = ["getrandom"]
optional = true

[dev-dependencies]
rand = "0.8.5"

[build-dependencies]
cc = {version = "1.0.73", optional = true }
nasm-rs = {version = "0.2.4", optional = true }
Expand All @@ -57,9 +55,10 @@ crate-type = ["cdylib", "rlib"]
name = "kyberlib"
path = "src/lib.rs"

[[bench]]
name = "api"
harness = false
# [[bench]]
# name = "bench"
# harness = false
# path = "benches/bench.rs"

[features]
### Security Levels ###
Expand Down Expand Up @@ -101,9 +100,6 @@ nasm = ["nasm-rs", "avx2"]
# Enable std library support
std = []

# For benchmarking
benchmarking = ["criterion"]

[workspace]
members = ["xtask"]

Expand Down
20 changes: 10 additions & 10 deletions benches/api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![cfg(feature = "benchmarking")] // Lint
extern crate criterion;
use criterion::{criterion_group, criterion_main, Criterion};
use kyberlib::*;
use kyberlib::{*, kem::{generate_key_pair, encrypt_message}};

// Benchmarking key generation
fn keypair(c: &mut Criterion) {
pub fn keypair(c: &mut Criterion) {
let mut _rng = rand::thread_rng(); //placeholder
let mut pk = [0u8; KYBER_PUBLIC_KEY_BYTES];
let mut sk = [0u8; KYBER_SECRET_KEY_BYTES];
Expand All @@ -16,10 +16,10 @@ fn keypair(c: &mut Criterion) {
}

// Encapsulating a single public key
fn encap(c: &mut Criterion) {
pub fn encap(c: &mut Criterion) {
let mut ct = [0u8; KYBER_CIPHERTEXT_BYTES];
let mut ss = [0u8; KYBER_SHARED_SECRET_BYTES];
let pk = crate::decode_hex(PK);
let pk = decode_hex(PK);
let mut _rng = rand::thread_rng();
let encap_buf = Some([255u8; 32].as_slice());
c.bench_function("Encapsulate", |b| {
Expand All @@ -30,7 +30,7 @@ fn encap(c: &mut Criterion) {
}

// Decapsulating a single correct ciphertext
fn decap(c: &mut Criterion) {
pub fn decap(c: &mut Criterion) {
let sk = decode_hex(SK);
let ct = decode_hex(CT);
c.bench_function("Decapsulate", |b| {
Expand All @@ -41,7 +41,7 @@ fn decap(c: &mut Criterion) {
}

// Decapsulating a single incorrect ciphertext
fn decap_fail(c: &mut Criterion) {
pub fn decap_fail(c: &mut Criterion) {
let sk = decode_hex(BAD_SK);
let ct = decode_hex(CT);
c.bench_function("Decapsulate Failure", |b| {
Expand All @@ -51,9 +51,6 @@ fn decap_fail(c: &mut Criterion) {
});
}

criterion_group!(benches, keypair, encap, decap, decap_fail);
criterion_main!(benches);

// Decodes a hex string into a vector of bytes
pub fn decode_hex(s: &str) -> Vec<u8> {
(0..s.len())
Expand Down Expand Up @@ -133,3 +130,6 @@ const SK: &str = "910c5a48053837472f7dcacc4e74709f3a29e7177e83198ee8228390d43d16
const BAD_SK: &str = "010c5a48053837472f7dcacc4e74709f3a29e7177e83198ee8228390d43d164a2d3526a72aec993fc5642023b0cb08a5c4b05d3e7baa3b27943b1b1ca6589aa565344c5c63a6b6c3dd5b53ffac269478958776127c1520f9dab47cc24a9c5b1e0125a7db596213c0526877b829b6484cc21f4d0397a3d39fc328af7dd1ce39d1291ba628d9189b69291659229021173f0b8b0bb09c56f52c566979a6603c19ac4453b6862aae8ba96983ac0d8a674af237397b369d1050f9a441d6c3c336fc5b22e62421723bdfc04eb074075f2b3b61c0268614744675ab30f2cede9c4989d922d8c3c740189aa7b65dca9a1892d998fa66a6cf37186a983151f065ba42cdd0dcbc08ecc6ac544aa8178e383940dc328d199a3e749c00d796841f64a5872ab74cec8b0ecbbc2db58e462ccd87e385be11a0948c19de9581d7d682c5b73ee3a868fdb0a61c82cce47a7615319397b13e64438b67b5747e6bad05f81f5b08ae9071a7d9106cfff80c39879e75879f06231ecf0495a896ab11727e97b1c638bc28893a948567bd0e98749604b0ec8587d0e49a38663fc1d33dd632162ed17a3f320a12e1c56c040418b25c5f478b62539a8bd765edb203da9c0a871b59a5e60c51f9295f263373999c96ac4f32684a52649fd109bbc256acec86c4c1c24dcce386414c692e4aa4e4496b87080fb9438e82468f95862441970ba79120c6f446ba6228c5719d19cc2d7fc8ac7de73a0d2ac7151480ae183d78fb7f1d3053b5a82f75131d702a1ae4c8c3028c5d1a2968e58726410b5b7be6888633cd3952024ef953809b69095a0aacba00e837a77e262b1ca9cca263328a74a789f01d8d25aeaa50c24e654d8fd42126ec0a6ec8462c8865ea01960e5b822ba9452f5542047804c190cbe8787256c80248a52e326c1a6c4465d4437323b25d86d46d366a200298a30d71ac1ba2c2ee6a31a3509eb46200f2aa4fa55b386a7087468b41df5236e8034bf059b5a5cb7d439a6ef5bb1704550c559c9b6428c87df1195c595ebd93ada3096796c15300fd86f18b55ee844b175b70dc0bb4e11376e7a81df433add04553d687ced41805f69a3a3f760aa476bfc0a04392387a3598824af2c2373762d1274e300c452118880542a50e1671ff778bb36390459b6477312b012c93ea43c45bdc3931d8ceb6949970e899ca09206f0841ee7961106b94f8831cfbfc3d856a9bc0b403c9f362d6556ffd97746eb896a0e44d1fabaebda13c39d1c00274cc77981ef26016ec89aa002c7d57f20b32ac5a9456bb2ea6a0fb1a517f9043fd31582e07a70b34380a324e2b52b366a2aa2f36c01d40560e9215f2a06ca6a2c147830e7fb8a1b959783f57c6a54963c42881dab7a96770a44df945fac73731a29e770129652211fe23cdf1fb7d565c23183258f0d43c3503093fc1b918b84353825eede34a77c7aeb9e78e0bf218498610f51067449137d925a9c3e4b5a7a031804a9e4b847f8478561e8c8756024032a661db899742203fbf233594823db7187d71659c34b61fc9a3881a4129c552b70ebc41a463a5446ccce536960cd86ed57b892f2b64580b636e69060b33681bb09dfbe31f9ad761d6074e8f628406a8994f8293345ab7348052264014490b0f0ae4a9cfa494bcd57702b8362356c29918b921633ed6ca66f9d9c658995693f146cf5abec9431a544a70446757f5ba6d57a7814348b8250505fdfacf3cf767202007f09a49bea65602589a39f59a830b15bbf96e5a66b4d514772c5c48854b3ff12c3ef0f9cb7a760219e26cca636fec873f28290c68840245c40412351b07b0b5dedc41947aae80580b539a8eb24ca76ada55293a1ea331b4b66a5621c8492185bbd9766d639acdb9863303c738debc3baa438c90428ee43643dd28b436f477b395599b4293dd733b7a0390047b59181c4b3d9305b9b768e4dc472759c4310b3f95645b891843f88847f8a67df1776173aa852551cae9e5923c758af27754df395da89033f919c8fbc312d30a1dca33c579016ad81256977046da17941fe347cb790834b44107aaab416a1432ea74ed060c22a0966daaba0ea629399794fbf79b2db74a6979081458a989f409fc355846f03cd9bc904d564e0bf7a067361c7ee05dd192ae9887173e52720442ae13fbbe9d2098b7a2bafbf41df0399408c41f1dbab85f8819cb0ba7c4b13daca064e08c7e35c42b3e70729959269635b6d2c808017859cc474616e000884606143814b3292f14ba618e786276434e0236670dda02251868a82851d24b0cf45a90a08256e21952b0ebb12e7cbd730b5ef8a4a32c566fad6909cc0b8054f56f2ebc651b96633f06158b3b32b2c89f4ef09be7b0a314b533c7960613207422f76b7788182d9376a7049f5cfcc57f3450eac5c12c2c1284c2342e0467c25842e60602d6553132848a57465d0bfb848a948901b1b8ea91057269c325542217a5932b673065f87019712ff1bb27f0d03a0e52c7129ac5496bcaf4d818e2dc8d4f9c51d1d9194cea7681c5afe090c9e810af15768a040cb7adeab558f66f9253318616bd4b604029b1027885421317319d4c30db8075c320531f0688ab91c60f8a408fa10785895e31a4856263915127c158b46abab0b73a44baefa0a3eed6090e8464be4187a7c5ac49a591021b24b49c6dbfa69362e820e519b9646577347b24b92ac2384b894db48adb216420f24e46547b50a87df3d89307578ffaab13b81a419e268cef8a0f8db8b165b03b55164c6eb28c1ea7996605121bfb75edb08a9905092c8a3f1e22c7c97cb87ebc74c060786a12bb73c4c46969292125118281c4c0598264cc5ab3c933949668ee19877757b701353fcaf219b3245685bbacc892be7bb38488c1ca9cac32c8d69918dab908081da6ac86140a036d7932d0795a86d7888733bd39181f13961df7185a06669b848855eb8c8c371b2c5cf0650e005ddba23d0d38052ad65780b28205fa7ee804b7ad3954d42b50d56330ee34600c84c47e684e3ec9c669c349080902c800bc1f9c165ce65292c18bb4a04b042148f0b6598d76b9fd356e50e274d2f5626072bd07620237c9ca232571c7005e81f47bdaf1a8909822d06047524b015e013ee92732358124491440987b4b84355431115f3bd4ae64cc527566941e44cdace12ed4656c89624cb73b1c427131af026ad73c3ced431ea4ac8b46c480550b247cc056d24c7fe4a28103bba2a99566ded7a1d168a2014a5ff7240decf68973146b8e26772f8119d874942dc33492796fd22b3066b26b73893a0b9242033b90b85744c90c6dd1758e14599bb4ea00c0170140d257330840a73a82d8b14211c55c0c68c30372a37bac60e4690c75f052fb40a959c13f47855164f31e2c28b0a136798312b1755770bd54a0d5c8c0aa623f14d3ae7a261e35c99de6c89f773b331854c86d27011c5408ee37013fe875a2e8788711b6d55762b144a127b02ed4e3adf4a1bde9b10ccba26de0a53b9c109e259156e5f1bf8b970ecd9c6864db48bfeb31a02157c10061feec5743618417866519e350fbc155fb47c67c5cb7fcd4ba00917d8b478f3f4aa85b9506ce7b1ea3e71b7778c7832c8ead1301e91c39d2f68389b63e41a69f8ca6b2de30c8b9f9a5e8d316b5b45fbea182c14804b3a0cd160338dd84a493985289f275ddab24d69bc45fd616b348978adc8f6256687a603fab81530344cde51828d320c53ff04d59106bec98cc82407cf6601a512c96c73436b8518c343269ffb324345368f3861ebb673a351b9e5677855d396bb2d631f4a845096cc170726168c597af210a7717c2caa19c602cc30c3cc041392afb29a0cb64ad391394b26434fc578ec54c280a4844e5c615eff1c0862c3c3fe4bf16149bc58b91f4ea5bf6f866f5e76cb9726ada27a230f39fdc0877735b29155a9deca2121df7692514193a34bfc147b6572c74b3b2c300097319176cb33658e92784943233e0971ed677b3276c68c590c899e49832659e0fec9b251bccd9a319ac786b951041c0e8b1f2cc83f1d793e691a61318b4173ca5819b22fe72900f2a50fff6bb1361cb7a057d9bc3b9dc1c6d934323962b7571678debcb3cca93b002c513b9388600f7623bf5a1831326780140b312571d6465961a1aa868ad07b9c34b50a46f10bc7dc7c1ba38b896f1b2da5559c8725d83495441606a99874cedec979e96bba5a13149da0edd0a6e33993ab4810145bb830687cb2c604910e2c33e3c810978c5d4e0ae99d177a19a646d3084ad719b555a7389da122c718274fa310a67ca03da866e6a6582700e966a1f1ed8cf72a5bb77590e208910a313075f7f5c2504f59871b3e7da307fe5e3e4123fb2896e20c45ddaf9cdc54a592f8d16496ef0f275f685261312928f19be085b60ec2d2047ff9b6daeba28648ac5423e2a2ea6c9c476fc4937b013c993a793d6c0ab9960695ba838f649da539ca3d0";
#[cfg(all(feature = "kyber1024", feature = "90s"))]
const CT: &str = "45039c00f10120df9ab21dc99e39e131db36e772d6dbf1674b01c373397c0ac184c6cf643b72cca5b1114563f2e3d77c2662ca7733fd44b44d720b83d2f88800213a1c2c1bad43bbcd8d96d1859ee68e5c31c6c897cf4986fc78ac79eeba67965d65ebb62ad54b45a1cc58a54608b82308932299baa74bff835e81b3fa420a8b7678c16fbd5bfc5d0a48e5114db91a11e205ab7c576ce8f2bdf1fe1d7eef6850709ec0fcd05f5f3e9c796e1b3dbbab0a89a7c87f0c97adf666183ceff8d99dc89ee6ba12b5aa578d297c35a7897cd2256b1975a7dfa1c58a3b764e6b5ae5ad7a6036ef725b0c3cdf6a46505d3ed6b2f22ba8d339180a0b73ffee93ede006c55911ea09a265959be22a527902315bb2eadc1286116019d28477bebe4274483829e9fe7403cda1996b2118fe7599c0ba0b5b4248f55d3d256a97c31511f1ddee17568fa8035cd05bf92d9d8708c20369cae3e79067eb01d5c6fe92f18be94e3e04f45035c29e4ffe01df1c8c4c2b65c4adbfa798fbd4dfbfc755ea2de1820077ccf90feb427436bc3a96481f70561439c79259162f5cdcb644350030e7e9f5d97951bc3a040fc54d26a8776fd89fa0bb14bc98656590257629585b69b6314ecb8ff783fe089419fe9f5e8c40d3385f444ac659b3cc2233cfdc08244f44442a5aa12d6ff3486955ca595e1f83b3193910002b8a65cd6e7a57e046d08761ad374f03133228efd4b9fc794dc5d889e080af2925138559029eab45ba269867a72eec08f32e286b0cc6155bf676503a71a82eafa63e3403f020539ab5de1b574208b05d71bb150eb7c9a8c8766137ce16d8024947cad656926199fc9f750e4bbd8cc99ff3962db5c4bb3d6862947a80f0f2c073c949b69914bfe1dd4e76949c459ee71febbab354d315426a06f99c949be3e41e690d0323da8a18534c31cdb6ee5c7d707eba044ef69251beeb619bf5fb8cabc72c5617c80b0ed77e33dc0e49f8e458facfafb13cdc51c7a50271b6e9428d2913190a35cbad304dcb7b1c24003215de05cbdd34248e57a7a014a2b7a9cb295e2f0194d701ba75f045fdd690874f4a2ebb6081eabf1a4d17ac0b4b7082bbd8852be96505e7c6c0d2bfef26d34a7540e8445144dc7f4243b89d52c59901aaa6faaaa87529925752012a3be0418c70983550733359d23babf17c994339bc411695cb8ec813fc986bf676ac17b7483047279706a7da32fc8c832ae377b09faa50abc0e9319f433f82fed700fff7d3a0b09f3b39fb417e07d07d2db595b9aa2244714633e857a676d6fc01bbdcab69d3b09fb5fb69544cc3ef1413a74336fe59bc2d6fe10a8b3360ab0a011d308d4b267119a822865ec56c6e8e94b0ffa0290fe5dbb391e68e9c06c7f5375a678f37e7f23c1e6eacca4a82a9d20bf14bfccdbc9ac6106782391f2b900d836361e16e563a282992b8ce469a4a166a97c43b13dd67e046eb4b31a63c78075e0126684b8b17cfb3eb37aec09ed44a84c796decd851567fd5aab299ee7e10be6239e70acc00c74e62471a99bf0ef0341ec7cc31e51ac1a96f372c2542c7365fbb32a983344acf738609b1bb6b1e13d8a7a69703e45c54b68586a03c19a119ed7db72d6ea4701bc04784b05607e9bf9c3e1fc4694cef58e3efdbf72e71082cbfd4b4cd957b01b92501ce2af996249a1e54601a9973bfadd8db33e6494f1a1109c9353d3fdc96d5c9c07316d5e75b275bd0603da71cd9896b9c975c91bf3cf1f91adf93eb89af7294cd6c047dd3f88299a8ce56f5aadc607bcaa10bbc8189f6beff6ff5c65b93566ac5d0e4bd6783ba9a0f9072cf5ee6729006d252a110a3bfc5a61d4be6b92f0035e9e3f1a8d725fdd8f3fe129f54567fedf8fee52053279946424a76e8d1522894096f6cc790b49456394fc79812d6bacd2eeeb9fbd1c0aac8cec4767db75ee53a828b62913532c033f7fb5adefe7e7f5e59c077c4dcf3527007fc62ebccff96e3867adf6d4f6a77293da5caffdef083fb7dd3adbd1c4a90cb8b76e8bf65b9b4c6c24b22bf7bbfd8bf6f02e105f880c74d199b5c6482c241b181e8d001aab471cd83eda8d38925702ab1fbe0dd18ba370916dd1c8bdbfa090bc5f2621fb891d94126f0627ced17cf29f74e6c04129de0132f8c19fd3221038ee651ce69f7d43df0b8a0a9e5b5a5deee26396e952cdb55e9855daf870dde03f048b3b8bdfeb435960";

criterion_group!(benches, keypair);
criterion_main!(benches);
20 changes: 20 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © 2023 KyberLib. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This crate is responsible for benchmarking various components of the application.
// extern crate criterion;
// use criterion::{criterion_group, criterion_main};

// /// This is a module for benchmarking API operations.
// mod api;

// Entry point for all benchmarks.
// criterion_group!(
// name = benches;
// config = Criterion::default()
// targets = api::keypair, api::encap, api::decap, api::decap_fail, api::decode_hex
// );

// // Run benchmarks
// criterion_main!(benches);

0 comments on commit bd60663

Please sign in to comment.