Top Description Fields Constructors Methods
org.bouncycastle.pqc.jcajce.provider.util

public abstract Class AsymmetricBlockCipher

extends CipherSpiExt
Class Inheritance
Known Direct Subclasses
org.bouncycastle.pqc.jcajce.provider.mceliece.McEliecePKCSCipherSpi
Imports
java.io.ByteArrayOutputStream, java.security.InvalidAlgorithmParameterException, .InvalidKeyException, .InvalidParameterException, .Key, .SecureRandom, java.security.spec.AlgorithmParameterSpec, javax.crypto.BadPaddingException, .IllegalBlockSizeException, .ShortBufferException, org.bouncycastle.crypto.CryptoServicesRegistrar

The AsymmetricBlockCipher class extends CipherSpiExt.

Note

Some Ciphers are using Padding. OneAndZeroesPadding is used as default padding. However padding can still be specified, but mode is not supported; if you try to instantiate the cipher with something else than "NONE" as mode NoSuchAlgorithmException is thrown.

Field Summary

Modifier and TypeField and Description
protected ByteArrayOutputStream
buf

Internal buffer

protected int
cipherTextSize

The maximum number of bytes the cipher can encrypt.

protected int
maxPlainTextSize

The maximum number of bytes the cipher can decrypt.

protected AlgorithmParameterSpec
paramSpec

ParameterSpec used with this cipher

Inherited from org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt:
DECRYPT_MODEENCRYPT_MODEopMode

Constructor Summary

AccessConstructor and Description
public
AsymmetricBlockCipher()

The AsymmetricBlockCipher() constructor

Method Summary

Modifier and TypeMethod and Description
protected void
checkLength(int
length of the input to check
inLen
)

Check if the message length plus the length of the input length can be en/decrypted.

public final byte[]

Returns:

a new buffer with the result
doFinal
(byte[]
the input buffer
input
,
int
the offset where the input starts
inOff
,
int
the input length
inLen
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.doFinal.

Finish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).

public final int

Returns:

the output length
doFinal
(byte[]
the input buffer
input
,
int
the offset where the input starts
inOff
,
int
the input length
inLen
,
byte[]
the buffer for the result
output
,
int
the offset where the result is stored
outOff
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.doFinal.

Finish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).

public final int

Returns:

if the cipher is not a hybrid one the max plain/cipher text size is returned, otherwise 0 is returned
getBlockSize
()

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getBlockSize.

Return the block size (in bytes).

public final byte[]

Returns:

null since no initialization vector is used.
getIV
()

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getIV.

Return the initialization vector.

public final int

Returns:

the length of the ciphertext or 0 if the input is too long.
getOutputSize
(int
the length of the input
inLen
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getOutputSize.

Return the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inLen (in bytes).

public final AlgorithmParameterSpec

Returns:

the parameters used with this cipher, or null if this cipher does not use any parameters.
getParameters
()

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getParameters.

Returns the parameters used with this cipher.

protected abstract void
initCipherDecrypt(Key
the key which has to be used to decrypt data
key
,
AlgorithmParameterSpec
the algorithm parameters
params
)

Initialize the AsymmetricBlockCipher with a certain key for data encryption.

protected abstract void
initCipherEncrypt(Key
the key which has to be used to encrypt data
key
,
AlgorithmParameterSpec
the algorithm parameters
params
,
SecureRandom
the source of randomness
sr
)

Initialize the AsymmetricBlockCipher with a certain key for data encryption.

public final void
initDecrypt(Key
the encryption or decryption key.
key
)

Initialize the cipher for decryption by forwarding it to initDecrypt(Key, AlgorithmParameterSpec).

public final void
initDecrypt(Key
the key which has to be used to decrypt data.
key
,
AlgorithmParameterSpec
the algorithm parameters.
params
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.initDecrypt.

This method initializes the AsymmetricBlockCipher with a certain key for data decryption.

public final void
initEncrypt(Key
the encryption or decryption key.
key
)

Initializes the cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom).

public final void
initEncrypt(Key
the encryption or decryption key.
key
,
SecureRandom
the source of randomness.
random
)

Initialize this cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom, AlgorithmParameterSpec).

public final void
initEncrypt(Key
the encryption or decryption key.
key
,
AlgorithmParameterSpec
the algorithm parameters.
params
)

Initializes the cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom, AlgorithmParameterSpec).

public final void
initEncrypt(Key
the key which has to be used to encrypt data.
key
,
AlgorithmParameterSpec
the algorithm parameters.
params
,
SecureRandom
the source of randomness.
secureRandom
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.initEncrypt.

This method initializes the AsymmetricBlockCipher with a certain key for data encryption.

protected abstract byte[]

Returns:

the decrypted message
messageDecrypt
(byte[]
the ciphertext to be decrypted (the ciphertext length is less than or equal to maxCipherTextSize)
input
)

Decrypt the ciphertext stored in input.

protected abstract byte[]

Returns:

the encrypted message (it has length equal to maxCipherTextSize_)
messageEncrypt
(byte[]
the message to be encrypted (usually the message length is less than or equal to maxPlainTextSize)
input
)

Encrypt the message stored in input.

protected final void
setMode(String
the cipher mode (unused)
modeName
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.setMode.

Since asymmetric block ciphers do not support modes, this method does nothing.

protected final void
setPadding(String
the name of the padding scheme (not used)
paddingName
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.setPadding.

Since asymmetric block ciphers do not support padding, this method does nothing.

public final byte[]

Returns:

a new buffer with the result (always empty)
update
(byte[]
byte array containing the next part of the input
input
,
int
index in the array where the input starts
inOff
,
int
length of the input
inLen
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.update.

Continue a multiple-part encryption or decryption operation.

public final int

Returns:

the length of the output (always 0)
update
(byte[]
the input buffer
input
,
int
the offset where the input starts
inOff
,
int
the input length
inLen
,
byte[]
the output buffer
output
,
int
the offset where the result is stored
outOff
)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.update.

Continue a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.

Inherited from org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt:
doFinaldoFinalengineDoFinalengineDoFinalengineGetBlockSizeengineGetIVengineGetKeySizeengineGetOutputSizeengineGetParametersengineInitengineInitengineInitengineSetModeengineSetPaddingengineUpdateengineUpdategetKeySizegetNameupdate

Field Detail

bufback to summary
protected ByteArrayOutputStream buf

Internal buffer

cipherTextSizeback to summary
protected int cipherTextSize

The maximum number of bytes the cipher can encrypt.

maxPlainTextSizeback to summary
protected int maxPlainTextSize

The maximum number of bytes the cipher can decrypt.

paramSpecback to summary
protected AlgorithmParameterSpec paramSpec

ParameterSpec used with this cipher

Constructor Detail

AsymmetricBlockCipherback to summary
public AsymmetricBlockCipher()

The AsymmetricBlockCipher() constructor

Method Detail

checkLengthback to summary
protected void checkLength(int inLen) throws IllegalBlockSizeException

Check if the message length plus the length of the input length can be en/decrypted. This method uses the specific values maxPlainTextSize and cipherTextSize which are set by the implementations. If the input length plus the length of the internal buffer is greater than maxPlainTextSize for encryption or not equal to cipherTextSize for decryption, an IllegalBlockSizeException will be thrown.

Parameters
inLen:int

length of the input to check

Exceptions
IllegalBlockSizeException:
if the input length is invalid.
doFinalback to summary
public final byte[] doFinal(byte[] input, int inOff, int inLen) throws IllegalBlockSizeException, BadPaddingException

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.doFinal.

Finish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).

Parameters
input:byte[]

the input buffer

inOff:int

the offset where the input starts

inLen:int

the input length

Returns:byte[]

a new buffer with the result

Exceptions
IllegalBlockSizeException:
if the plaintext or ciphertext size is too large.
BadPaddingException:
if the ciphertext is invalid.
doFinalback to summary
public final int doFinal(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.doFinal.

Finish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).

Parameters
input:byte[]

the input buffer

inOff:int

the offset where the input starts

inLen:int

the input length

output:byte[]

the buffer for the result

outOff:int

the offset where the result is stored

Returns:int

the output length

Exceptions
ShortBufferException:
if the output buffer is too small to hold the result.
IllegalBlockSizeException:
if the plaintext or ciphertext size is too large.
BadPaddingException:
if the ciphertext is invalid.
getBlockSizeback to summary
public final int getBlockSize()

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getBlockSize.

Return the block size (in bytes).

Note

although the ciphers extending this class are not block ciphers, the method was adopted to return the maximal plaintext and ciphertext sizes for non hybrid ciphers. If the cipher is hybrid, it returns 0.

Returns:int

if the cipher is not a hybrid one the max plain/cipher text size is returned, otherwise 0 is returned

getIVback to summary
public final byte[] getIV()

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getIV.

Doc from org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getIV.

Return the initialization vector. This is useful in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.

Returns:byte[]

null since no initialization vector is used.

getOutputSizeback to summary
public final int getOutputSize(int inLen)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getOutputSize.

Return the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inLen (in bytes). This call takes into account any unprocessed (buffered) data from a previous update call, and padding. The actual output length of the next update() or doFinal() call may be smaller than the length returned by this method.

If the input length plus the length of the buffered data exceeds the maximum length, 0 is returned.

Parameters
inLen:int

the length of the input

Returns:int

the length of the ciphertext or 0 if the input is too long.

getParametersback to summary
public final AlgorithmParameterSpec getParameters()

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.getParameters.

Returns the parameters used with this cipher.

The returned parameters may be the same that were used to initialize this cipher, or may contain the default set of parameters or a set of randomly generated parameters used by the underlying cipher implementation (provided that the underlying cipher implementation uses a default set of parameters or creates new parameters if it needs parameters but was not initialized with any).

Returns:AlgorithmParameterSpec

the parameters used with this cipher, or null if this cipher does not use any parameters.

initCipherDecryptback to summary
protected abstract void initCipherDecrypt(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException

Initialize the AsymmetricBlockCipher with a certain key for data encryption.

Parameters
key:Key

the key which has to be used to decrypt data

params:AlgorithmParameterSpec

the algorithm parameters

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given parameters are inappropriate for initializing this cipher.
initCipherEncryptback to summary
protected abstract void initCipherEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom sr) throws InvalidKeyException, InvalidAlgorithmParameterException

Initialize the AsymmetricBlockCipher with a certain key for data encryption.

Parameters
key:Key

the key which has to be used to encrypt data

params:AlgorithmParameterSpec

the algorithm parameters

sr:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher.
InvalidAlgorithmParameterException:
if the given parameters are inappropriate for initializing this cipher.
initDecryptback to summary
public final void initDecrypt(Key key) throws InvalidKeyException

Initialize the cipher for decryption by forwarding it to initDecrypt(Key, AlgorithmParameterSpec).

If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption, and raise an InvalidKeyException if it is being initialized for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

Parameters
key:Key

the encryption or decryption key.

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher.
initDecryptback to summary
public final void initDecrypt(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.initDecrypt.

This method initializes the AsymmetricBlockCipher with a certain key for data decryption.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it

Parameters
key:Key

the key which has to be used to decrypt data.

params:AlgorithmParameterSpec

the algorithm parameters.

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher, or if this cipher is being initialized for decryption and requires algorithm parameters and params is null.
initEncryptback to summary
public final void initEncrypt(Key key) throws InvalidKeyException

Initializes the cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom).

If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption, and raise an InvalidKeyException if it is being initialized for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

Parameters
key:Key

the encryption or decryption key.

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher.
initEncryptback to summary
public final void initEncrypt(Key key, SecureRandom random) throws InvalidKeyException

Initialize this cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom, AlgorithmParameterSpec).

If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption, and raise an InvalidKeyException if it is being initialized for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

Parameters
key:Key

the encryption or decryption key.

random:SecureRandom

the source of randomness.

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher.
initEncryptback to summary
public final void initEncrypt(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException

Initializes the cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom, AlgorithmParameterSpec).

Parameters
key:Key

the encryption or decryption key.

params:AlgorithmParameterSpec

the algorithm parameters.

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher.
InvalidAlgorithmParameterException:
if the given algortihm parameters are inappropriate for this cipher, or if this cipher is being initialized for decryption and requires algorithm parameters and params is null.
initEncryptback to summary
public final void initEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.initEncrypt.

This method initializes the AsymmetricBlockCipher with a certain key for data encryption.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it

Parameters
key:Key

the key which has to be used to encrypt data.

params:AlgorithmParameterSpec

the algorithm parameters.

secureRandom:SecureRandom

the source of randomness.

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher, or if this cipher is being initialized for decryption and requires algorithm parameters and params is null.
messageDecryptback to summary
protected abstract byte[] messageDecrypt(byte[] input) throws IllegalBlockSizeException, BadPaddingException

Decrypt the ciphertext stored in input. The method should also perform an additional length check.

Parameters
input:byte[]

the ciphertext to be decrypted (the ciphertext length is less than or equal to maxCipherTextSize)

Returns:byte[]

the decrypted message

Exceptions
IllegalBlockSizeException:
if the input is inappropriate for this cipher.
BadPaddingException:
if the input format is invalid.
messageEncryptback to summary
protected abstract byte[] messageEncrypt(byte[] input) throws IllegalBlockSizeException, BadPaddingException

Encrypt the message stored in input. The method should also perform an additional length check.

Parameters
input:byte[]

the message to be encrypted (usually the message length is less than or equal to maxPlainTextSize)

Returns:byte[]

the encrypted message (it has length equal to maxCipherTextSize_)

Exceptions
IllegalBlockSizeException:
if the input is inappropriate for this cipher.
BadPaddingException:
if the input format is invalid.
setModeback to summary
protected final void setMode(String modeName)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.setMode.

Since asymmetric block ciphers do not support modes, this method does nothing.

Parameters
modeName:String

the cipher mode (unused)

setPaddingback to summary
protected final void setPadding(String paddingName)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.setPadding.

Since asymmetric block ciphers do not support padding, this method does nothing.

Parameters
paddingName:String

the name of the padding scheme (not used)

updateback to summary
public final byte[] update(byte[] input, int inOff, int inLen)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.update.

Continue a multiple-part encryption or decryption operation. This method just writes the input into an internal buffer.

Parameters
input:byte[]

byte array containing the next part of the input

inOff:int

index in the array where the input starts

inLen:int

length of the input

Returns:byte[]

a new buffer with the result (always empty)

updateback to summary
public final int update(byte[] input, int inOff, int inLen, byte[] output, int outOff)

Implements abstract org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt.update.

Continue a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.

Parameters
input:byte[]

the input buffer

inOff:int

the offset where the input starts

inLen:int

the input length

output:byte[]

the output buffer

outOff:int

the offset where the result is stored

Returns:int

the length of the output (always 0)