Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PBKDF2WithHmacSHA1 Java speed up?

980860Dec 19 2012 — edited Dec 21 2012
Hello everyone. I'm making model in Java that is able to calculate keys used in WPA/WPA2 protocol. So, model is able to calculate Pairwise Master Key from given "password" and "salt", than calculate Pairwise Transient Key and Eapol hmac. For calculating PMK, "PBKDF2WithHmacSHA1" is used. Every call of that function is extremely slow, and because final idea for this model is to be used in distributed computing environment for testing all possible keys (brute-force) attack I can't accept this slowness of function.

For example, with this code, I'm able to calculate ~56 keys per second and slowest part is PBKDF2WithHmacSHA. And for comparation, program used for same thing on linux (aircrack-ng), written in C, on same computer is able to calculate over 1000 keys per second! Am i mistaking somewhere? Could I implement this in some way that it is going to work faster? Yes, there are 4096 iterations, that's how WPA works. Maybe If I somehow write this method differently it will work faster?
Here is example:

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class temp {
static String pmkAlgorithm = "PBKDF2WithHmacSHA1";
static int pmkLength = 256;
static int pmkIterations = 4096;
static byte[] pmk = new byte[32];

//-------- PMK --------
public static byte[] calculatePmk(char[] password, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException {
KeySpec spec = new PBEKeySpec(password, salt, pmkIterations, pmkLength);
SecretKeyFactory f = SecretKeyFactory.getInstance(pmkAlgorithm);
return f.generateSecret(spec).getEncoded();
}

public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException{
char[] password = "password".toCharArray();
byte[] salt = "salt".getBytes();


long t1 = System.currentTimeMillis();
pmk = calculatePmk(password, salt);
long t2 = System.currentTimeMillis();

System.out.println(t2 - t1);
}

}

Any ideas? THanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2013
Added on Dec 19 2012
6 comments
5,398 views