java.lang.Object
org.bouncycastle.pqc.crypto.util.SecretWithEncapsulationImpl
- All Implemented Interfaces:
Destroyable, SecretWithEncapsulation
Implementation of SecretWithEncapsulation for post-quantum cryptography. Provides secure storage and destruction of encapsulated secrets and session keys.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]The encapsulated key sent to the other side.private final AtomicBooleanSet once the key material has been wiped.private final byte[]The shared secret that was established.Constructor Summary
ConstructorsConstructorDescriptionSecretWithEncapsulationImpl(byte[] sessionKey, byte[] cipher_text) Stores the shared key and the encapsulated key.Method Summary
Public MethodsModifier and TypeMethodDescription(package private) voidThrows if the secret has already been destroyed.voiddestroy()Zeroes the session key and encapsulated key.byte[]Returns a copy of the encapsulated key.byte[]Returns a copy of the KEM session key.booleanReports whether destroy() has already run.
Field Details
hasBeenDestroyed
Set once the key material has been wiped.sessionKey
private final byte[] sessionKeyThe shared secret that was established.cipher_text
private final byte[] cipher_textThe encapsulated key sent to the other side.
Constructor Details
SecretWithEncapsulationImpl
public SecretWithEncapsulationImpl(byte[] sessionKey, byte[] cipher_text) Stores the shared key and the encapsulated key.- Parameters:
sessionKey- the shared key agreed by the KEM, zeroed bydestroy()and copied on every readcipher_text- the encapsulated key produced by the encapsulator, zeroed by destroy() and copied on every read
Method Details
getSecret
public byte[] getSecret()Returns a copy of the KEM session key.- Specified by:
getSecretin interfaceSecretWithEncapsulation- Returns:
- a copy of the KEM session key
- Throws:
IllegalStateException- if the secret has already been destroyed
getEncapsulation
public byte[] getEncapsulation()Returns a copy of the encapsulated key.- Specified by:
getEncapsulationin interfaceSecretWithEncapsulation- Returns:
- a copy of the encapsulated key
- Throws:
IllegalStateException- if the secret has already been destroyed
destroy
Zeroes the session key and encapsulated key.- Specified by:
destroyin interfaceDestroyable- Throws:
DestroyFailedException
isDestroyed
public boolean isDestroyed()Reports whether destroy() has already run.- Specified by:
isDestroyedin interfaceDestroyable- Returns:
- true if the secret has been destroyed
checkDestroyed
void checkDestroyed()Throws if the secret has already been destroyed.