Class OpenSSLMessageDigestNative
java.lang.Object
java.security.MessageDigestSpi
de.sfuhrm.openssl4j.OpenSSLMessageDigestNative
- Direct Known Subclasses:
MessageDigest.BLAKE2b512, MessageDigest.BLAKE2s256, MessageDigest.MD4, MessageDigest.MD5, MessageDigest.RIPEMD160, MessageDigest.SHA_224, MessageDigest.SHA_256, MessageDigest.SHA_384, MessageDigest.SHA_512, MessageDigest.SHA_512_224, MessageDigest.SHA_512_256, MessageDigest.SHA1, MessageDigest.SHA3_224, MessageDigest.SHA3_256, MessageDigest.SHA3_384, MessageDigest.SHA3_512, MessageDigest.SM3, MessageDigest.Whirlpool
An interface to OpenSSL message digest functions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe OpenSSL algorithm name as returned by listMessageDigests().private final ByteBufferA native message digest context where the state of the current calculation is stored.private final intThe digest length as calculated by the engine. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static intdigestLength(ByteBuffer context) Return the digest length in bytes.protected final byte[]protected final intprotected final voidprotected final voidengineUpdate(byte inputByte) protected final voidengineUpdate(byte[] input, int offset, int len) protected final voidengineUpdate(ByteBuffer input) protected static voidfree(ByteBuffer context) Free the native context that came from nativeContext().Get the list of digest algorithms supported by the OpenSSL library.private static String[]Get the list of MessageDigest algorithms supported by OpenSSL.private final ByteBufferReturns the context size in bytes.private final voidnativeFinal(ByteBuffer context, byte[] digest) Do the final digest calculation and return it.private final voidnativeInit(ByteBuffer context, String algorithmName) Initialize the context.private final voidnativeUpdateWithByte(ByteBuffer context, byte byteData) Update the context with a single byte.private final voidnativeUpdateWithByteArray(ByteBuffer context, byte[] byteArray, int offset, int length) Update the context with an array.private final voidnativeUpdateWithByteBuffer(ByteBuffer context, ByteBuffer data, int offset, int length) Update the context with a direct byte buffer.private static voidremoveContext(ByteBuffer context) Removes a context allocated with nativeContext().Methods inherited from class MessageDigestSpi
clone, engineDigest
-
Field Details
-
context
A native message digest context where the state of the current calculation is stored. Allocated with nativeContext(), freed by the PhantomReferenceCleanup with free(ByteBuffer). -
algorithmName
The OpenSSL algorithm name as returned by listMessageDigests(). -
digestLength
private final int digestLengthThe digest length as calculated by the engine.
-
-
Constructor Details
-
OpenSSLMessageDigestNative
OpenSSLMessageDigestNative(String openSslName)
-
-
Method Details
-
digestLength
Return the digest length in bytes.- Returns:
- the digest length in bytes.
-
removeContext
Removes a context allocated with nativeContext().- Parameters:
context- the context to free.
-
listMessageDigests
Get the list of MessageDigest algorithms supported by OpenSSL.- Returns:
- an array of supported message digest algorithms from the OpenSSL library.
-
nativeContext
Returns the context size in bytes. This is used to allocate thedirect ByteBuffer.- Returns:
- a ByteBuffer containing the native message digest context.
-
nativeInit
Initialize the context.- Parameters:
context- the context as allocated incontext.algorithmName- the OpenSSL algorithm name as returned by listMessageDigests().
-
nativeUpdateWithByte
Update the context with a single byte.- Parameters:
context- the context as allocated incontext.byteData- the byte to update the context with.
-
nativeUpdateWithByteArray
private final void nativeUpdateWithByteArray(ByteBuffer context, byte[] byteArray, int offset, int length) Update the context with an array.- Parameters:
context- the context as allocated incontext.byteArray- the array to update the context with.offset- the start offset of the array data to update the context with.length- the number of bytes to update the context with.
-
nativeUpdateWithByteBuffer
private final void nativeUpdateWithByteBuffer(ByteBuffer context, ByteBuffer data, int offset, int length) Update the context with a direct byte buffer.- Parameters:
context- the context as allocated incontext.data- the byte buffer to update the context with.offset- the start offset of the buffer data to update the context with.length- the number of bytes to update the context with.
-
nativeFinal
Do the final digest calculation and return it.- Parameters:
context- the context as allocated incontext.digest- the target array to write the digest data to.
-
free
Free the native context that came from nativeContext().- Parameters:
context- the context allocated with nativeContext().
-
engineGetDigestLength
protected final int engineGetDigestLength()- Overrides:
engineGetDigestLengthin classMessageDigestSpi
-
getMessageDigestList
-
engineUpdate
- Overrides:
engineUpdatein classMessageDigestSpi
-
engineUpdate
protected final void engineUpdate(byte inputByte) - Specified by:
engineUpdatein classMessageDigestSpi
-
engineUpdate
protected final void engineUpdate(byte[] input, int offset, int len) - Specified by:
engineUpdatein classMessageDigestSpi
-
engineDigest
protected final byte[] engineDigest()- Specified by:
engineDigestin classMessageDigestSpi
-
engineReset
protected final void engineReset()- Specified by:
engineResetin classMessageDigestSpi
-