Package com.eatthepath.noise.component
Interface NoiseKeyAgreement
public interface NoiseKeyAgreement
A Noise key agreement implementation encapsulates the key agreement functions of a Noise protocol. A Noise key
agreement generates key pairs for key agreement operations with the remote party in a Noise handshake, performs key
agreement operations, and converts keys to and from "raw" formats for serialization in Noise messages.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
checkKeyPair
(KeyPair keyPair) Checks that both of the keys in the given key pair are compatible with this key agreement algorithm.void
checkPublicKey
(PublicKey publicKey) Checks that the given public key is compatible with this key agreement algorithm.deserializePublicKey
(byte[] publicKeyBytes) Interprets a "raw" public key as aPublicKey
compatible with this key agreement algorithm.Generates a new key pair compatible with this key agreement algorithm for use in a Noise handshake.byte[]
generateSecret
(PrivateKey privateKey, PublicKey publicKey) Calculates a shared secret from a local private key and a remote public key.static NoiseKeyAgreement
getInstance
(String noiseKeyAgreementName) Returns aNoiseKeyAgreement
instance that implements the named key agreement algorithm.getName()
Returns the name of this Noise key agreement as it would appear in a full Noise protocol name.int
Returns the length of public keys and shared secrets generated by this key agreement algorithm.byte[]
serializePublicKey
(PublicKey publicKey) Serializes a public key compatible with this key agreement algorithm to an array of bytes suitable for transmission in a Noise handshake message.
-
Method Details
-
getInstance
Returns aNoiseKeyAgreement
instance that implements the named key agreement algorithm. This method recognizes the following key agreement algorithm names:- 25519
- Returns a Noise key agreement implementation backed by the
KeyAgreement
returned by the most preferred security provider that supports the "X25519" algorithm - 448
- Returns a Noise key agreement implementation backed by the
KeyAgreement
returned by the most preferred security provider that supports the "X448" algorithm
- Parameters:
noiseKeyAgreementName
- the name of the Noise key agreement algorithm for which to return a concreteNoiseKeyAgreement
implementation- Returns:
- a concrete
NoiseKeyAgreement
implementation for the given algorithm name - Throws:
NoSuchAlgorithmException
- if the given name is a known Noise key agreement name, but the underlying key agreement algorithm is not supported by any security provider in the current JVMIllegalArgumentException
- if the given name is not a known Noise key agreement name- See Also:
-
getName
String getName()Returns the name of this Noise key agreement as it would appear in a full Noise protocol name.- Returns:
- the name of this Noise key agreement as it would appear in a full Noise protocol name
-
generateKeyPair
KeyPair generateKeyPair()Generates a new key pair compatible with this key agreement algorithm for use in a Noise handshake.- Returns:
- a new key pair for use in a Noise handshake
-
generateSecret
Calculates a shared secret from a local private key and a remote public key.- Parameters:
privateKey
- the local private key from which to calculate a shared secretpublicKey
- the remote public key from which to calculate a shared secret- Returns:
- a shared secret of length
getPublicKeyLength()
- Throws:
IllegalArgumentException
- if either the local private key or remote public key is not a valid key for this key agreement algorithm
-
getPublicKeyLength
int getPublicKeyLength()Returns the length of public keys and shared secrets generated by this key agreement algorithm.- Returns:
- the length of public keys and shared secrets generated by this key agreement algorithm
-
serializePublicKey
Serializes a public key compatible with this key agreement algorithm to an array of bytes suitable for transmission in a Noise handshake message.- Parameters:
publicKey
- the public key to serialize as an array of bytes- Returns:
- a byte array containing the "raw" public key
- See Also:
-
deserializePublicKey
Interprets a "raw" public key as aPublicKey
compatible with this key agreement algorithm.- Parameters:
publicKeyBytes
- the "raw" public key bytes to interpret; must have a length ofgetPublicKeyLength()
- Returns:
- a
PublicKey
instance defined by the givenpublicKeyBytes
- Throws:
IllegalArgumentException
- if the given array of bytes could not be interpreted as a public key compatible with this key agreement algorithm for any reason- See Also:
-
checkPublicKey
Checks that the given public key is compatible with this key agreement algorithm.- Parameters:
publicKey
- the public key to check for compatibility with this key agreement algorithm- Throws:
InvalidKeyException
- if the given key is not compatible with this key agreement algorithm
-
checkKeyPair
Checks that both of the keys in the given key pair are compatible with this key agreement algorithm.- Parameters:
keyPair
- the key pair to check for compatibility with this key agreement algorithm- Throws:
InvalidKeyException
- if either key in the given key pair is not compatible with this key agreement algorithm
-