Package fr.cryptohash

Class DigestEngine

    • Constructor Summary

      Constructors 
      Constructor Description
      DigestEngine()
      Instantiate the engine.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected Digest copyState​(DigestEngine dest)
      This function copies the internal buffering state to some other instance of a class extending DigestEngine.
      byte[] digest()
      Finalize the current hash computation and return the hash value in a newly-allocated array.
      byte[] digest​(byte[] input)
      Input some bytes, then finalize the current hash computation and return the hash value in a newly-allocated array.
      int digest​(byte[] buf, int offset, int len)
      Finalize the current hash computation and store the hash value in the provided output buffer.
      protected abstract void doInit()
      This function is called at object creation time; the implementation should use it to perform initialization tasks.
      protected abstract void doPadding​(byte[] buf, int off)
      Perform the final padding and store the result in the provided buffer.
      protected abstract void engineReset()
      Reset the hash algorithm state.
      protected int flush()
      Flush internal buffers, so that less than a block of data may at most be upheld.
      protected byte[] getBlockBuffer()
      Get a reference to an internal buffer with the same size than a block.
      protected long getBlockCount()
      Get the "block count": this is the number of times the processBlock(byte[]) method has been invoked for the current hash operation.
      protected int getInternalBlockLength()
      Get the internal block length.
      protected abstract void processBlock​(byte[] data)
      Process one block of data.
      void reset()
      Reset the object: this makes it suitable for a new hash computation.
      void update​(byte input)
      Insert one more input data byte.
      void update​(byte[] input)
      Insert some more bytes.
      void update​(byte[] input, int offset, int len)
      Insert some more bytes.
    • Constructor Detail

      • DigestEngine

        public DigestEngine()
        Instantiate the engine.
    • Method Detail

      • engineReset

        protected abstract void engineReset()
        Reset the hash algorithm state.
      • processBlock

        protected abstract void processBlock​(byte[] data)
        Process one block of data.
        Parameters:
        data - the data block
      • doPadding

        protected abstract void doPadding​(byte[] buf,
                                          int off)
        Perform the final padding and store the result in the provided buffer. This method shall call flush() and then update(byte) with the appropriate padding data in order to get the full input data.
        Parameters:
        buf - the output buffer
        off - the output offset
      • doInit

        protected abstract void doInit()
        This function is called at object creation time; the implementation should use it to perform initialization tasks. After this method is called, the implementation should be ready to process data or meaningfully honour calls such as Digest.getDigestLength().
      • digest

        public byte[] digest()
        Description copied from interface: Digest
        Finalize the current hash computation and return the hash value in a newly-allocated array. The object is resetted.
        Specified by:
        digest in interface Digest
        Returns:
        the hash output
        See Also:
        Digest
      • digest

        public byte[] digest​(byte[] input)
        Description copied from interface: Digest
        Input some bytes, then finalize the current hash computation and return the hash value in a newly-allocated array. The object is resetted.
        Specified by:
        digest in interface Digest
        Parameters:
        input - the input data
        Returns:
        the hash output
        See Also:
        Digest
      • digest

        public int digest​(byte[] buf,
                          int offset,
                          int len)
        Description copied from interface: Digest
        Finalize the current hash computation and store the hash value in the provided output buffer. The len parameter contains the maximum number of bytes that should be written; no more bytes than the natural hash function output length will be produced. If len is smaller than the natural hash output length, the hash output is truncated to its first len bytes. The object is resetted.
        Specified by:
        digest in interface Digest
        Parameters:
        buf - the output buffer
        offset - the output offset within outbuf
        len - the requested hash output length (in bytes)
        Returns:
        the number of bytes actually written in outbuf
        See Also:
        Digest
      • reset

        public void reset()
        Description copied from interface: Digest
        Reset the object: this makes it suitable for a new hash computation. The current computation, if any, is discarded.
        Specified by:
        reset in interface Digest
        See Also:
        Digest
      • update

        public void update​(byte input)
        Description copied from interface: Digest
        Insert one more input data byte.
        Specified by:
        update in interface Digest
        Parameters:
        input - the input byte
        See Also:
        Digest
      • update

        public void update​(byte[] input)
        Description copied from interface: Digest
        Insert some more bytes.
        Specified by:
        update in interface Digest
        Parameters:
        input - the data bytes
        See Also:
        Digest
      • update

        public void update​(byte[] input,
                           int offset,
                           int len)
        Description copied from interface: Digest
        Insert some more bytes.
        Specified by:
        update in interface Digest
        Parameters:
        input - the data buffer
        offset - the data offset in inbuf
        len - the data length (in bytes)
        See Also:
        Digest
      • getInternalBlockLength

        protected int getInternalBlockLength()
        Get the internal block length. This is the length (in bytes) of the array which will be passed as parameter to processBlock(byte[]). The default implementation of this method calls Digest.getBlockLength() and returns the same value. Overriding this method is useful when the advertised block length (which is used, for instance, by HMAC) is suboptimal with regards to internal buffering needs.
        Returns:
        the internal block length (in bytes)
      • flush

        protected final int flush()
        Flush internal buffers, so that less than a block of data may at most be upheld.
        Returns:
        the number of bytes still unprocessed after the flush
      • getBlockBuffer

        protected final byte[] getBlockBuffer()
        Get a reference to an internal buffer with the same size than a block. The contents of that buffer are defined only immediately after a call to flush(): if flush() return the value n, then the first n bytes of the array returned by this method are the n bytes of input data which are still unprocessed. The values of the remaining bytes are undefined and may be altered at will.
        Returns:
        a block-sized internal buffer
      • getBlockCount

        protected long getBlockCount()
        Get the "block count": this is the number of times the processBlock(byte[]) method has been invoked for the current hash operation. That counter is incremented after the call to processBlock(byte[]).
        Returns:
        the block count
      • copyState

        protected Digest copyState​(DigestEngine dest)
        This function copies the internal buffering state to some other instance of a class extending DigestEngine. It returns a reference to the copy. This method is intended to be called by the implementation of the Digest.copy() method.
        Parameters:
        dest - the copy
        Returns:
        the value dest