mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
PBKDF2SHA512: don't allow negative count or dkLen
This commit is contained in:
parent
140deb0669
commit
ee23c2d6ff
1 changed files with 4 additions and 0 deletions
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
package org.bitcoinj.crypto;
|
package org.bitcoinj.crypto;
|
||||||
|
|
||||||
|
import org.bitcoinj.base.internal.Preconditions;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -41,6 +43,8 @@ public class PBKDF2SHA512 {
|
||||||
private static final int H_LEN = 64;
|
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) {
|
||||||
|
Preconditions.checkArgument(c > 0, () -> "count must be greater than zero");
|
||||||
|
Preconditions.checkArgument(dkLen > 0, () -> "derived key length must be greater than zero");
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
if (dkLen > ((Math.pow(2, 32)) - 1) * H_LEN) {
|
if (dkLen > ((Math.pow(2, 32)) - 1) * H_LEN) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue