PBKDF2SHA512: make hLen a constant

This commit is contained in:
Sean Gilligan 2023-09-12 10:50:23 -07:00 committed by Andreas Schildbach
parent c830107bce
commit 4e039df446

View file

@ -37,16 +37,17 @@ import java.nio.charset.StandardCharsets;
* @see <a href="https://cryptofreek.org/2012/11/29/pbkdf2-pure-java-implementation/">PBKDF2 Pure Java Implementation by Cryptofreek</a>
*/
public class PBKDF2SHA512 {
// Length of HMAC result
private static final int H_LEN = 64;
public static byte[] derive(String P, String S, int c, int dkLen) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
int hLen = 64; // Length of HMAC result
if (dkLen > ((Math.pow(2, 32)) - 1) * hLen) {
if (dkLen > ((Math.pow(2, 32)) - 1) * H_LEN) {
throw new IllegalArgumentException("derived key too long");
} else {
int l = (int) Math.ceil((double) dkLen / (double) hLen);
int l = (int) Math.ceil((double) dkLen / (double) H_LEN);
// int r = dkLen - (l-1)*hLen;
for (int i = 1; i <= l; i++) {