public class ScryptSecureHasher extends AbstractSecureHasher
Scrypt
for secure password hashing.
One critical difference is that this implementation uses a
static universal salt unless instructed otherwise, which provides
strict determinism across nodes in a cluster. The purpose for this is to allow for
blind equality comparison of sensitive values hashed on different nodes (with
potentially different nifi.sensitive.props.key
values) during flow inheritance
(see FingerprintFactory
).
The resulting output is referred to as a hash to be consistent with SecureHasher
terminology,
but the length parameter is clarified as the derived key length dkLen
in Scrypt terms, not to be
confused with the internal concept of hash length for the PBKDF2 cryptographic hash function (CHF) primitive (SHA-256).
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_DK_LENGTH |
private static int |
DEFAULT_N
These values can be calculated automatically using the code
ScryptCipherProviderGroovyTest#calculateMinimumParameters or manually updated by a maintainer |
private static int |
DEFAULT_P |
private static int |
DEFAULT_R |
private static int |
DEFAULT_SALT_LENGTH |
private int |
dkLength |
private static org.slf4j.Logger |
logger |
private static int |
MAX_R |
private static int |
MAX_SALT_LENGTH |
private static int |
MIN_DK_LENGTH |
private static int |
MIN_N |
private static int |
MIN_P |
private static int |
MIN_R |
private static int |
MIN_SALT_LENGTH |
private int |
n |
private int |
p |
private int |
r |
saltLength, UPPER_BOUNDARY
Constructor and Description |
---|
ScryptSecureHasher()
Instantiates an Scrypt secure hasher using the default cost parameters
(
N = DEFAULT_N ,
r = DEFAULT_R ,
p = DEFAULT_R ,
dkLen = DEFAULT_DK_LENGTH ). |
ScryptSecureHasher(int n,
int r,
int p,
int dkLength)
Instantiates an Scrypt secure hasher using the provided cost parameters.
|
ScryptSecureHasher(int n,
int r,
int p,
int dkLength,
int saltLength)
Instantiates an Scrypt secure hasher using the provided cost parameters.
|
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
acceptsEmptyInput()
Returns
true if the algorithm can accept empty (non-null ) inputs. |
(package private) String |
getAlgorithmName()
Returns the algorithm-specific name for logging and messages.
|
int |
getDefaultSaltLength()
Returns the algorithm-specific default salt length in bytes.
|
int |
getMaxSaltLength()
Returns the algorithm-specific maximum salt length in bytes.
|
int |
getMinSaltLength()
Returns the algorithm-specific minimum salt length in bytes.
|
(package private) byte[] |
hash(byte[] input)
Internal method to hash the raw bytes.
|
(package private) byte[] |
hash(byte[] input,
byte[] rawSalt)
Internal method to hash the raw bytes.
|
protected static boolean |
isDKLengthValid(Integer dkLength)
Returns whether the provided hash (derived key) length is within boundaries.
|
protected static boolean |
isNValid(Integer n,
int r)
Returns true if the provided iteration count N is within boundaries.
|
protected static boolean |
isPValid(int p,
int r)
Returns true if the provided parallelization factor is within boundaries.
|
protected static boolean |
isRValid(int r)
Returns true if the provided block size in bytes is within boundaries.
|
private void |
validateParameters(Integer n,
Integer r,
int p,
Integer dkLength,
Integer saltLength)
Enforces valid Scrypt secure hasher cost parameters are provided.
|
getSalt, hashBase64, hashBase64, hashHex, hashHex, hashRaw, hashRaw, initializeSalt, isSaltLengthValid, isUsingStaticSalt
private static final org.slf4j.Logger logger
private static final int DEFAULT_N
ScryptCipherProviderGroovyTest#calculateMinimumParameters
or manually updated by a maintainerprivate static final int DEFAULT_R
private static final int DEFAULT_P
private static final int DEFAULT_DK_LENGTH
private static final int DEFAULT_SALT_LENGTH
private static final int MIN_P
private static final int MIN_DK_LENGTH
private static final int MIN_N
private static final int MIN_R
private static final int MAX_R
private static final int MIN_SALT_LENGTH
private static final int MAX_SALT_LENGTH
private final int n
private final int r
private final int p
private final int dkLength
public ScryptSecureHasher()
N =
DEFAULT_N
,
r =
DEFAULT_R
,
p =
DEFAULT_R
,
dkLen =
DEFAULT_DK_LENGTH
). A static salt is also used.public ScryptSecureHasher(int n, int r, int p, int dkLength)
DEFAULT_SALT_LENGTH
byte salt will be generated on every hash request.n
- number of iterations (power of 2 from 1 to 2^(128 * r / 8)
)r
- the block size of memory (> 0
)p
- parallelization factor from (1 to ((2^32-1) * 32) / (128 * r)
)dkLength
- the output length in bytes (1 to (2^32 - 1) * 32
)public ScryptSecureHasher(int n, int r, int p, int dkLength, int saltLength)
n
- number of iterations (power of 2 from 1 to 2^(128 * r / 8)
)r
- the block size of memory (> 0
)p
- parallelization factor from (1 to ((2^32-1) * 32) / (128 * r)
)dkLength
- the output length in bytes (1 to (2^32 - 1) * 32
)saltLength
- the salt length in bytes >= 8
)private void validateParameters(Integer n, Integer r, int p, Integer dkLength, Integer saltLength)
n
- number of iterations (power of 2 from 1 to 2^(128 * r / 8)
)r
- the block size of memory (> 0
)p
- parallelization factor from (1 to ((2^32-1) * 32) / (128 * r)
)dkLength
- the output length in bytes (1 to (2^32 - 1) * 32
)saltLength
- the salt length in bytes >= 8
)byte[] hash(byte[] input)
hash
in class AbstractSecureHasher
input
- the raw bytes to hash (can be length 0)byte[] hash(byte[] input, byte[] rawSalt)
hash
in class AbstractSecureHasher
input
- the raw bytes to hash (can be length 0)rawSalt
- the raw bytes to saltprotected static boolean isNValid(Integer n, int r)
n
- number of iterationsr
- the blocksize parameterprotected static boolean isRValid(int r)
r
- the integer number * 128 B usedprotected static boolean isPValid(int p, int r)
p
- degree of parallelismr
- the blocksize parameterprotected static boolean isDKLengthValid(Integer dkLength)
dkLength
- the output length in bytespublic int getDefaultSaltLength()
getDefaultSaltLength
in class AbstractSecureHasher
public int getMinSaltLength()
AbstractSecureHasher
getMinSaltLength
in class AbstractSecureHasher
public int getMaxSaltLength()
AbstractSecureHasher
getMaxSaltLength
in class AbstractSecureHasher
String getAlgorithmName()
AbstractSecureHasher
getAlgorithmName
in class AbstractSecureHasher
boolean acceptsEmptyInput()
AbstractSecureHasher
true
if the algorithm can accept empty (non-null
) inputs.acceptsEmptyInput
in class AbstractSecureHasher
""
is allowable inputCopyright © 2020 Apache NiFi Project. All rights reserved.