public class LunaKeyAgreementDh extends KeyAgreementSpi
| Modifier and Type | Field and Description |
|---|---|
protected KeyFactory |
kf |
protected LunaKey |
privateKey |
| Constructor and Description |
|---|
LunaKeyAgreementDh() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkPublicKey(Key key,
boolean lastPhase)
Checks the parameters to engineDoPhase().
|
protected Key |
engineDoPhase(Key key,
boolean lastPhase)
Executes the next phase of this key agreement with the given key that
was received from the other party involved in this key agreement.
|
protected byte[] |
engineGenerateSecret()
Generates the shared secret and returns it in a new buffer.
|
protected int |
engineGenerateSecret(byte[] sharedSecret,
int offset)
Generates the shared secret, and places it into the buffer
sharedSecret, beginning at offset inclusive. |
protected SecretKey |
engineGenerateSecret(String algorithm)
Creates the shared secret and returns it as a secret key object of
the requested algorithm type.
|
protected void |
engineInit(Key key,
AlgorithmParameterSpec params,
SecureRandom random)
Initializes this key agreement with the given key.
|
protected void |
engineInit(Key key,
SecureRandom random)
Initializes this key agreement.
|
protected int |
getDerivedKeyLength(long algId)
Returns the derived key length in bytes for a key of the given algorithm.
|
protected int |
getMaxSharedSecretLength()
The maximum size of the generated key will be equal to the size of
the prime, in bits.
|
protected LunaKey privateKey
protected final KeyFactory kf
protected void engineInit(Key key, SecureRandom random) throws InvalidKeyException
engineInit in class KeyAgreementSpikey - The party's private information, typically the local party's
private key. If the private key does not already exist on the HSM
it is injected into the HSM as a session objectrandom - Unused. The Luna HSM has its own source of randomnessInvalidKeyException - If the given key is not a DHPrivateKeyprotected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException
The Luna provider only supports two-party key exchanges, so this method
can only be called once per exchange, with lastPhase set
to true
engineDoPhase in class KeyAgreementSpikey - The other party's public keylastPhase - Must be set to trueIllegalStateException - If this key agreement has not been initialized,
or if lastPhase is falseInvalidKeyException - If the given key is not a DHPublicKey, or if
it is not in the same slot as the private key that the agreement was
initialized withprotected SecretKey engineGenerateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException
This method resets this KeyAgreement object, so that it
can be reused for further key agreements. Unless this key agreement is
reinitialized with one of the init methods, the same
private information will be used for subsequent key agreements. However,
doPhase will have to be called after every call to
generateSecret in order to re-initialize the public information.
engineGenerateSecret in class KeyAgreementSpialgorithm - The requested secret key algorithmIllegalStateException - If this key agreement has not been
completed yetNoSuchAlgorithmException - If the requested secret key
algorithm is not availableInvalidKeyException - If the key material is too short to
generate the requested secret keyprotected int getMaxSharedSecretLength()
protected void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
engineInit in class KeyAgreementSpikey - The party's private information, typically the local party's
private keyparams - Any additional information required for the key agreement.random - Unused. The Luna HSM has its own source of randomnessInvalidKeyException - If the given key is of the wrong type for
this key agreement or has an incompatible algorithm typeInvalidAlgorithmParameterExceptionprotected void checkPublicKey(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException
key - The other party's public keylastPhase - Must be set to trueIllegalStateException - If this key agreement has not been initialized,
or if lastPhase is falseInvalidKeyException - If the pubic key's slot doesn't match the
private key's slotprotected byte[] engineGenerateSecret()
throws IllegalStateException
LunaSlotManager.
setExtractableKeys(true) has been set. If LunaSlotManager
is set to create non-extractable keys, the shared secret will remain on
the HSM. In this case an encoded version of the key handle is returned.
This method resets this KeyAgreement object, so that it
can be reused for further key agreements. Unless this key agreement is
reinitialized with one of the init methods, the same
private information will be used for subsequent key agreements. However,
doPhase will have to be called after every call to
generateSecret in order to re-initialize the public information.
engineGenerateSecret in class KeyAgreementSpiIllegalStateExceptionprotected int engineGenerateSecret(byte[] sharedSecret,
int offset)
throws IllegalStateException,
ShortBufferException
sharedSecret, beginning at offset inclusive.
If the sharedSecret buffer is too small to hold the result,
a ShortBufferException is thrown. In this case, the key
agreement is not reset and the call can be repeated with a larger output
buffer.
Successful completion of this method resets this KeyAgreement
object, so that it can be reused for further key agreements. Unless this
key agreement is reinitialized with one of the init methods,
the same private information will be used for subsequent key agreements.
However, doPhase will have to be called after every call to
generateSecret in order to re-initialize the public information.
engineGenerateSecret in class KeyAgreementSpisharedSecret - The buffer for the shared secretoffset - The offset in sharedSecret where the shared
secret will be storedsharedSecretIllegalStateException - If this key agreement has not been completed yetShortBufferException - If the given output buffer is too small to
hold the secretprotected int getDerivedKeyLength(long algId)
throws NoSuchAlgorithmException
algId - Algorithm of the secret keyNoSuchAlgorithmException - If the algorithm id is not recognizedCopyright 2014-2016 SafeNet Inc