Package com.lambdaworks.crypto
Class SCrypt
- java.lang.Object
-
- com.lambdaworks.crypto.SCrypt
-
public class SCrypt extends java.lang.Object
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 Modifier and Type Field Description private static boolean
native_library_loaded
-
Constructor Summary
Constructors Constructor Description SCrypt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
blockmix_salsa8(byte[] BY, int Bi, int Yi, int r)
static void
blockxor(byte[] S, int Si, byte[] D, int Di, int len)
static int
integerify(byte[] B, int Bi, int r)
static int
R(int a, int b)
static void
salsa20_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 void
smix(byte[] B, int Bi, int r, int N, byte[] V, byte[] XY)
-
-
-
Method Detail
-
scrypt
public static byte[] scrypt(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen) throws java.security.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:
java.security.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 java.security.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:
java.security.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)
-
-