flip condition

This commit is contained in:
Rocknest 2020-09-14 02:27:09 +03:00
parent 73863cf72b
commit 988fc6f9d1

View File

@ -59,15 +59,15 @@ pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds:
const dkLen = derivedKey.len;
const hLen = Prf.mac_length;
comptime std.debug.assert(hLen >= 1);
// FromSpec:
//
// 1. If dkLen > maxInt(u32) * hLen, output "derived key too long" and
// stop.
//
if (comptime (maxInt(usize) < maxInt(u32) * hLen) and (dkLen > @as(usize, maxInt(u32) * hLen))) {
if (comptime (maxInt(usize) > maxInt(u32) * hLen) and (dkLen > @as(usize, maxInt(u32) * hLen))) {
// If maxInt(usize) is less than `maxInt(u32) * hLen` then dkLen is always inbounds
// This also asserts hLen >= 1
return error.DerivedKeyTooLong;
}