| ... | ... | @@ -173,9 +173,9 @@ const signatures = [_]Crypto{ |
| 173 | 173 | Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" }, |
| 174 | 174 | }; |
| 175 | 175 | |
| 176 | | pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 { |
| 176 | pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 177 | 177 | const msg = [_]u8{0} ** 64; |
| 178 | | const key_pair = Signature.KeyPair.generate(); |
| 178 | const key_pair = Signature.KeyPair.generate(io); |
| 179 | 179 | |
| 180 | 180 | var timer = try Timer.start(); |
| 181 | 181 | const start = timer.lap(); |
| ... | ... | @@ -201,9 +201,9 @@ const signature_verifications = [_]Crypto{ |
| 201 | 201 | Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" }, |
| 202 | 202 | }; |
| 203 | 203 | |
| 204 | | pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 { |
| 204 | pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 205 | 205 | const msg = [_]u8{0} ** 64; |
| 206 | | const key_pair = Signature.KeyPair.generate(); |
| 206 | const key_pair = Signature.KeyPair.generate(io); |
| 207 | 207 | const sig = try key_pair.sign(&msg, null); |
| 208 | 208 | |
| 209 | 209 | var timer = try Timer.start(); |
| ... | ... | @@ -225,9 +225,9 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign |
| 225 | 225 | |
| 226 | 226 | const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }}; |
| 227 | 227 | |
| 228 | | pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 { |
| 228 | pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 229 | 229 | const msg = [_]u8{0} ** 64; |
| 230 | | const key_pair = Signature.KeyPair.generate(); |
| 230 | const key_pair = Signature.KeyPair.generate(io); |
| 231 | 231 | const sig = try key_pair.sign(&msg, null); |
| 232 | 232 | |
| 233 | 233 | var batch: [64]Signature.BatchElement = undefined; |
| ... | ... | @@ -240,7 +240,7 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime |
| 240 | 240 | { |
| 241 | 241 | var i: usize = 0; |
| 242 | 242 | while (i < signatures_count) : (i += 1) { |
| 243 | | try Signature.verifyBatch(batch.len, batch); |
| 243 | try Signature.verifyBatch(io, batch.len, batch); |
| 244 | 244 | mem.doNotOptimizeAway(&sig); |
| 245 | 245 | } |
| 246 | 246 | } |
| ... | ... | @@ -258,15 +258,15 @@ const kems = [_]Crypto{ |
| 258 | 258 | Crypto{ .ty = crypto.kem.kyber_d00.Kyber1024, .name = "kyber1024d00" }, |
| 259 | 259 | }; |
| 260 | 260 | |
| 261 | | pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 { |
| 262 | | const key_pair = Kem.KeyPair.generate(); |
| 261 | pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 { |
| 262 | const key_pair = Kem.KeyPair.generate(io); |
| 263 | 263 | |
| 264 | 264 | var timer = try Timer.start(); |
| 265 | 265 | const start = timer.lap(); |
| 266 | 266 | { |
| 267 | 267 | var i: usize = 0; |
| 268 | 268 | while (i < kems_count) : (i += 1) { |
| 269 | | const e = key_pair.public_key.encaps(null); |
| 269 | const e = key_pair.public_key.encaps(io); |
| 270 | 270 | mem.doNotOptimizeAway(&e); |
| 271 | 271 | } |
| 272 | 272 | } |
| ... | ... | @@ -278,10 +278,10 @@ pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u |
| 278 | 278 | return throughput; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | | pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 { |
| 282 | | const key_pair = Kem.KeyPair.generate(); |
| 281 | pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 { |
| 282 | const key_pair = Kem.KeyPair.generate(io); |
| 283 | 283 | |
| 284 | | const e = key_pair.public_key.encaps(null); |
| 284 | const e = key_pair.public_key.encaps(io); |
| 285 | 285 | |
| 286 | 286 | var timer = try Timer.start(); |
| 287 | 287 | const start = timer.lap(); |
| ... | ... | @@ -300,13 +300,13 @@ pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_i |
| 300 | 300 | return throughput; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | | pub fn benchmarkKemKeyGen(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 { |
| 303 | pub fn benchmarkKemKeyGen(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 { |
| 304 | 304 | var timer = try Timer.start(); |
| 305 | 305 | const start = timer.lap(); |
| 306 | 306 | { |
| 307 | 307 | var i: usize = 0; |
| 308 | 308 | while (i < kems_count) : (i += 1) { |
| 309 | | const key_pair = Kem.KeyPair.generate(); |
| 309 | const key_pair = Kem.KeyPair.generate(io); |
| 310 | 310 | mem.doNotOptimizeAway(&key_pair); |
| 311 | 311 | } |
| 312 | 312 | } |
| ... | ... | @@ -464,7 +464,9 @@ fn benchmarkPwhash( |
| 464 | 464 | |
| 465 | 465 | const strHash = ty.strHash; |
| 466 | 466 | const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn"; |
| 467 | | const needs_io = strHashFnInfo.params.len == 4; |
| 467 | const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io; |
| 468 | const needs_salt = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type != std.Io; |
| 469 | const salt: [16]u8 = .{0} ** 16; |
| 468 | 470 | |
| 469 | 471 | var timer = try Timer.start(); |
| 470 | 472 | const start = timer.lap(); |
| ... | ... | @@ -473,6 +475,8 @@ fn benchmarkPwhash( |
| 473 | 475 | while (i < count) : (i += 1) { |
| 474 | 476 | if (needs_io) { |
| 475 | 477 | _ = try strHash(password, opts, &buf, io); |
| 478 | } else if (needs_salt) { |
| 479 | _ = try strHash(password, opts, &buf, &salt); |
| 476 | 480 | } else { |
| 477 | 481 | _ = try strHash(password, opts, &buf); |
| 478 | 482 | } |
| ... | ... | @@ -514,7 +518,7 @@ pub fn main(init: std.process.Init) !void { |
| 514 | 518 | |
| 515 | 519 | const args = try init.minimal.args.toSlice(arena); |
| 516 | 520 | |
| 517 | | var filter: ?[]u8 = ""; |
| 521 | var filter: ?[]const u8 = null; |
| 518 | 522 | |
| 519 | 523 | var i: usize = 1; |
| 520 | 524 | while (i < args.len) : (i += 1) { |
| ... | ... | @@ -582,7 +586,7 @@ pub fn main(init: std.process.Init) !void { |
| 582 | 586 | |
| 583 | 587 | inline for (signatures) |E| { |
| 584 | 588 | if (filter == null or std.mem.find(u8, E.name, filter.?) != null) { |
| 585 | | const throughput = try benchmarkSignature(E.ty, mode(1000)); |
| 589 | const throughput = try benchmarkSignature(E.ty, mode(1000), io); |
| 586 | 590 | try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput }); |
| 587 | 591 | try stdout.flush(); |
| 588 | 592 | } |
| ... | ... | @@ -590,7 +594,7 @@ pub fn main(init: std.process.Init) !void { |
| 590 | 594 | |
| 591 | 595 | inline for (signature_verifications) |E| { |
| 592 | 596 | if (filter == null or std.mem.find(u8, E.name, filter.?) != null) { |
| 593 | | const throughput = try benchmarkSignatureVerification(E.ty, mode(1000)); |
| 597 | const throughput = try benchmarkSignatureVerification(E.ty, mode(1000), io); |
| 594 | 598 | try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput }); |
| 595 | 599 | try stdout.flush(); |
| 596 | 600 | } |
| ... | ... | @@ -598,7 +602,7 @@ pub fn main(init: std.process.Init) !void { |
| 598 | 602 | |
| 599 | 603 | inline for (batch_signature_verifications) |E| { |
| 600 | 604 | if (filter == null or std.mem.find(u8, E.name, filter.?) != null) { |
| 601 | | const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000)); |
| 605 | const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000), io); |
| 602 | 606 | try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput }); |
| 603 | 607 | try stdout.flush(); |
| 604 | 608 | } |
| ... | ... | @@ -638,7 +642,7 @@ pub fn main(init: std.process.Init) !void { |
| 638 | 642 | |
| 639 | 643 | inline for (kems) |E| { |
| 640 | 644 | if (filter == null or std.mem.find(u8, E.name, filter.?) != null) { |
| 641 | | const throughput = try benchmarkKem(E.ty, mode(1000)); |
| 645 | const throughput = try benchmarkKem(E.ty, mode(1000), io); |
| 642 | 646 | try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput }); |
| 643 | 647 | try stdout.flush(); |
| 644 | 648 | } |
| ... | ... | @@ -646,7 +650,7 @@ pub fn main(init: std.process.Init) !void { |
| 646 | 650 | |
| 647 | 651 | inline for (kems) |E| { |
| 648 | 652 | if (filter == null or std.mem.find(u8, E.name, filter.?) != null) { |
| 649 | | const throughput = try benchmarkKemDecaps(E.ty, mode(25000)); |
| 653 | const throughput = try benchmarkKemDecaps(E.ty, mode(25000), io); |
| 650 | 654 | try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput }); |
| 651 | 655 | try stdout.flush(); |
| 652 | 656 | } |
| ... | ... | @@ -654,7 +658,7 @@ pub fn main(init: std.process.Init) !void { |
| 654 | 658 | |
| 655 | 659 | inline for (kems) |E| { |
| 656 | 660 | if (filter == null or std.mem.find(u8, E.name, filter.?) != null) { |
| 657 | | const throughput = try benchmarkKemKeyGen(E.ty, mode(25000)); |
| 661 | const throughput = try benchmarkKemKeyGen(E.ty, mode(25000), io); |
| 658 | 662 | try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput }); |
| 659 | 663 | try stdout.flush(); |
| 660 | 664 | } |