Calibrate PBKDF2 iterations on first run. Fixes development issue #29.

This commit is contained in:
akwizgran
2013-12-05 23:18:07 +00:00
parent bab2aca584
commit db5702d7fc
2 changed files with 89 additions and 14 deletions

View File

@@ -38,4 +38,18 @@ public class PasswordBasedKdfTest extends BriarTestCase {
byte[] output = crypto.decryptWithPassword(ciphertext, password);
assertNull(output);
}
@Test
public void testCalibration() {
CryptoComponentImpl crypto = new CryptoComponentImpl();
// If the target time is unachievable, one iteration should be used
int iterations = crypto.chooseIterationCount(0);
assertEquals(1, iterations);
// If the target time is long, more than one iteration should be used
iterations = crypto.chooseIterationCount(10 * 1000);
assertTrue(iterations > 1);
// If the target time is very long, max iterations should be used
iterations = crypto.chooseIterationCount(Integer.MAX_VALUE);
assertEquals(Integer.MAX_VALUE, iterations);
}
}