| ... | ... | @@ -297,32 +297,32 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int) !u64 { |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | const CryptoPwhash = struct { |
| 300 | | hashFn: @compileError("anytype fields are removed from the language"), |
| 301 | | params: @compileError("anytype fields are removed from the language"), |
| 300 | ty: type, |
| 301 | params: *const anyopaque, |
| 302 | 302 | name: []const u8, |
| 303 | 303 | }; |
| 304 | 304 | const bcrypt_params = crypto.pwhash.bcrypt.Params{ .rounds_log = 12 }; |
| 305 | 305 | const pwhashes = [_]CryptoPwhash{ |
| 306 | | .{ .hashFn = crypto.pwhash.bcrypt.strHash, .params = bcrypt_params, .name = "bcrypt" }, |
| 306 | .{ .ty = crypto.pwhash.bcrypt, .params = &bcrypt_params, .name = "bcrypt" }, |
| 307 | 307 | .{ |
| 308 | | .hashFn = crypto.pwhash.scrypt.strHash, |
| 309 | | .params = crypto.pwhash.scrypt.Params.interactive, |
| 308 | .ty = crypto.pwhash.scrypt, |
| 309 | .params = &crypto.pwhash.scrypt.Params.interactive, |
| 310 | 310 | .name = "scrypt", |
| 311 | 311 | }, |
| 312 | 312 | .{ |
| 313 | | .hashFn = crypto.pwhash.argon2.strHash, |
| 314 | | .params = crypto.pwhash.argon2.Params.interactive_2id, |
| 313 | .ty = crypto.pwhash.argon2, |
| 314 | .params = &crypto.pwhash.argon2.Params.interactive_2id, |
| 315 | 315 | .name = "argon2", |
| 316 | 316 | }, |
| 317 | 317 | }; |
| 318 | 318 | |
| 319 | 319 | fn benchmarkPwhash( |
| 320 | | comptime hashFn: anytype, |
| 321 | | comptime params: anytype, |
| 320 | comptime ty: anytype, |
| 321 | comptime params: *const anyopaque, |
| 322 | 322 | comptime count: comptime_int, |
| 323 | 323 | ) !f64 { |
| 324 | 324 | const password = "testpass" ** 2; |
| 325 | | const opts = .{ .allocator = std.testing.allocator, .params = params, .encoding = .phc }; |
| 325 | const opts = .{ .allocator = std.testing.allocator, .params = @ptrCast(*const ty.Params, params).*, .encoding = .phc }; |
| 326 | 326 | var buf: [256]u8 = undefined; |
| 327 | 327 | |
| 328 | 328 | var timer = try Timer.start(); |
| ... | ... | @@ -330,7 +330,7 @@ fn benchmarkPwhash( |
| 330 | 330 | { |
| 331 | 331 | var i: usize = 0; |
| 332 | 332 | while (i < count) : (i += 1) { |
| 333 | | _ = try hashFn(password, opts, &buf); |
| 333 | _ = try ty.strHash(password, opts, &buf); |
| 334 | 334 | mem.doNotOptimizeAway(&buf); |
| 335 | 335 | } |
| 336 | 336 | } |
| ... | ... | @@ -463,8 +463,8 @@ pub fn main() !void { |
| 463 | 463 | |
| 464 | 464 | inline for (pwhashes) |H| { |
| 465 | 465 | if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) { |
| 466 | | const throughput = try benchmarkPwhash(H.hashFn, H.params, mode(64)); |
| 467 | | try stdout.print("{s:>17}: {d:.3} s/ops\n", .{ H.name, throughput }); |
| 466 | const throughput = try benchmarkPwhash(H.ty, H.params, mode(64)); |
| 467 | try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput }); |
| 468 | 468 | } |
| 469 | 469 | } |
| 470 | 470 | } |