Top Fields Constructors Methods
org.bouncycastle.pqc.jcajce.provider.newhope

public Class KeyAgreementSpi

extends BaseAgreementSpi
Class Inheritance
Imports
java.security.InvalidAlgorithmParameterException, .InvalidKeyException, .Key, .SecureRandom, java.security.spec.AlgorithmParameterSpec, javax.crypto.ShortBufferException, org.bouncycastle.crypto.params.AsymmetricKeyParameter, org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi, org.bouncycastle.pqc.crypto.ExchangePair, org.bouncycastle.pqc.crypto.newhope.NHAgreement, .NHExchangePairGenerator, .NHPublicKeyParameters, org.bouncycastle.util.Arrays

Field Summary

Modifier and TypeField and Description
private NHAgreement
private NHExchangePairGenerator
private BCNHPublicKey
private byte[]
Inherited from org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi:
kaAlgorithmkdfukmParametersukmParametersSalt

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected byte[]
protected void
protected Key
engineDoPhase(Key
the key for this phase. For example, in the case of Diffie-Hellman between 2 parties, this would be the other party's Diffie-Hellman public key.
key
,
boolean
flag which indicates whether this is the last phase of this key agreement.
lastPhase
)

Implements abstract javax.crypto.KeyAgreementSpi.engineDoPhase.

Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement.

protected byte[]
engineGenerateSecret()

Overrides org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.engineGenerateSecret.

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

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

Overrides org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.engineGenerateSecret.

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

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
secureRandom
)

Overrides org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.engineInit.

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

Inherited from org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi:
engineGenerateSecretengineInitgetAlgorithmgetKeySizetrimZeroes

Field Detail

agreementback to summary
private NHAgreement agreement
exchangePairGeneratorback to summary
private NHExchangePairGenerator exchangePairGenerator
otherPartyKeyback to summary
private BCNHPublicKey otherPartyKey
sharedback to summary
private byte[] shared

Constructor Detail

KeyAgreementSpiback to summary
public KeyAgreementSpi()

Method Detail

doCalcSecretback to summary
protected byte[] doCalcSecret()

Implements abstract org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.doCalcSecret.

doInitFromKeyback to summary
protected void doInitFromKey(Key key, AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.doInitFromKey.

engineDoPhaseback to summary
protected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException

Implements abstract javax.crypto.KeyAgreementSpi.engineDoPhase.

Doc from javax.crypto.KeyAgreementSpi.engineDoPhase.

Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement.

Parameters
key:Key

the key for this phase. For example, in the case of Diffie-Hellman between 2 parties, this would be the other party's Diffie-Hellman public key.

lastPhase:boolean

flag which indicates whether this is the last phase of this key agreement.

Returns:Key

the (intermediate) key resulting from this phase, or null if this phase does not yield a key

Exceptions
InvalidKeyException:
if the given key is inappropriate for this phase.
IllegalStateException:
if this key agreement has not been initialized.
engineGenerateSecretback to summary
protected byte[] engineGenerateSecret() throws IllegalStateException

Overrides org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.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[] bytes, int offset) throws IllegalStateException, ShortBufferException

Overrides org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.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
bytes: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
engineInitback to summary
protected void engineInit(Key key, SecureRandom secureRandom) throws InvalidKeyException

Overrides org.bouncycastle.jcajce.provider.asymmetric.util.BaseAgreementSpi.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.

secureRandom: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.