public final class HelixCipher extends CipherSpi
Constructor and Description |
---|
HelixCipher()
Creates a new HelixCipher and performs the provider
self-integrity check.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
engineDoFinal(byte[] input,
int inputOffset,
int inputLen)
Encrypts or decrypts data in a single-part operation, or finishes a
multiple-part operation.
|
protected int |
engineDoFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
Encrypts or decrypts data in a single-part operation, or finishes a
multiple-part operation.
|
protected int |
engineGetBlockSize()
Returns the block size (in bytes).
|
protected byte[] |
engineGetIV()
Returns the initialization vector (IV) in a new buffer.
|
protected int |
engineGetKeySize(Key key)
Returns the key size of the given key object in bits.
|
protected int |
engineGetOutputSize(int inputLen)
Returns 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 inputLen (in bytes).
|
protected AlgorithmParameters |
engineGetParameters()
Returns the parameters used with this cipher.
|
protected void |
engineInit(int opmode,
Key key,
AlgorithmParameterSpec params,
SecureRandom random)
Initializes this cipher with a key, a set of algorithm parameters, and a
source of randomness.
|
protected void |
engineInit(int opmode,
Key key,
AlgorithmParameters params,
SecureRandom random)
Initializes this cipher with a key, a set of algorithm parameters, and a
source of randomness.
|
protected void |
engineInit(int opmode,
Key key,
SecureRandom random)
Initializes this cipher with a key and a source of randomness.
|
protected void |
engineSetMode(String mode)
Sets the mode of this cipher.
|
protected void |
engineSetPadding(String padding)
Sets the padding mechanism of this cipher.
|
protected Key |
engineUnwrap(byte[] wrappedKey,
String wrappedKeyAlgorithm,
int wrappedKeyType)
Unwraps a previously wrapped key.
|
protected byte[] |
engineUpdate(byte[] input,
int inputOffset,
int inputLen)
Continues a multiple-part encryption or decryption operation (depending
on how this cipher was initialized), processing another data part.
|
protected int |
engineUpdate(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
Continues a multiple-part encryption or decryption operation (depending
on how this cipher was initialized), processing another data part.
|
protected byte[] |
engineWrap(Key key)
Wraps a key.
|
engineDoFinal, engineUpdate, engineUpdateAAD, engineUpdateAAD
public HelixCipher()
protected int engineGetBlockSize()
engineGetBlockSize
in class CipherSpi
CipherSpi.engineGetBlockSize()
protected int engineGetKeySize(Key key) throws InvalidKeyException
engineGetKeySize
in class CipherSpi
key
- a Helix SecretKey
InvalidKeyException
- if key is null or not a Helix
SecretKey
CipherSpi.engineGetKeySize(java.security.Key)
protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException
Initializing the cipher in this manner causes the Helix nonce to be randomly generated; therefore, this method can only be used to initialize the cipher for encryption or key wrapping.
The randomly-generated nonce can be retrieved directly via
Cipher.getIV()
or indirectly via Cipher.getParameters()
.
engineInit
in class CipherSpi
opmode
- the operation mode of this cipher (restricted to
Cipher.ENCRYPT_MODE
or Cipher.WRAP_MODE
)key
- the secret key to be used for encryption or key wrapping (must
be a Helix SecretKey
)random
- the RNGIllegalArgumentException
- if the operation mode is Cipher.DECRYPT_MODE
or
Cipher.UNWRAP_MODE
InvalidKeyException
- if key is null or is not a Helix
SecretKey
CipherSpi.engineInit(int, java.security.Key,
java.security.SecureRandom)
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
When opmode is Cipher.DECRYPT_MODE
or
Cipher.UNWRAP_MODE
, a MAC specified in params must
be exactly 16 bytes in length, in which case Cipher.doFinal()
will fail unless the generated MAC matches the MAC specified in
params. Otherwise, the MAC can be left null, causing MAC
verification to be skipped.
When opmode is Cipher.ENCRYPT_MODE
or
Cipher.WRAP_MODE
, a MAC must not be specified in
params. After Cipher.doFinal()
completes successfully, the
generated MAC can be retrieved indirectly via
Cipher.getParameters()
(prior to this cipher being
re-initialized).
engineInit
in class CipherSpi
opmode
- the operation mode of this cipherkey
- a Helix SecretKey
params
- a HelixParameterSpec
random
- the RNG (not used)InvalidKeyException
- if key is null or is not a Helix
SecretKey
; or if the algorithm parameters cannot be
initialized from the parameter specInvalidAlgorithmParameterException
- if params is null or is not a
HelixParameterSpec
; or if a non-null MAC in
params is not exactly 16 bytes in length; or if a non-
null MAC is specified in params when
opmode is Cipher.ENCRYPT_MODE
or
Cipher.WRAP_MODE
CipherSpi.engineInit(int, java.security.Key,
java.security.spec.AlgorithmParameterSpec,
java.security.SecureRandom)
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
When opmode is Cipher.DECRYPT_MODE
or
Cipher.UNWRAP_MODE
, a MAC specified in params must
be exactly 16 bytes in length, in which case Cipher.doFinal()
will fail unless the generated MAC matches the MAC specified in
params. Otherwise, the MAC can be left null, causing MAC
verification to be skipped.
When opmode is Cipher.ENCRYPT_MODE
or
Cipher.WRAP_MODE
, a MAC must not be specified in
params. After Cipher.doFinal()
completes successfully, the
generated MAC can be retrieved indirectly via
Cipher.getParameters()
(prior to this cipher being
re-initialized).
engineInit
in class CipherSpi
opmode
- the operation mode of this cipherkey
- a Helix SecretKey
params
- Helix algorithm parameters provided by NinthTestrandom
- the RNG (not used)InvalidKeyException
- if key is null or is not a Helix
SecretKey
InvalidAlgorithmParameterException
- if params is null or is not a Helix
AlgorithmParameters
provided by NinthTest; or if a
HelixParameterSpec
cannot be derived from
params; or if a non-null MAC in params
is not exactly 16 bytes in length; or if a non-null
MAC is specified in params when opmode is
either Cipher.ENCRYPT_MODE
or
Cipher.WRAP_MODE
CipherSpi.engineInit(int, java.security.Key,
java.security.AlgorithmParameters, java.security.SecureRandom)
protected void engineSetMode(String mode) throws NoSuchAlgorithmException
This method always throws UnsupportedOperationException
.
engineSetMode
in class CipherSpi
mode
- the cipher modeNoSuchAlgorithmException
- if the requested cipher mode does not existUnsupportedOperationException
- if this method is invokedCipherSpi.engineSetMode(java.lang.String)
protected void engineSetPadding(String padding) throws NoSuchPaddingException
This method always throws UnsupportedOperationException
.
engineSetPadding
in class CipherSpi
padding
- the cipher padding methodNoSuchPaddingException
- if the requested padding mechanism does not existUnsupportedOperationException
- if this method is invokedCipherSpi.engineSetPadding(java.lang.String)
protected AlgorithmParameters engineGetParameters()
This method provides one way of obtaining the randomly-generated nonce
after initialization (the other being the Cipher.getIV()
method).
The nonce is randomly generated if the cipher is initialized using
Cipher.init(int, Key)
or
Cipher.init(int, Key, SecureRandom)
.
This method also allows for the retrieval of the generated MAC following a successful encryption or key-wrapping operation.
engineGetParameters
in class CipherSpi
CipherSpi.engineGetParameters()
protected byte[] engineGetIV()
This method provides one way of obtaining the randomly-generated nonce
after initialization (the other being the Cipher.getParameters()
method).
The nonce is randomly generated if the cipher is initialized using
Cipher.init(int, Key)
or
Cipher.init(int, Key, SecureRandom)
.
engineGetIV
in class CipherSpi
CipherSpi.engineGetIV()
protected int engineGetOutputSize(int inputLen)
Up to three input bytes may be buffered when Cipher.update(byte[])
is called, because input is processed by the underlying Helix primitive
one word (i.e. one 32-bit integer) at a time.
engineGetOutputSize
in class CipherSpi
inputLen
- the number of input bytes that will be passed to the
next Cipher.update(byte[])
or Cipher.doFinal()
operationCipher.update(byte[])
or
Cipher.doFinal()
operation (given input of length
inputLen)CipherSpi.engineGetOutputSize(int)
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)
If the input (combined with any previously-buffered input) is not long enough to yield at least four bytes of output, input will be buffered and this method will return null.
If this method returns non-null, the returned byte array will always have a length that is a multiple of four.
engineUpdate
in class CipherSpi
input
- the input bufferinputOffset
- the index into input where the input bytes begininputLen
- the number of bytes to be used from input (beginning at
inputOffset)CipherSpi.engineUpdate(byte[], int, int)
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException
If the input (combined with any previously-buffered input) is not long enough to yield at least four bytes of output, input will be buffered, output will not be modified, and this method will return 0 (zero).
The integer returned by this method will always be a multiple of four (or zero, as described above).
engineUpdate
in class CipherSpi
input
- the input bufferinputOffset
- the index into input where the input bytes begininputLen
- the number of bytes to be used from input (beginning at
inputOffset)output
- the buffer for the resultoutputOffset
- the index into output where the output bytes are storedShortBufferException
- if output (beginning at outputOffset) is not
large enough to store the number of bytes produced by this
callCipherSpi.engineUpdate(byte[], int, int, byte[], int)
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException
If the current operation mode is Cipher.ENCRYPT_MODE
, the
Helix-generated MAC will be stored in the algorithm parameters. The MAC
can be retrieved indirectly via Cipher.getParameters()
prior to this cipher being re-initialized.
If the current operation mode is Cipher.DECRYPT_MODE
, and the
expected MAC was specified when this cipher was initialized, the expected
MAC will be compared to the MAC that was generated for this operation. If
the expected and generated MACs are not equal, this method will throw
MessageAuthenticationException
.
engineDoFinal
in class CipherSpi
input
- the input bufferinputOffset
- the index into input where the input bytes begininputLen
- the number of bytes to be used from input (beginning at
inputOffset)IllegalBlockSizeException
- never (Helix is a stream cipher)BadPaddingException
- never (Helix padding is masked off)MessageAuthenticationException
- for a decryption operation only, if the non-null
expected MAC does not match the generated MACCipherSpi.engineDoFinal(byte[], int, int)
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException
If the current operation mode is Cipher.ENCRYPT_MODE
, the
generated MAC will be stored in the algorithm parameters, and can be
retrieved indirectly via Cipher.getParameters()
prior to
re-initializing this cipher.
If the current operation mode is Cipher.DECRYPT_MODE
, and the
expected MAC was specified when this cipher was initialized, the expected
MAC will be compared to the MAC that was generated for this operation. If
the expected and generated MACs are not equal, this method will throw
MessageAuthenticationException
.
engineDoFinal
in class CipherSpi
input
- the input bufferinputOffset
- the index into input where the input bytes begininputLen
- the number of bytes to be used from input (beginning at
inputOffset)output
- the buffer for the resultoutputOffset
- the index into output where the output bytes are storedShortBufferException
- if output (beginning at outputOffset) is not
large enough to store the number of bytes produced by this
callIllegalBlockSizeException
- never (Helix is a stream cipher)BadPaddingException
- never (Helix padding is masked off)MessageAuthenticationException
- for a decryption operation only, if the non-null
expected MAC does not match the generated MACCipherSpi.engineDoFinal(byte[], int, int, byte[], int)
protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException
engineWrap
in class CipherSpi
key
- the key to be wrappedIllegalBlockSizeException
- never (Helix is a stream cipher)InvalidKeyException
- if key is nullCipherSpi.engineWrap(java.security.Key)
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException
If the expected MAC was specified when this cipher was initialized, the
expected MAC will be compared to the MAC that was generated for this
operation. If the expected and generated MACs are not equal, this method
will throw MessageAuthenticationException
.
engineUnwrap
in class CipherSpi
wrappedKey
- the key to be unwrappedwrappedKeyAlgorithm
- the algorithm associated with the wrapped keywrappedKeyType
- the type of the wrapped key ( Cipher.SECRET_KEY
,
Cipher.PRIVATE_KEY
, or Cipher.PUBLIC_KEY
)InvalidKeyException
- if wrappedKey does not represent a key of type
wrappedKeyType for the wrappedKeyAlgorithmNoSuchAlgorithmException
- if no installed providers can create keys of type
wrappedKeyType for the wrappedKeyAlgorithmMessageAuthenticationException
- if the non-null expected MAC does not match the
generated MACCipherSpi.engineUnwrap(byte[], java.lang.String, int)
Copyright © 2010-2015 Matthew Zipay. All Rights Reserved.