Package com.eatthepath.noise.component
Interface NoiseHash
public interface NoiseHash
A Noise hash implementation encapsulates the hashing functionality of a Noise protocol. A Noise hash provides
MessageDigest
instances that implement the Noise hash's hashing algorithm, Mac
instances using the
same algorithm for calculating HMAC digests, and key derivation function.-
Method Summary
Modifier and TypeMethodDescriptiondefault byte[][]
deriveKeys
(byte[] chainingKey, byte[] inputKeyMaterial, int outputKeys) Derives two or three pseudo-random keys from the given chaining key and input key material using the HKDF algorithm with this Noise hash's HMAC algorithm.int
Returns the length of a digest produced by theMessageDigest
orMac
provided by this Noise hash.getHmac()
Returns a newMac
instance for calculating HMAC digests using this Noise hash's hashing algorithm.static NoiseHash
getInstance
(String noiseHashName) Returns aNoiseHash
instance that implements the named hash algorithm.Returns a newMessageDigest
for calculating hashes using this Noise hash's hashing algorithm.getName()
Returns the name of this Noise hash as it would appear in a full Noise protocol name.
-
Method Details
-
getInstance
Returns a
NoiseHash
instance that implements the named hash algorithm. This method recognizes the following hash names:- SHA256
- Returns a Noise hash implementation backed by the
MessageDigest
returned by the most preferred security provider that supports the "SHA-256" algorithm and theMac
returned by the most preferred security provider that supports the "HmacSHA256" algorithm - SHA512
- Returns a Noise hash implementation backed by the
MessageDigest
returned by the most preferred security provider that supports the "SHA-512" algorithm and theMac
returned by the most preferred security provider that supports the "HmacSHA512" algorithm - BLAKE2s
- Returns a Noise hash implementation backed by BLAKE2s implementations included in java-noise
- BLAKE2b
- Returns a Noise hash implementation backed by BLAKE2b implementations included in java-noise
Every implementation of the Java platform is required to support the "SHA-256" and "HmacSHA256" algorithms. Java-noise provides its own BLAKE2b/BLAKE2s implementations.
- Parameters:
noiseHashName
- the name of the Noise hash algorithm for which to return a concreteNoiseHash
implementation- Returns:
- a concrete
NoiseCipher
implementation for the given algorithm name - Throws:
NoSuchAlgorithmException
- if the given name is "SHA512" and either the "SHA-512" or "HmacSHA512" algorithm is not supported by any security provider in the current JVMIllegalArgumentException
- if the given name is not a known Noise hash name- See Also:
-
getName
String getName()Returns the name of this Noise hash as it would appear in a full Noise protocol name.- Returns:
- the name of this Noise hash as it would appear in a full Noise protocol name
-
getMessageDigest
MessageDigest getMessageDigest()Returns a newMessageDigest
for calculating hashes using this Noise hash's hashing algorithm.- Returns:
- a new
MessageDigest
for calculating hashes
-
getHmac
Mac getHmac()Returns a newMac
instance for calculating HMAC digests using this Noise hash's hashing algorithm.- Returns:
- a new
Mac
instance for calculating HMAC digests
-
getHashLength
int getHashLength()Returns the length of a digest produced by theMessageDigest
orMac
provided by this Noise hash.- Returns:
- the length of a digest produced by this Noise hash
-
deriveKeys
default byte[][] deriveKeys(byte[] chainingKey, byte[] inputKeyMaterial, int outputKeys) Derives two or three pseudo-random keys from the given chaining key and input key material using the HKDF algorithm with this Noise hash's HMAC algorithm.
As the Noise Protocol Framework specification notes:
Note that [the derived keys] are all [
getHashLength()
] bytes in length. Also note that the [deriveKeys
] function is simply HKDF from [IETF RFC 5869] with the chaining_key as HKDF salt, and zero-length HKDF info.- Parameters:
chainingKey
- the chaining key (salt) from which to derive new keysinputKeyMaterial
- the input key material from which to derive new keysoutputKeys
- the number of keys to derive; must be either 2 or 3- Returns:
- an array containing
outputKeys
derived keys - See Also:
-