public class LunaKeyAgreementEcDh extends KeyAgreementSpi
| Modifier and Type | Field and Description |
|---|---|
protected KeyFactory |
kf |
protected LunaKey |
privateKey |
| Modifier | Constructor and Description |
|---|---|
|
LunaKeyAgreementEcDh() |
protected |
LunaKeyAgreementEcDh(long kdf,
boolean cof) |
| 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()
Wrapper function around engineGenerateSecretWantBytes.
|
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)
Wrapper function around engineGenerateSecretWantBytes.
|
protected SecretKey |
engineGenerateSecretWantBytes(String algorithm,
boolean wantBytes)
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 key size is the maximum size of key that this curve can generate,
in bits.
|
protected LunaKey privateKey
protected final KeyFactory kf
public LunaKeyAgreementEcDh()
protected LunaKeyAgreementEcDh(long kdf,
boolean cof)
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 an ECPrivateKeyprotected 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 an ECPublicKey, or if
it is not in the same slot as the private key that the agreement was
initialized withprotected SecretKey engineGenerateSecretWantBytes(String algorithm, boolean wantBytes) 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.
algorithm - The requested secret key algorithmwantBytes - A hint that the caller just wants the key bytesIllegalStateException - 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 byte[] engineGenerateSecret()
throws IllegalStateException
IllegalStateExceptionprotected SecretKey engineGenerateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException
engineGenerateSecret in class KeyAgreementSpiIllegalStateExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionprotected 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 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