Top Fields Constructors Methods
org.bouncycastle.jcajce.provider.asymmetric.util

public abstract Class BaseAgreementSpi

extends KeyAgreementSpi
Class Inheritance
Known Direct Subclasses
org.bouncycastle.pqc.jcajce.provider.newhope.KeyAgreementSpi, org.bouncycastle.jcajce.provider.asymmetric.dh.KeyAgreementSpi, org.bouncycastle.jcajce.provider.asymmetric.ec.KeyAgreementSpi, org.bouncycastle.jcajce.provider.asymmetric.ecgost.KeyAgreementSpi, org.bouncycastle.jcajce.provider.asymmetric.ecgost12.KeyAgreementSpi, org.bouncycastle.jcajce.provider.asymmetric.edec.KeyAgreementSpi
Imports
java.security.InvalidAlgorithmParameterException, .InvalidKeyException, .Key, .NoSuchAlgorithmException, .SecureRandom, java.security.spec.AlgorithmParameterSpec, java.util.HashMap, .Hashtable, .Map, javax.crypto.KeyAgreementSpi, .SecretKey, .ShortBufferException, javax.crypto.spec.SecretKeySpec, org.bouncycastle.asn1.ASN1ObjectIdentifier, org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers, org.bouncycastle.asn1.nist.NISTObjectIdentifiers, org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers, org.bouncycastle.crypto.DerivationFunction, org.bouncycastle.crypto.agreement.kdf.DHKDFParameters, .DHKEKGenerator, org.bouncycastle.crypto.generators.HKDFBytesGenerator, org.bouncycastle.crypto.params.DESParameters, .HKDFParameters, .KDFParameters, org.bouncycastle.internal.asn1.gnu.GNUObjectIdentifiers, org.bouncycastle.internal.asn1.kisa.KISAObjectIdentifiers, org.bouncycastle.internal.asn1.misc.MiscObjectIdentifiers, org.bouncycastle.internal.asn1.ntt.NTTObjectIdentifiers, org.bouncycastle.internal.asn1.oiw.OIWObjectIdentifiers, org.bouncycastle.jcajce.spec.HybridValueParameterSpec, org.bouncycastle.util.Arrays, .Integers, .Strings

Field Summary

Modifier and TypeField and Description
private static final Map<String, ASN1ObjectIdentifier>
private static final Hashtable<K, V>
private HybridValueParameterSpec
protected final String
protected final DerivationFunction
private static final Map<String, Integer>
private static final Map<String, String>
private static final Hashtable<K, V>
protected byte[]
protected byte[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private byte[]
protected abstract byte[]
protected abstract void
protected byte[]
engineGenerateSecret()

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret and returns it in a new buffer.

protected int
engineGenerateSecret(byte[]
the buffer for the shared secret
sharedSecret
,
int
the offset in sharedSecret where the shared secret will be stored
offset
)

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret, and places it into the buffer sharedSecret, beginning at offset inclusive.

protected SecretKey
engineGenerateSecret(String
the requested secret key algorithm
algorithm
)

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Creates the shared secret and returns it as a secret key object of the requested algorithm type.

protected void
engineInit(Key
the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.
key
,
SecureRandom
the source of randomness
random
)

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key and source of randomness.

protected void
engineInit(Key
the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.
key
,
AlgorithmParameterSpec
the key agreement parameters
params
,
SecureRandom
the source of randomness
random
)

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness.

protected static String
getAlgorithm(String algDetails)

protected static int
getKeySize(String algDetails)

private byte[]
getSharedSecretBytes(byte[] secret, String oidAlgorithm, int keySize)

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

Inherited from javax.crypto.KeyAgreementSpi:
engineDoPhase

Field Detail

defaultOidsback to summary
private static final Map<String, ASN1ObjectIdentifier> defaultOids
desback to summary
private static final Hashtable<K, V> des
hybridSpecback to summary
private HybridValueParameterSpec hybridSpec
kaAlgorithmback to summary
protected final String kaAlgorithm
kdfback to summary
protected final DerivationFunction kdf
keySizesback to summary
private static final Map<String, Integer> keySizes
nameTableback to summary
private static final Map<String, String> nameTable
oidsback to summary
private static final Hashtable<K, V> oids
ukmParametersback to summary
protected byte[] ukmParameters
ukmParametersSaltback to summary
protected byte[] ukmParametersSalt

Constructor Detail

BaseAgreementSpiback to summary
public BaseAgreementSpi(String kaAlgorithm, DerivationFunction kdf)

Method Detail

calcSecretback to summary
private byte[] calcSecret()
doCalcSecretback to summary
protected abstract byte[] doCalcSecret()
doInitFromKeyback to summary
protected abstract void doInitFromKey(Key key, AlgorithmParameterSpec parameterSpec, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
engineGenerateSecretback to summary
protected byte[] engineGenerateSecret() throws IllegalStateException

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Doc from javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret and returns it in a new buffer.

This method resets this KeyAgreementSpi object to the state that it was in after the most recent call to one of the init methods. After a call to generateSecret, the object can be reused for further key agreement operations by calling doPhase to supply new keys, and then calling generateSecret to produce a new secret. In this case, the private information and algorithm parameters supplied to init will be used for multiple key agreement operations. The init method can be called after generateSecret to change the private information used in subsequent operations.

Returns:byte[]

the new buffer with the shared secret

Exceptions
IllegalStateException:
if this key agreement has not been initialized or if doPhase has not been called to supply the keys for all parties in the agreement
engineGenerateSecretback to summary
protected int engineGenerateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferException

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Doc from javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret, and places it into the buffer sharedSecret, beginning at offset inclusive.

If the sharedSecret buffer is too small to hold the result, a ShortBufferException is thrown. In this case, this call should be repeated with a larger output buffer.

This method resets this KeyAgreementSpi object to the state that it was in after the most recent call to one of the init methods. After a call to generateSecret, the object can be reused for further key agreement operations by calling doPhase to supply new keys, and then calling generateSecret to produce a new secret. In this case, the private information and algorithm parameters supplied to init will be used for multiple key agreement operations. The init method can be called after generateSecret to change the private information used in subsequent operations.

Parameters
sharedSecret:byte[]

the buffer for the shared secret

offset:int

the offset in sharedSecret where the shared secret will be stored

Returns:int

the number of bytes placed into sharedSecret

Exceptions
IllegalStateException:
if this key agreement has not been initialized or if doPhase has not been called to supply the keys for all parties in the agreement
ShortBufferException:
if the given output buffer is too small to hold the secret
engineGenerateSecretback to summary
protected SecretKey engineGenerateSecret(String algorithm) throws NoSuchAlgorithmException

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Doc from javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Creates the shared secret and returns it as a secret key object of the requested algorithm type.

This method resets this KeyAgreementSpi object to the state that it was in after the most recent call to one of the init methods. After a call to generateSecret, the object can be reused for further key agreement operations by calling doPhase to supply new keys, and then calling generateSecret to produce a new secret. In this case, the private information and algorithm parameters supplied to init will be used for multiple key agreement operations. The init method can be called after generateSecret to change the private information used in subsequent operations.

Parameters
algorithm:String

the requested secret key algorithm

Returns:SecretKey

the shared secret key

Exceptions
NoSuchAlgorithmException:
if the requested secret key algorithm is not available
engineInitback to summary
protected void engineInit(Key key, SecureRandom random) throws InvalidKeyException

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Doc from javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key and source of randomness. The given key is required to contain all the algorithm parameters required for this key agreement.

If the key agreement algorithm requires random bytes, it gets them from the given source of randomness, random. However, if the underlying algorithm implementation does not require any random bytes, random is ignored.

Parameters
key:Key

the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for this key agreement, e.g., is of the wrong type or has an incompatible algorithm type.
engineInitback to summary
protected void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Doc from javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness.

Parameters
key:Key

the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.

params:AlgorithmParameterSpec

the key agreement parameters

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for this key agreement, e.g., is of the wrong type or has an incompatible algorithm type.
InvalidAlgorithmParameterException:
if the given parameters are inappropriate for this key agreement.
getAlgorithmback to summary
protected static String getAlgorithm(String algDetails)
getKeySizeback to summary
protected static int getKeySize(String algDetails)
getSharedSecretBytesback to summary
private byte[] getSharedSecretBytes(byte[] secret, String oidAlgorithm, int keySize) throws NoSuchAlgorithmException
trimZeroesback to summary
protected static byte[] trimZeroes(byte[] secret)