com.ibm.crypto.fips.provider
Class JITFullHardwareCrypt
- java.lang.Object
-
- com.ibm.crypto.fips.provider.JITFullHardwareCrypt
-
public final class JITFullHardwareCrypt extends java.lang.ObjectThe class provides a fast implementation backed by hardware, optimized by JIT, of several encryption algorithms.. START |<--------------------------------------------------+ |---------------V----------------| | | AlgorithmSupportedByHardware() | (false) New Algorithm | or isSupportedByHardware() | ------> softwareOnly New MODE |---------------|----------------| New Key Length | (true) | |-----V-----| (null) | | getCrypto | -----> softwareOnly | |-----|-----| | |<---------------------------------------------+ | |--------------------V-----------------------| | | | init() (three versions, depending on mode) | New Init. Vector | |--------------------|-----------------------| New Key | |<--------------------------+ New isEncipher | |--------------------V-----------------------| | | | | cipher() (two versions, depending on mode) | More data (slower!) | | |--------------------|-----------------------| | | | +---------------------------+ | | +----------------------------------------------+ | +---------------------------------------------------+ | V DONE
-
-
Method Summary
Methods Modifier and Type Method and Description voidcipher(byte[] in, int inputLength, int inputOffset, byte[] out, int outputOffset)Will encipher the data in in[] and output to out[] using the {algorithm, mode, key} previously selected by calls to getCrypto() and init().voidcipher(byte[] in, int inputLength, int inputOffset, byte[] out, int outputOffset, byte[] ctr, int ctrOffset)Will encipher the data in in[] and output to out[] using the {algorithm, mode, key} previously selected by calls to getCrypto() and init().intgetBlockSize()Once instance of the Crypto object was obtained (via getCrypto), this returns the block-size length (in bytes) the selected algorithm will use.byte[]getIV()Provides direct access to the chaining value used by the algorithm.intgetIVSize()Once instance of the Crypto object was obtained (via getCrypto), this returns the Initialization Vector length (in bytes) the selected algorithm will need.voidinit(boolean isEncrypt, byte[] key)To be called before cipher() can be used.voidinit(boolean isEncrypt, byte[] key, byte[] IV)To be called before cipher() can be used.voidinit(boolean isEncrypt, byte[] key, byte[] IV, int size)To be called before cipher() can be used.static booleanisSupportedByHardware(java.lang.String algorithm, java.lang.String mode)Returns false if hardware does not support encryption for the particular algorithm.
-
-
-
Method Detail
-
cipher
public void cipher(byte[] in, int inputLength, int inputOffset, byte[] out, int outputOffset)Will encipher the data in in[] and output to out[] using the {algorithm, mode, key} previously selected by calls to getCrypto() and init(). Assumes correct init() function has already been called (Modes: ECB, CBC, OFB, CFB) Will not do any padding; assumes enough blocks has been provided in in[] and out[]. For best performance, provide as much data as is available (that is single cipher() invocation is much faster then several repeated ones).- Parameters:
in- input byte arrayinputLength- number of bytes to process, MUST be multiple of blockSizeinputOffset- starting point in in[]out- output byte array, with enough memory allocated to process inputLength bytesoutputOffset- starting point in out[]
-
cipher
public void cipher(byte[] in, int inputLength, int inputOffset, byte[] out, int outputOffset, byte[] ctr, int ctrOffset)Will encipher the data in in[] and output to out[] using the {algorithm, mode, key} previously selected by calls to getCrypto() and init(). Assumes correct init() function has already been called (Modes: CTR) Will not do any padding; assumes enough blocks has been provided in in[] and out[]. For best performance, provide as much data as is available (that is single cipher() invocation is much faster then several repeated ones).- Parameters:
in- input byte arrayinputLength- number of bytes to process, MUST be multiple of blockSizeinputOffset- starting point in in[]out- output byte array, with enough memory allocatedoutputOffset- starting point in out[]ctr-ctrOffset-
-
init
public void init(boolean isEncrypt, byte[] key)To be called before cipher() can be used. This function is to be used for mode "ECB", "CTR" for hardwareOuter. This function is to be used for all modes for hardwarePartial.- Parameters:
isEncrypt- true for encryption, false for decryptionkey- Secret key to be used, usually either 128bit, 192bit or 256bit (16,24,32 bytes respectively)
-
init
public void init(boolean isEncrypt, byte[] key, byte[] IV)To be called before cipher() can be used. This init is to be used for mode "CBC", "OFB".- Parameters:
isEncrypt- true for encryption, false for decryptionkey- Secret key to be used, usually either 128bit, 192bit or 256bit (16,24,32 bytes respectively)IV- Initialization vector (sometimes also called chaining value) to be used (to start ciphering).
-
init
public void init(boolean isEncrypt, byte[] key, byte[] IV, int size)To be called before cipher() can be used. This init is to be used for mode "CFB".- Parameters:
isEncrypt- true for encryption, false for decryptionkey- Secret key to be used, usually either 128bit, 192bit or 256bit (16,24,32 bytes respectively)IV- Initialization vector (sometimes also called chaining value) to be used (to start ciphering).size- Length of cipher feedback (LCFB) in bytes
-
isSupportedByHardware
public static boolean isSupportedByHardware(java.lang.String algorithm, java.lang.String mode)Returns false if hardware does not support encryption for the particular algorithm. This is a hint if getCrypto() will fail. Even if true is returned, it still could fail if keyLength is not supported by hardware).- Parameters:
algorithm- Name of algorithm (i.e. AES)mode- Name of mode (i.e. CBC)- Returns:
- false if hardware is known not to support this algorithm.
-
getBlockSize
public int getBlockSize()
Once instance of the Crypto object was obtained (via getCrypto), this returns the block-size length (in bytes) the selected algorithm will use. cipher() will process multiple block-size chunks of data at a time, do not break data into block-size pieces.- Returns:
- block size in bytes
-
getIV
public byte[] getIV()
Provides direct access to the chaining value used by the algorithm. THIS IS A COPY of the memory, so changing its value will not affect subsequent invocations of the cipher()!- Returns:
- Intermediate initialization vector (or chaining value).
-
getIVSize
public int getIVSize()
Once instance of the Crypto object was obtained (via getCrypto), this returns the Initialization Vector length (in bytes) the selected algorithm will need.- Returns:
- the length of initialization vector that the appropriate init() function expects.
-
-