mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
PBKDF2SHA512: make hLen a constant
This commit is contained in:
parent
c830107bce
commit
4e039df446
1 changed files with 5 additions and 4 deletions
|
@ -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>
|
* @see <a href="https://cryptofreek.org/2012/11/29/pbkdf2-pure-java-implementation/">PBKDF2 – Pure Java Implementation by Cryptofreek</a>
|
||||||
*/
|
*/
|
||||||
public class PBKDF2SHA512 {
|
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) {
|
public static byte[] derive(String P, String S, int c, int dkLen) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int hLen = 64; // Length of HMAC result
|
if (dkLen > ((Math.pow(2, 32)) - 1) * H_LEN) {
|
||||||
|
|
||||||
if (dkLen > ((Math.pow(2, 32)) - 1) * hLen) {
|
|
||||||
throw new IllegalArgumentException("derived key too long");
|
throw new IllegalArgumentException("derived key too long");
|
||||||
} else {
|
} 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;
|
// int r = dkLen - (l-1)*hLen;
|
||||||
|
|
||||||
for (int i = 1; i <= l; i++) {
|
for (int i = 1; i <= l; i++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue