Class OpenSSLMessageDigestNative

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String algorithmName
      The OpenSSL algorithm name as returned by listMessageDigests().
      private java.nio.ByteBuffer context
      A native message digest context where the state of the current calculation is stored.
      private int digestLength
      The digest length as calculated by the engine.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static int digestLength​(java.nio.ByteBuffer context)
      Return the digest length in bytes.
      protected byte[] engineDigest()  
      protected int engineGetDigestLength()  
      protected void engineReset()  
      protected void engineUpdate​(byte inputByte)  
      protected void engineUpdate​(byte[] input, int offset, int len)  
      protected void engineUpdate​(java.nio.ByteBuffer input)  
      protected static void free​(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.ByteBuffer nativeContext()
      Returns the context size in bytes.
      private void nativeFinal​(java.nio.ByteBuffer context, byte[] digest)
      Do the final digest calculation and return it.
      private void nativeInit​(java.nio.ByteBuffer context, java.lang.String algorithmName)
      Initialize the context.
      private void nativeUpdateWithByte​(java.nio.ByteBuffer context, byte byteData)
      Update the context with a single byte.
      private void nativeUpdateWithByteArray​(java.nio.ByteBuffer context, byte[] byteArray, int offset, int length)
      Update the context with an array.
      private void nativeUpdateWithByteBuffer​(java.nio.ByteBuffer context, java.nio.ByteBuffer data, int offset, int length)
      Update the context with a direct byte buffer.
      private static void removeContext​(java.nio.ByteBuffer context)
      Removes a context allocated with nativeContext().
      • Methods inherited from class java.security.MessageDigestSpi

        clone, engineDigest
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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.
    • Constructor Detail

      • OpenSSLMessageDigestNative

        OpenSSLMessageDigestNative​(java.lang.String openSslName)
    • 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 the direct 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 in context.
        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 in context.
        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 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​(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 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​(java.nio.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​(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:
        engineGetDigestLength in class java.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:
        engineUpdate in class java.security.MessageDigestSpi
      • engineUpdate

        protected final void engineUpdate​(byte inputByte)
        Specified by:
        engineUpdate in class java.security.MessageDigestSpi
      • engineUpdate

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

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

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