| |
---|
| | |
---|
| | /** |
---|
| | * 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 <mark.george@otago.ac.nz> |
---|
| | */ |
---|
| | public final class ScryptHelper { |
---|
| |
---|
| | return result; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * 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. |
---|
| | * |
---|
| |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | 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)); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /* |
---|
| | * Source: https://stackoverflow.com/a/9670279 |
---|
| |
---|
|