Bouncy Castle Cryptography Library 1.87

org.bouncycastle.jcajce.provider.asymmetric.util
Class BaseAgreementSpi

java.lang.Object
  extended byjavax.crypto.KeyAgreementSpi
      extended byorg.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi
Direct Known Subclasses:
GMKeyExchangeSpi, KeyAgreementSpi, KeyAgreementSpi, KeyAgreementSpi, KeyAgreementSpi, KeyAgreementSpi, KeyAgreementSpi

public abstract class BaseAgreementSpi
extends javax.crypto.KeyAgreementSpi


Field Summary
protected  java.lang.String kaAlgorithm
           
protected  DerivationFunction kdf
           
protected  byte[] ukmParameters
           
protected  byte[] ukmParametersSalt
           
 
Constructor Summary
BaseAgreementSpi(java.lang.String kaAlgorithm, DerivationFunction kdf)
           
 
Method Summary
protected  void agreementCompleted()
          Record that the agreement has run to completion and its shared secret may now be generated.
protected  void checkAgreementCompleted()
          Refuse a shared secret asked for before the agreement has completed. javax.crypto.KeyAgreement specifies IllegalStateException for that state; without this each SPI would hand back whatever its result field happened to hold, which for DH was the private value itself.
protected  void checkKdfSalt(UserKeyingMaterialSpec spec)
          Refuse a UserKeyingMaterialSpec whose salt this agreement would have no use for.
protected abstract  byte[] doCalcSecret()
           
protected abstract  void doInitFromKey(java.security.Key key, java.security.spec.AlgorithmParameterSpec parameterSpec, java.security.SecureRandom random)
           
protected  byte[] engineGenerateSecret()
           
protected  int engineGenerateSecret(byte[] sharedSecret, int offset)
           
protected  javax.crypto.SecretKey engineGenerateSecret(java.lang.String algorithm)
           
protected  void engineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
           
protected  void engineInit(java.security.Key key, java.security.SecureRandom random)
           
protected static java.lang.String getAlgorithm(java.lang.String algDetails)
           
protected  void resetAgreement()
          Require a fresh agreement before the next shared secret.
protected static byte[] trimZeroes(byte[] secret)
           
 
Methods inherited from class javax.crypto.KeyAgreementSpi
engineDoPhase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kaAlgorithm

protected final java.lang.String kaAlgorithm

kdf

protected final DerivationFunction kdf

ukmParameters

protected byte[] ukmParameters

ukmParametersSalt

protected byte[] ukmParametersSalt
Constructor Detail

BaseAgreementSpi

public BaseAgreementSpi(java.lang.String kaAlgorithm,
                        DerivationFunction kdf)
Method Detail

getAlgorithm

protected static java.lang.String getAlgorithm(java.lang.String algDetails)

trimZeroes

protected static byte[] trimZeroes(byte[] secret)

engineInit

protected void engineInit(java.security.Key key,
                          java.security.SecureRandom random)
                   throws java.security.InvalidKeyException
Throws:
java.security.InvalidKeyException

engineInit

protected void engineInit(java.security.Key key,
                          java.security.spec.AlgorithmParameterSpec params,
                          java.security.SecureRandom random)
                   throws java.security.InvalidKeyException,
                          java.security.InvalidAlgorithmParameterException
Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException

agreementCompleted

protected void agreementCompleted()
Record that the agreement has run to completion and its shared secret may now be generated. A subclass calls this on the successful return of the doPhase that completes the agreement.


resetAgreement

protected void resetAgreement()
Require a fresh agreement before the next shared secret. Called by the engineInit methods here; a subclass that overrides one of those rather than doInitFromKey must call this itself.


checkKdfSalt

protected void checkKdfSalt(UserKeyingMaterialSpec spec)
                     throws java.security.InvalidAlgorithmParameterException
Refuse a UserKeyingMaterialSpec whose salt this agreement would have no use for. Only an HKDF (RFC 5869) based agreement takes a KDF salt; every other agreement would silently derive its key without it, so a salt given to one is a mismatch between the caller and the algorithm.

Parameters:
spec - the user keying material the agreement was initialised with.
Throws:
java.security.InvalidAlgorithmParameterException - if the spec carries a salt and the KDF is not HKDF.

checkAgreementCompleted

protected void checkAgreementCompleted()
Refuse a shared secret asked for before the agreement has completed. javax.crypto.KeyAgreement specifies IllegalStateException for that state; without this each SPI would hand back whatever its result field happened to hold, which for DH was the private value itself.

Throws:
java.lang.IllegalStateException - if no doPhase has completed the agreement since the last init.

engineGenerateSecret

protected byte[] engineGenerateSecret()
                               throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

engineGenerateSecret

protected int engineGenerateSecret(byte[] sharedSecret,
                                   int offset)
                            throws java.lang.IllegalStateException,
                                   javax.crypto.ShortBufferException
Throws:
java.lang.IllegalStateException
javax.crypto.ShortBufferException

engineGenerateSecret

protected javax.crypto.SecretKey engineGenerateSecret(java.lang.String algorithm)
                                               throws java.security.NoSuchAlgorithmException
Throws:
java.security.NoSuchAlgorithmException

doCalcSecret

protected abstract byte[] doCalcSecret()

doInitFromKey

protected abstract void doInitFromKey(java.security.Key key,
                                      java.security.spec.AlgorithmParameterSpec parameterSpec,
                                      java.security.SecureRandom random)
                               throws java.security.InvalidKeyException,
                                      java.security.InvalidAlgorithmParameterException
Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException

Bouncy Castle Cryptography Library 1.87