Package de.sfuhrm.openssl4j
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
class OpenSSLMessageDigestNative extends java.security.MessageDigestSpiAn interface to OpenSSL message digest functions.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringalgorithmNameThe OpenSSL algorithm name as returned by listMessageDigests().private java.nio.ByteBuffercontextA native message digest context where the state of the current calculation is stored.private intdigestLengthThe digest length as calculated by the engine.
-
Constructor Summary
Constructors Constructor Description OpenSSLMessageDigestNative(java.lang.String openSslName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intdigestLength(java.nio.ByteBuffer context)Return the digest length in bytes.protected byte[]engineDigest()protected intengineGetDigestLength()protected voidengineReset()protected voidengineUpdate(byte inputByte)protected voidengineUpdate(byte[] input, int offset, int len)protected voidengineUpdate(java.nio.ByteBuffer input)protected static voidfree(java.nio.ByteBuffer context)Free the native context that came from nativeContext().protected static java.util.Set<java.lang.String>getMessageDigestList()Get the list of digest algorithms supported by the OpenSSL library.private static java.lang.String[]listMessageDigests()Get the list of MessageDigest algorithms supported by OpenSSL.private java.nio.ByteBuffernativeContext()Returns the context size in bytes.private voidnativeFinal(java.nio.ByteBuffer context, byte[] digest)Do the final digest calculation and return it.private voidnativeInit(java.nio.ByteBuffer context, java.lang.String algorithmName)Initialize the context.private voidnativeUpdateWithByte(java.nio.ByteBuffer context, byte byteData)Update the context with a single byte.private voidnativeUpdateWithByteArray(java.nio.ByteBuffer context, byte[] byteArray, int offset, int length)Update the context with an array.private voidnativeUpdateWithByteBuffer(java.nio.ByteBuffer context, java.nio.ByteBuffer data, int offset, int length)Update the context with a direct byte buffer.private static voidremoveContext(java.nio.ByteBuffer context)Removes a context allocated with nativeContext().
-
-
-
Field Detail
-
context
private final java.nio.ByteBuffer 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
private final java.lang.String algorithmName
The OpenSSL algorithm name as returned by listMessageDigests().
-
digestLength
private final int digestLength
The digest length as calculated by the engine.
-
-
Method Detail
-
digestLength
private static int digestLength(java.nio.ByteBuffer context)
Return the digest length in bytes.- Returns:
- the digest length in bytes.
-
removeContext
private static void removeContext(java.nio.ByteBuffer context)
Removes a context allocated with nativeContext().- Parameters:
context- the context to free.
-
listMessageDigests
private static java.lang.String[] listMessageDigests()
Get the list of MessageDigest algorithms supported by OpenSSL.- Returns:
- an array of supported message digest algorithms from the OpenSSL library.
-
nativeContext
private final java.nio.ByteBuffer nativeContext()
Returns the context size in bytes. This is used to allocate thedirect ByteBuffer.- Returns:
- a ByteBuffer containing the native message digest context.
-
nativeInit
private final void nativeInit(java.nio.ByteBuffer context, java.lang.String algorithmName)Initialize the context.- Parameters:
context- the context as allocated incontext.algorithmName- the OpenSSL algorithm name as returned by listMessageDigests().
-
nativeUpdateWithByte
private final void nativeUpdateWithByte(java.nio.ByteBuffer context, byte byteData)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(java.nio.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(java.nio.ByteBuffer context, java.nio.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
private final void nativeFinal(java.nio.ByteBuffer context, byte[] digest)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
protected static void free(java.nio.ByteBuffer context)
Free the native context that came from nativeContext().- Parameters:
context- the context allocated with nativeContext().
-
engineGetDigestLength
protected final int engineGetDigestLength()
- Overrides:
engineGetDigestLengthin classjava.security.MessageDigestSpi
-
getMessageDigestList
protected static java.util.Set<java.lang.String> getMessageDigestList()
Get the list of digest algorithms supported by the OpenSSL library.- Returns:
- a Set of supported message digest algorithms.
-
engineUpdate
protected final void engineUpdate(java.nio.ByteBuffer input)
- Overrides:
engineUpdatein classjava.security.MessageDigestSpi
-
engineUpdate
protected final void engineUpdate(byte inputByte)
- Specified by:
engineUpdatein classjava.security.MessageDigestSpi
-
engineUpdate
protected final void engineUpdate(byte[] input, int offset, int len)- Specified by:
engineUpdatein classjava.security.MessageDigestSpi
-
engineDigest
protected final byte[] engineDigest()
- Specified by:
engineDigestin classjava.security.MessageDigestSpi
-
engineReset
protected final void engineReset()
- Specified by:
engineResetin classjava.security.MessageDigestSpi
-
-