public abstract class PKCS11KeyAgreement extends javax.crypto.KeyAgreementSpi implements PKCS11EngineClass
Modifier and Type | Field and Description |
---|---|
protected boolean |
currentKeyIsSoftwareKey_
Indicates that the currently used key is a software key.
|
protected boolean |
initialized_
Indicates, if this object is initialized and ready for signing or verification.
|
protected IAIKPKCS11Key |
initKey_
The key used to initialize this object.
|
protected iaik.pkcs.pkcs11.objects.Key |
initKeyObject_
The PKCS#11 key object used to initialize this object..
|
protected PKCS11KeyAgreementSpec |
keyAgreementSpec_
The parameters for this key agreement.
|
protected boolean |
keyAgreementSpecChanged_
Indicates that the parameters for this key agreement changed.
|
protected IAIKPKCS11Key |
phaseKey_
The key used for the current phase
|
protected boolean |
pkcs11OperationInitialized_
Indicates, if the PKCS#11 signature/verify is already initialized for the next operation round.
|
protected iaik.pkcs.pkcs11.Session |
session_
The session this object works with.
|
protected javax.crypto.KeyAgreement |
softwareDelegate_
The software implementation, if the currently used key is not a PKCS#11 key.
|
protected TokenManager |
tokenManager_
Token manager used to login session, if required.
|
protected iaik.pkcs.pkcs11.MechanismInfo[][] |
usedMechanismInfos_
The mechanism info is the same for all digest mechanisms.
|
protected iaik.pkcs.pkcs11.Mechanism[] |
usedMechanisms_
The list of used mechanisms.
|
Constructor and Description |
---|
PKCS11KeyAgreement()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
checkInitKeyObject(iaik.pkcs.pkcs11.objects.Key key)
Check the key object used for initialization, if it is acceptable for this agreement
implementation.
|
protected abstract void |
checkPhaseKeyObject(iaik.pkcs.pkcs11.objects.Key key)
Check the key object used for a phase, if it is acceptable for this agreement implementation.
|
protected java.security.Key |
engineDoPhase(java.security.Key key,
boolean lastPhase)
Returns the key resulting from the next phase of this key agreement.
|
protected byte[] |
engineGenerateSecret()
Returns the shared secret finally generated by this key agreement.
|
protected int |
engineGenerateSecret(byte[] sharedSecret,
int offset)
Generates the shared secret finishing this key agreement procedure and writes it into the given
byte array, beginning at the given offset position.
|
protected javax.crypto.SecretKey |
engineGenerateSecret(java.lang.String algorithm)
Returns the shared secret finally generated by this key agreement as SecretKey to be used for
the secret key algorithm given by its name.
|
protected void |
engineInit(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes this KeyAgreement with the given key, algorithm parameters, and random seed.
|
protected void |
engineInit(java.security.Key key,
java.security.SecureRandom random)
Initializes this KeyAgreement with the given key and random seed, where the given key
constitutes the private key (including all required algorithm parameters) of some entity being
involved in this key agreement procedure.
|
protected byte[] |
extractValue(iaik.pkcs.pkcs11.objects.SecretKey secretKeyObject)
Extract the value of the given secret key object and return it as byte array.
|
protected void |
finalize()
Tries to close the used session.
|
protected void |
finalizePkcs11Operation()
The internal session finalization method, if the current operation has been finished.
|
protected abstract java.lang.String |
getAlgorithmName()
Get the JCA standard name of this key agreement algorithm.
|
protected abstract int |
getMaxSecretLength(iaik.pkcs.pkcs11.objects.Key phaseKey)
Get the maximum length in bytes of the resulting shared secret key.
|
protected abstract iaik.pkcs.pkcs11.Mechanism |
getMechanism()
Get the mechanism that this key agreement uses.
|
protected iaik.pkcs.pkcs11.MechanismInfo[][] |
getUsedMechanismFeatures()
Returns an two-dimensional array of MechanismInfos that this engine class uses.
|
protected iaik.pkcs.pkcs11.Mechanism[] |
getUsedMechanisms()
Returns an array of Mechanisms that this engine class uses.
|
protected void |
initializePkcs11Operation()
The internal session initialization method, if all necessary member variables are set.
|
protected void |
initializeSession()
Sets up an appropriate session.
|
protected void |
initializeSoftwareDelegate()
Instantiate a new software cipher to delegate software keys operations.
|
boolean |
isSupportedBy(TokenManager tokenManager)
Check, if the current token of the given token manager supports the required features for this
engine class.
|
protected java.security.Key |
pkcs11DoPhase(java.security.Key key,
boolean lastPhase)
Returns the key resulting from the next phase of this key agreement.
|
protected byte[] |
pkcs11GenerateSecret()
Returns the shared secret finally generated by this key agreement.
|
protected int |
pkcs11GenerateSecret(byte[] sharedSecret,
int offset)
Generates the shared secret finishing this key agreement procedure and writes it into the given
byte array, beginning at the given offset position.
|
protected javax.crypto.SecretKey |
pkcs11GenerateSecret(java.lang.String algorithm)
Returns the shared secret finally generated by this key agreement as SecretKey to be used for
the secret key algorithm given by its name.
|
protected void |
pkcs11Init(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes this KeyAgreement with the given key, algorithm parameters, and random seed.
|
protected void |
pkcs11Init(java.security.Key key,
java.security.SecureRandom random)
Initializes this KeyAgreement with the given key and random seed, where the given key
constitutes the private key (including all required algorithm parameters) of some entity being
involved in this key agreement procedure.
|
protected TokenManager tokenManager_
protected iaik.pkcs.pkcs11.Session session_
protected PKCS11KeyAgreementSpec keyAgreementSpec_
protected boolean keyAgreementSpecChanged_
protected boolean initialized_
protected boolean pkcs11OperationInitialized_
protected IAIKPKCS11Key initKey_
protected iaik.pkcs.pkcs11.objects.Key initKeyObject_
protected IAIKPKCS11Key phaseKey_
protected boolean currentKeyIsSoftwareKey_
protected javax.crypto.KeyAgreement softwareDelegate_
protected iaik.pkcs.pkcs11.Mechanism[] usedMechanisms_
protected iaik.pkcs.pkcs11.MechanismInfo[][] usedMechanismInfos_
protected iaik.pkcs.pkcs11.Mechanism[] getUsedMechanisms()
getRequiredMechanismFeatures()
method.getUsedMechanismFeatures()
. May be empty, but must not be null.protected iaik.pkcs.pkcs11.MechanismInfo[][] getUsedMechanismFeatures()
getUsedMechanisms()
. The array at this index is the list of used feature
combinations used by this engine. The current token must at least support one mechanism and one
of the feature combinations (expressed as a MechanismInfo) of the same mechanism.getUsedMechanisms()
. The token must at
least support one of these features.public boolean isSupportedBy(TokenManager tokenManager)
isSupportedBy
in interface PKCS11EngineClass
tokenManager
- The token manager. Used to get information about the current token.protected abstract void checkInitKeyObject(iaik.pkcs.pkcs11.objects.Key key) throws java.security.InvalidKeyException
key
- The initialization key object to check.java.security.InvalidKeyException
- If this implementation cannot work with this type of key object.protected abstract void checkPhaseKeyObject(iaik.pkcs.pkcs11.objects.Key key) throws java.security.InvalidKeyException
key
- The phase key object to check.java.security.InvalidKeyException
- If this implementation cannot work with this type of key object.protected void engineInit(java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException
doFinal
methods will represent public key material of another participated entity
or key material resulting from some previously performed phase (if there are more than two
entities involved in the key agreement). This implementation delegates this call to the
software provider, if the key is a software key. If the key is a key of this provider, it
delegates the call to the corresponding pkcs11 method with prefix pkcs11
instead
of engine
.engineInit
in class javax.crypto.KeyAgreementSpi
key
- the private key information of the entity involved in the key agreementrandom
- the random seedjava.security.InvalidKeyException
- if the given key cannot be used for this key agreementprotected void initializeSession()
protected void initializePkcs11Operation()
protected void finalizePkcs11Operation()
protected void initializeSoftwareDelegate()
protected abstract java.lang.String getAlgorithmName()
protected void pkcs11Init(java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException
doFinal
methods will represent public key material of another participated entity
or key material resulting from some previously performed phase (if there are more than two
entities involved in the key agreement).key
- the private key information of the entity involved in the key agreementrandom
- the random seedjava.security.InvalidKeyException
- if the given key cannot be used for this key agreementprotected void engineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
doFinal
methods will represent
public key material of another participated entity or key material resulting from some
previously performed phase (if there are more than two entities involved in the key agreement).
This implementation delegates this call to the software provider, if the key is a software key.
If the key is a key of this provider, it delegates the call to the corresponding pkcs11 method
with prefix pkcs11
instead of engine
.engineInit
in class javax.crypto.KeyAgreementSpi
key
- the private key information of the entity involved in the key agreementparams
- The algorithm parameters used for this key agreement algorithm. It must be a
PKCS11KeyAgreementSpec for this implementation.random
- The random seed. This implementation ignores this parameter.java.security.InvalidKeyException
- if the given key cannot be used for this key agreementjava.security.InvalidAlgorithmParameterException
- if the given parameters do not match to this key agreement algorithmprotected void pkcs11Init(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
doFinal
methods will represent
public key material of another participated entity or key material resulting from some
previously performed phase (if there are more than two entities involved in the key agreement).key
- the private key information of the entity involved in the key agreementparams
- The algorithm parameters used for this key agreement algorithm. It must be a
PKCS11KeyAgreementSpec for this implementation.random
- The random seed. This implementation ignores this parameter.java.security.InvalidKeyException
- if the given key cannot be used for this key agreementjava.security.InvalidAlgorithmParameterException
- if the given parameters do not match to this key agreement algorithmprotected java.security.Key engineDoPhase(java.security.Key key, boolean lastPhase) throws java.security.InvalidKeyException, java.lang.IllegalStateException
pkcs11
instead of engine
.engineDoPhase
in class javax.crypto.KeyAgreementSpi
key
- the required key for this phase, supplied by some other entity involved in this key
agreementlastPhase
- true
if this is the last phase of this key agreement, false
if notnull
if no key is returned by this
phasejava.security.InvalidKeyException
- if the given key cannot be used for this key agreement algorithm / phasejava.lang.IllegalStateException
- if the given phase cannot be performed in this state of the key agreement
procedureprotected java.security.Key pkcs11DoPhase(java.security.Key key, boolean lastPhase) throws java.security.InvalidKeyException, java.lang.IllegalStateException
key
- the required key for this phase, supplied by some other entity involved in this key
agreementlastPhase
- true
if this is the last phase of this key agreement, false
if notnull
if no key is returned by this
phasejava.security.InvalidKeyException
- if the given key cannot be used for this key agreement algorithm / phasejava.lang.IllegalStateException
- if the given phase cannot be performed in this state of the key agreement
procedureprotected byte[] engineGenerateSecret() throws java.lang.IllegalStateException
pkcs11
instead of
engine
.engineGenerateSecret
in class javax.crypto.KeyAgreementSpi
java.lang.IllegalStateException
- if this key agreement procedure yet is not ready for being finished by generating
the shared secretprotected byte[] pkcs11GenerateSecret() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if this key agreement procedure yet is not ready for being finished by generating
the shared secretprotected int engineGenerateSecret(byte[] sharedSecret, int offset) throws java.lang.IllegalStateException, javax.crypto.ShortBufferException
pkcs11
instead of
engine
.engineGenerateSecret
in class javax.crypto.KeyAgreementSpi
sharedSecret
- the byte array to which the generated secret has to be writtenoffset
- the offset indicating the start position within the output byte array to which to
write the generated shared secretjava.lang.IllegalStateException
- if this key agreement procedure yet is not ready for being finished by generating
the shared secretjavax.crypto.ShortBufferException
- if the given output buffer is too small for holding the secretprotected int pkcs11GenerateSecret(byte[] sharedSecret, int offset) throws java.lang.IllegalStateException, javax.crypto.ShortBufferException
sharedSecret
- the byte array to which the generated secret has to be writtenoffset
- the offset indicating the start position within the output byte array to which to
write the generated shared secretjava.lang.IllegalStateException
- if this key agreement procedure yet is not ready for being finished by generating
the shared secretjavax.crypto.ShortBufferException
- if the given output buffer is too small for holding the secretprotected javax.crypto.SecretKey engineGenerateSecret(java.lang.String algorithm) throws java.lang.IllegalStateException, java.security.NoSuchAlgorithmException, java.security.InvalidKeyException
pkcs11
instead of
engine
.engineGenerateSecret
in class javax.crypto.KeyAgreementSpi
algorithm
- The name of the secret key algorithm for which the generated secret key shall be used.
This implementation ignores this parameter.java.lang.IllegalStateException
- if this key agreement procedure yet is not ready for being finished by generating
the shared secretjava.security.NoSuchAlgorithmException
- if the given secret key algorithm is not supportedjava.security.InvalidKeyException
- if the generated shared secret cannot be returned as SecretKey matching to the
given algorithmprotected javax.crypto.SecretKey pkcs11GenerateSecret(java.lang.String algorithm) throws java.lang.IllegalStateException, java.security.NoSuchAlgorithmException, java.security.InvalidKeyException
algorithm
- The name of the secret key algorithm for which the generated secret key shall be used.
This implementation ignores this parameter.java.lang.IllegalStateException
- if this key agreement procedure yet is not ready for being finished by generating
the shared secretjava.security.NoSuchAlgorithmException
- if the given secret key algorithm is not supportedjava.security.InvalidKeyException
- if the generated shared secret cannot be returned as SecretKey matching to the
given algorithmprotected byte[] extractValue(iaik.pkcs.pkcs11.objects.SecretKey secretKeyObject)
secretKeyObject
- The pkcs#11 secret key object to get the value.protected abstract iaik.pkcs.pkcs11.Mechanism getMechanism()
protected abstract int getMaxSecretLength(iaik.pkcs.pkcs11.objects.Key phaseKey)
The provided phase key may help the implementation in determining the maximum length; e.g. for Diffie-Hellman in getting the length of the prime P.
phaseKey
- The (last) phase key which has been passed to engineDoPhase(Key, boolean)
.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- If finalization fails.IAIK JavaSecurity Website https://jce.iaik.tugraz.at/
IAIK at Graz University of Technology, Austria, Europe
Copyright 2001-2023 IAIK, Graz University of Technology, Inffeldgasse 16a, 8010 Graz, Austria. All Rights Reserved. Version 1.9.4