com.ibm.crypto.fips.provider
Class HmacSHA256
- java.lang.Object
-
- javax.crypto.MacSpi
-
- com.ibm.crypto.fips.provider.HmacSHA256
-
- All Implemented Interfaces:
- java.lang.Cloneable
public final class HmacSHA256 extends javax.crypto.MacSpi implements java.lang.CloneableThis is an implementation of the HMAC-SHA256 algorithm.
-
-
Constructor Summary
Constructors Constructor and Description HmacSHA256()Standard constructor, creates a new HmacSHA256 instance.
-
Method Summary
Methods Modifier and Type Method and Description java.lang.Objectclone()protected byte[]engineDoFinal()Completes the HMAC computation and resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.protected intengineGetMacLength()Returns the length of the HMAC in bytes.protected voidengineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)Initializes the HMAC with the given secret key and algorithm parameters.protected voidengineReset()Resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.protected voidengineUpdate(byte input)Processes the given byte.protected voidengineUpdate(byte[] input, int offset, int len)Processes the firstlenbytes ininput, starting atoffset.protected voidfinalize()This function zeroizes the key so that it isn't in memory when GC is done.java.lang.ObjectinternalClone()protected byte[]internalDoFinal()Completes the HMAC computation and resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.protected intinternalGetMacLength()Returns the length of the HMAC in bytes.protected voidinternalInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)Initializes the HMAC with the given secret key and algorithm parameters.protected voidinternalReset()Resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.protected voidinternalUpdate(byte input)Processes the given byte.protected voidinternalUpdate(byte[] input, int offset, int len)Processes the firstlenbytes ininput, starting atoffset.voidzeroize()This function zeroizes the key so that it isn't in memory
-
-
-
Constructor Detail
-
HmacSHA256
public HmacSHA256() throws java.security.NoSuchAlgorithmExceptionStandard constructor, creates a new HmacSHA256 instance. Verify the JCE framework in the constructor.- Throws:
java.lang.SecurityException- if fails to verify the JCE framework.java.security.NoSuchAlgorithmException
-
-
Method Detail
-
engineGetMacLength
protected int engineGetMacLength()
Returns the length of the HMAC in bytes.- Specified by:
engineGetMacLengthin classjavax.crypto.MacSpi- Returns:
- the HMAC length in bytes.
- Throws:
FIPSRuntimeException- if SelfTest.isFipsRunnable returns false.
-
internalGetMacLength
protected int internalGetMacLength()
Returns the length of the HMAC in bytes.- Returns:
- the HMAC length in bytes.
-
engineInit
protected void engineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInitializes the HMAC with the given secret key and algorithm parameters.- Specified by:
engineInitin classjavax.crypto.MacSpi- Parameters:
key- the secret key.params- the algorithm parameters.- Throws:
java.security.InvalidKeyException- if the given key is inappropriate for initializing this MAC.java.security.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this MAC.FIPSRuntimeException- if SelfTest.isFipsRunnable returns false.
-
internalInit
protected void internalInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInitializes the HMAC with the given secret key and algorithm parameters.- Parameters:
key- the secret key.params- the algorithm parameters.- Throws:
java.security.InvalidKeyException- if the given key is inappropriate for initializing this MAC.java.security.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this MAC.
-
engineUpdate
protected void engineUpdate(byte input)
Processes the given byte.- Specified by:
engineUpdatein classjavax.crypto.MacSpi- Parameters:
input- the input byte to be processed.- Throws:
FIPSRuntimeException- if SelfTest.isFipsRunnable returns false.
-
internalUpdate
protected void internalUpdate(byte input)
Processes the given byte.- Parameters:
input- the input byte to be processed.
-
engineUpdate
protected void engineUpdate(byte[] input, int offset, int len)Processes the firstlenbytes ininput, starting atoffset.- Specified by:
engineUpdatein classjavax.crypto.MacSpi- Parameters:
input- the input buffer.offset- the offset ininputwhere the input starts.len- the number of bytes to process.- Throws:
FIPSRuntimeException- if SelfTest.isFipsRunnable returns false.
-
internalUpdate
protected void internalUpdate(byte[] input, int offset, int len)Processes the firstlenbytes ininput, starting atoffset.- Parameters:
input- the input buffer.offset- the offset ininputwhere the input starts.len- the number of bytes to process.
-
engineDoFinal
protected byte[] engineDoFinal()
Completes the HMAC computation and resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.- Specified by:
engineDoFinalin classjavax.crypto.MacSpi- Returns:
- the HMAC result.
- Throws:
FIPSRuntimeException- if SelfTest.isFipsRunnable returns false.
-
internalDoFinal
protected byte[] internalDoFinal()
Completes the HMAC computation and resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.- Returns:
- the HMAC result.
-
engineReset
protected void engineReset()
Resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.- Specified by:
engineResetin classjavax.crypto.MacSpi- Throws:
FIPSRuntimeException- if SelfTest.isFipsRunnable returns false.
-
internalReset
protected void internalReset()
Resets the HMAC for further use, maintaining the secret key that the HMAC was initialized with.
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjavax.crypto.MacSpi
-
internalClone
public java.lang.Object internalClone()
-
zeroize
public void zeroize()
This function zeroizes the key so that it isn't in memory
-
finalize
protected void finalize()
This function zeroizes the key so that it isn't in memory when GC is done.- Overrides:
finalizein classjava.lang.Object
-
-