| ... | @@ -67,8 +67,8 @@ pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: | ... | @@ -67,8 +67,8 @@ pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: |
| 67 | // 1. If dkLen > maxInt(u32) * hLen, output "derived key too long" and | 67 | // 1. If dkLen > maxInt(u32) * hLen, output "derived key too long" and |
| 68 | // stop. | 68 | // stop. |
| 69 | // | 69 | // |
| 70 | if (comptime (maxInt(usize) > maxInt(u32) * hLen) and (dkLen > @as(usize, maxInt(u32) * hLen))) { | 70 | if (dkLen / hLen >= maxInt(u32)) { |
| 71 | // If maxInt(usize) is less than `maxInt(u32) * hLen` then dkLen is always inbounds | 71 | // Counter starts at 1 and is 32 bit, so if we have to return more blocks, we would overflow |
| 72 | return error.OutputTooLong; | 72 | return error.OutputTooLong; |
| 73 | } | 73 | } |
| 74 | | 74 | |