Class SCrypt
java.lang.Object
com.lambdaworks.crypto.SCrypt
An implementation of the scrypt
key derivation function. This class will attempt to load a native library
containing the optimized C implementation from
http://www.tarsnap.com/scrypt.html and
fall back to the pure Java version if that fails.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidblockmix_salsa8(byte[] BY, int Bi, int Yi, int r) static voidblockxor(byte[] S, int Si, byte[] D, int Di, int len) static intintegerify(byte[] B, int Bi, int r) static intR(int a, int b) static voidsalsa20_8(byte[] B) static byte[]scrypt(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen) static byte[]scryptJ(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen) static byte[]scryptN(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen) static voidsmix(byte[] B, int Bi, int r, int N, byte[] V, byte[] XY)
-
Field Details
-
native_library_loaded
private static final boolean native_library_loaded
-
-
Constructor Details
-
SCrypt
public SCrypt()
-
-
Method Details
-
scrypt
public static byte[] scrypt(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen) throws GeneralSecurityException Implementation of the scrypt KDF. Calls the native implementationscryptN(byte[], byte[], int, int, int, int)when the native library was successfully loaded, otherwise callsscryptJ(byte[], byte[], int, int, int, int).- Parameters:
passwd- Password.salt- Salt.N- CPU cost parameter.r- Memory cost parameter.p- Parallelization parameter.dkLen- Intended length of the derived key.- Returns:
- The derived key.
- Throws:
GeneralSecurityException- when HMAC_SHA256 is not available.
-
scryptN
public static byte[] scryptN(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen) - Parameters:
passwd- Password.salt- Salt.N- CPU cost parameter.r- Memory cost parameter.p- Parallelization parameter.dkLen- Intended length of the derived key.- Returns:
- The derived key.
-
scryptJ
public static byte[] scryptJ(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen) throws GeneralSecurityException - Parameters:
passwd- Password.salt- Salt.N- CPU cost parameter.r- Memory cost parameter.p- Parallelization parameter.dkLen- Intended length of the derived key.- Returns:
- The derived key.
- Throws:
GeneralSecurityException- when HMAC_SHA256 is not available.
-
smix
public static void smix(byte[] B, int Bi, int r, int N, byte[] V, byte[] XY) -
blockmix_salsa8
public static void blockmix_salsa8(byte[] BY, int Bi, int Yi, int r) -
R
public static int R(int a, int b) -
salsa20_8
public static void salsa20_8(byte[] B) -
blockxor
public static void blockxor(byte[] S, int Si, byte[] D, int Di, int len) -
integerify
public static int integerify(byte[] B, int Bi, int r)
-