diff --git a/src/main/java/helpers/ScryptHelper.java b/src/main/java/helpers/ScryptHelper.java index bf4c903..0503a26 100644 --- a/src/main/java/helpers/ScryptHelper.java +++ b/src/main/java/helpers/ScryptHelper.java @@ -15,7 +15,8 @@ /** * Wrapper for Bouncy Castle's scrypt implementation. * - * Generates salted scrypt hashes in a format similar to Modular Crypt Format (MCF). + * Generates salted scrypt hashes in a format similar to Modular Crypt Format + * (MCF). * * @author Mark George */ @@ -73,8 +74,7 @@ } /** - * Checks a hash (as generated by the hash method) against a - * password. + * Checks a hash (as generated by the hash method) against a password. * * @param mcfHash The MCF formatted hash. * @param password The password. @@ -130,14 +130,12 @@ } private static int log2(int operand) { - int result = 0; - - do { - operand = operand >> 1; - result++; - } while (operand > 1); - - return result; + double log2 = Math.log(operand) / Math.log(2); + if (log2 % 1 != 0) { + throw new IllegalArgumentException("N must be a power of 2."); + } else { + return Math.toIntExact(Math.round(log2)); + } } /*