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 MessageDigestSpi
An interface to OpenSSL message digest functions.
  • Field Details

  • Constructor Details

    • OpenSSLMessageDigestNative

      OpenSSLMessageDigestNative(String openSslName)
  • Method Details

    • digestLength

      private static int digestLength(ByteBuffer context)
      Return the digest length in bytes.
      Returns:
      the digest length in bytes.
    • removeContext

      private static void removeContext(ByteBuffer context)
      Removes a context allocated with nativeContext().
      Parameters:
      context - the context to free.
    • listMessageDigests

      private static 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 ByteBuffer nativeContext()
      Returns the context size in bytes. This is used to allocate the direct ByteBuffer.
      Returns:
      a ByteBuffer containing the native message digest context.
    • nativeInit

      private final void nativeInit(ByteBuffer context, String algorithmName)
      Initialize the context.
      Parameters:
      context - the context as allocated in context.
      algorithmName - the OpenSSL algorithm name as returned by listMessageDigests().
    • nativeUpdateWithByte

      private final void nativeUpdateWithByte(ByteBuffer context, byte byteData)
      Update the context with a single byte.
      Parameters:
      context - the context as allocated in context.
      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 in context.
      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 in context.
      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(ByteBuffer context, byte[] digest)
      Do the final digest calculation and return it.
      Parameters:
      context - the context as allocated in context.
      digest - the target array to write the digest data to.
    • free

      protected static void free(ByteBuffer context)
      Free the native context that came from nativeContext().
      Parameters:
      context - the context allocated with nativeContext().
    • engineGetDigestLength

      protected final int engineGetDigestLength()
      Overrides:
      engineGetDigestLength in class MessageDigestSpi
    • getMessageDigestList

      protected static Set<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(ByteBuffer input)
      Overrides:
      engineUpdate in class MessageDigestSpi
    • engineUpdate

      protected final void engineUpdate(byte inputByte)
      Specified by:
      engineUpdate in class MessageDigestSpi
    • engineUpdate

      protected final void engineUpdate(byte[] input, int offset, int len)
      Specified by:
      engineUpdate in class MessageDigestSpi
    • engineDigest

      protected final byte[] engineDigest()
      Specified by:
      engineDigest in class MessageDigestSpi
    • engineReset

      protected final void engineReset()
      Specified by:
      engineReset in class MessageDigestSpi