com.lambdaworks.crypto
Class SCryptLessAlloc

java.lang.Object
  extended by com.lambdaworks.crypto.SCryptLessAlloc

public class SCryptLessAlloc
extends 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.

Author:
Will Glozer

Constructor Summary
SCryptLessAlloc()
           
 
Method Summary
static void blockmix_salsa8(byte[] BY, int Bi, int Yi, int r, byte[] X, int[] B32, int[] salsaX)
           
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, int[] B32, int[] x)
           
static byte[] scrypt(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen)
          Implementation of the scrypt KDF.
static byte[] scryptJ(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen)
          Pure Java implementation of the scrypt KDF.
static byte[] scryptN(byte[] passwd, byte[] salt, long N, int r, int p, int dkLen)
          Native C implementation of the scrypt KDF using the code from http://www.tarsnap.com/scrypt.html.
static void smix(byte[] B, int Bi, int r, int N, byte[] V, byte[] XY, byte[] X, int[] B32, int[] salsaX)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SCryptLessAlloc

public SCryptLessAlloc()
Method Detail

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 implementation scryptN(byte[], byte[], long, int, int, int) when the native library was successfully loaded, otherwise calls scryptJ(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,
                             long N,
                             int r,
                             int p,
                             int dkLen)
Native C implementation of the scrypt KDF using the code from http://www.tarsnap.com/scrypt.html.

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
Pure Java implementation of the scrypt KDF.

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,
                        byte[] X,
                        int[] B32,
                        int[] salsaX)

blockmix_salsa8

public static void blockmix_salsa8(byte[] BY,
                                   int Bi,
                                   int Yi,
                                   int r,
                                   byte[] X,
                                   int[] B32,
                                   int[] salsaX)

R

public static int R(int a,
                    int b)

salsa20_8

public static void salsa20_8(byte[] B,
                             int[] B32,
                             int[] x)

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)


Copyright © 2012. All Rights Reserved.