Top Description Fields Constructors Methods
sun.security.pkcs11

pack-priv final Class P11Mac

extends MacSpi
Class Inheritance
Imports
java.nio.ByteBuffer, java.security.*, java.security.spec.AlgorithmParameterSpec, .InvalidKeySpecException, javax.crypto.MacSpi, javax.crypto.spec.PBEKeySpec, .PBEParameterSpec, jdk.internal.access.JavaNioAccess, .SharedSecrets, sun.nio.ch.DirectBuffer, sun.security.pkcs11.wrapper.*, sun.security.util.PBEUtil

MAC implementation class. This class currently supports HMAC using MD5, SHA-1, SHA-2 family (SHA-224, SHA-256, SHA-384, and SHA-512), SHA-3 family (SHA3-224, SHA3-256, SHA3-384, and SHA3-512), and the SSL3 MAC using MD5 and SHA-1. Note that unlike other classes (e.g. Signature), this does not composite various operations if the token only supports part of the required functionality. The MAC implementations in SunJCE already do exactly that by implementing an MAC on top of MessageDigests. We could not do any better than they.
Author
Andreas Sterbenz
Since
1.5

Field Summary

Modifier and TypeField and Description
private final String
private final CK_MECHANISM
private boolean
private final int
private static final JavaNioAccess
private byte[]
private P11Key
private Session
private final P11SecretKeyFactory.PBEKeyInfo
private final Token

Constructor Summary

AccessConstructor and Description
pack-priv
P11Mac(Token token, String algorithm, long mechanism)

Method Summary

Modifier and TypeMethod and Description
private void
protected byte[]
engineDoFinal()

Implements abstract javax.crypto.MacSpi.engineDoFinal.

Completes the MAC computation and resets the MAC for further use, maintaining the secret key that the MAC was initialized with.

protected int
engineGetMacLength()

Implements abstract javax.crypto.MacSpi.engineGetMacLength.

Returns the length of the MAC in bytes.

protected void
engineInit(Key
the (secret) key.
key
,
AlgorithmParameterSpec
the algorithm parameters.
params
)

Implements abstract javax.crypto.MacSpi.engineInit.

Initializes the MAC with the given (secret) key and algorithm parameters.

protected void
engineReset()

Implements abstract javax.crypto.MacSpi.engineReset.

Resets the MAC for further use, maintaining the secret key that the MAC was initialized with.

protected void
engineUpdate(byte
the input byte to be processed.
input
)

Implements abstract javax.crypto.MacSpi.engineUpdate.

Processes the given byte.

protected void
engineUpdate(byte[]
the input buffer.
b
,
int
the offset in input where the input starts.
ofs
,
int
the number of bytes to process.
len
)

Implements abstract javax.crypto.MacSpi.engineUpdate.

Processes the first len bytes in input, starting at offset inclusive.

protected void
engineUpdate(ByteBuffer
the ByteBuffer
byteBuffer
)

Overrides javax.crypto.MacSpi.engineUpdate.

Processes input.remaining() bytes in the ByteBuffer input, starting at input.position().

private void
private void
private void
reset(boolean doCancel)

Inherited from javax.crypto.MacSpi:
clone

Field Detail

algorithmback to summary
private final String algorithm
ckMechanismback to summary
private final CK_MECHANISM ckMechanism
initializedback to summary
private boolean initialized
macLengthback to summary
private final int macLength
NIO_ACCESSback to summary
private static final JavaNioAccess NIO_ACCESS
oneByteback to summary
private byte[] oneByte
p11Keyback to summary
private P11Key p11Key
sessionback to summary
private Session session
svcPbeKiback to summary
private final P11SecretKeyFactory.PBEKeyInfo svcPbeKi
tokenback to summary
private final Token token

Constructor Detail

P11Macback to summary
pack-priv P11Mac(Token token, String algorithm, long mechanism) throws PKCS11Exception

Method Detail

cancelOperationback to summary
private void cancelOperation()
engineDoFinalback to summary
protected byte[] engineDoFinal()

Implements abstract javax.crypto.MacSpi.engineDoFinal.

Doc from javax.crypto.MacSpi.engineDoFinal.

Completes the MAC computation and resets the MAC for further use, maintaining the secret key that the MAC was initialized with.

Returns:byte[]

the MAC result.

engineGetMacLengthback to summary
protected int engineGetMacLength()

Implements abstract javax.crypto.MacSpi.engineGetMacLength.

Doc from javax.crypto.MacSpi.engineGetMacLength.

Returns the length of the MAC in bytes.

Returns:int

the MAC length in bytes.

engineInitback to summary
protected void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.MacSpi.engineInit.

Doc from javax.crypto.MacSpi.engineInit.

Initializes the MAC with the given (secret) key and algorithm parameters.

Parameters
key:Key

the (secret) key.

params:AlgorithmParameterSpec

the algorithm parameters.

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this MAC.
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this MAC.
engineResetback to summary
protected void engineReset()

Implements abstract javax.crypto.MacSpi.engineReset.

Doc from javax.crypto.MacSpi.engineReset.

Resets the MAC for further use, maintaining the secret key that the MAC was initialized with.

engineUpdateback to summary
protected void engineUpdate(byte input)

Implements abstract javax.crypto.MacSpi.engineUpdate.

Doc from javax.crypto.MacSpi.engineUpdate.

Processes the given byte.

Parameters
input:byte

the input byte to be processed.

engineUpdateback to summary
protected void engineUpdate(byte[] b, int ofs, int len)

Implements abstract javax.crypto.MacSpi.engineUpdate.

Doc from javax.crypto.MacSpi.engineUpdate.

Processes the first len bytes in input, starting at offset inclusive.

Parameters
b:byte[]

the input buffer.

ofs:int

the offset in input where the input starts.

len:int

the number of bytes to process.

engineUpdateback to summary
protected void engineUpdate(ByteBuffer byteBuffer)

Overrides javax.crypto.MacSpi.engineUpdate.

Doc from javax.crypto.MacSpi.engineUpdate.

Processes input.remaining() bytes in the ByteBuffer input, starting at input.position(). Upon return, the buffer's position will be equal to its limit; its limit will not have changed.

Subclasses should consider overriding this method if they can process ByteBuffers more efficiently than byte arrays.

Parameters
byteBuffer:ByteBuffer

the ByteBuffer

ensureInitializedback to summary
private void ensureInitialized() throws PKCS11Exception
initializeback to summary
private void initialize() throws PKCS11Exception
resetback to summary
private void reset(boolean doCancel)