PBKDF2SHA512: move dkLen check out of try/catch

It throws an exception so doesn't need an if/else
and it also doesn't need to be in the try.
This commit is contained in:
Sean Gilligan 2023-09-14 11:26:41 -07:00 committed by Andreas Schildbach
parent 4e039df446
commit 140deb0669

View file

@ -43,17 +43,16 @@ public class PBKDF2SHA512 {
public static byte[] derive(String P, String S, int c, int dkLen) { public static byte[] derive(String P, String S, int c, int dkLen) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (dkLen > ((Math.pow(2, 32)) - 1) * H_LEN) {
throw new IllegalArgumentException("derived key too long");
}
try { try {
if (dkLen > ((Math.pow(2, 32)) - 1) * H_LEN) { int l = (int) Math.ceil((double) dkLen / (double) H_LEN);
throw new IllegalArgumentException("derived key too long"); // int r = dkLen - (l-1)*hLen;
} else {
int l = (int) Math.ceil((double) dkLen / (double) H_LEN);
// int r = dkLen - (l-1)*hLen;
for (int i = 1; i <= l; i++) { for (int i = 1; i <= l; i++) {
byte[] T = F(P, S, c, i); byte[] T = F(P, S, c, i);
baos.write(T); baos.write(T);
}
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);