org.bouncycastle.crypto.modes.AESGCMSIVModePacketCipher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-lts8on Show documentation
Show all versions of bcprov-lts8on Show documentation
The Long Term Stable (LTS) Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains the JCA/JCE provider and low-level API for the BC LTS version 2.73.7 for Java 8 and later.
package org.bouncycastle.crypto.modes;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.ExceptionMessages;
import org.bouncycastle.crypto.PacketCipher;
import org.bouncycastle.crypto.params.AEADParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.util.Arrays;
public interface AESGCMSIVModePacketCipher
extends PacketCipher
{
/**
* The nonce length.
*/
int NONCELEN = 12;
default void checkParameters(CipherParameters parameters)
{
byte[] myNonce;
KeyParameter myKey;
if (parameters instanceof AEADParameters)
{
final AEADParameters myAEAD = (AEADParameters)parameters;
myNonce = myAEAD.getNonce();
myKey = myAEAD.getKey();
}
else if (parameters instanceof ParametersWithIV)
{
final ParametersWithIV myParms = (ParametersWithIV)parameters;
myNonce = Arrays.clone(myParms.getIV());
myKey = (KeyParameter)myParms.getParameters();
}
else
{
throw new IllegalArgumentException(ExceptionMessages.GCM_SIV_INVALID_PARAMETER);
}
/* Check nonceSize */
if (myNonce == null || myNonce.length != NONCELEN)
{
throw new IllegalArgumentException(ExceptionMessages.GCM_SIV_IV_SIZE);
}
/* Check keysize */
if (myKey == null || (myKey.getKeyLength() != 16 && myKey.getKeyLength() != 32))
{
throw new IllegalArgumentException(ExceptionMessages.AES_KEY_LENGTH);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy