fr.cryptohash
Interface Digest

All Known Implementing Classes:
BLAKE224, BLAKE256, BLAKE384, BLAKE512, BMW224, BMW256, BMW384, BMW512, CubeHash224, CubeHash256, CubeHash384, CubeHash512, DigestEngine, ECHO224, ECHO256, ECHO384, ECHO512, Fugue224, Fugue256, Fugue384, Fugue512, Groestl224, Groestl256, Groestl384, Groestl512, Hamsi224, Hamsi256, Hamsi384, Hamsi512, HAVAL128_3, HAVAL128_4, HAVAL128_5, HAVAL160_3, HAVAL160_4, HAVAL160_5, HAVAL192_3, HAVAL192_4, HAVAL192_5, HAVAL224_3, HAVAL224_4, HAVAL224_5, HAVAL256_3, HAVAL256_4, HAVAL256_5, HMAC, JH224, JH256, JH384, JH512, Keccak224, Keccak256, Keccak384, Keccak512, Luffa224, Luffa256, Luffa384, Luffa512, MD2, MD4, MD5, PANAMA, RadioGatun32, RadioGatun64, RIPEMD, RIPEMD128, RIPEMD160, SHA0, SHA1, SHA224, SHA256, SHA384, SHA512, Shabal192, Shabal224, Shabal256, Shabal384, Shabal512, ShabalGeneric, SHAvite224, SHAvite256, SHAvite384, SHAvite512, SIMD224, SIMD256, SIMD384, SIMD512, Skein224, Skein256, Skein384, Skein512, Tiger, Tiger2, Whirlpool, Whirlpool0, Whirlpool1

public interface Digest

This interface documents the API for a hash function. This interface somewhat mimics the standard java.security.MessageDigest class. We do not extend that class in order to provide compatibility with reduced Java implementations such as J2ME. Implementing a java.security.Provider compatible with Sun's JCA ought to be easy.

A Digest object maintains a running state for a hash function computation. Data is inserted with update() calls; the result is obtained from a digest() method (where some final data can be inserted as well). When a digest output has been produced, the objet is automatically resetted, and can be used immediately for another digest operation. The state of a computation can be cloned with the copy() method; this can be used to get a partial hash result without interrupting the complete computation.

Digest objects are stateful and hence not thread-safe; however, distinct Digest objects can be accessed concurrently without any problem.

 ==========================(LICENSE BEGIN)============================

 Copyright (c) 2007-2010  Projet RNRT SAPHIR
 
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 "Software"), to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject to
 the following conditions:
 
 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 ===========================(LICENSE END)=============================
 


Method Summary
 Digest copy()
          Clone the current state.
 byte[] digest()
          Finalize the current hash computation and return the hash value in a newly-allocated array.
 byte[] digest(byte[] inbuf)
          Input some bytes, then finalize the current hash computation and return the hash value in a newly-allocated array.
 int digest(byte[] outbuf, int off, int len)
          Finalize the current hash computation and store the hash value in the provided output buffer.
 int getBlockLength()
          Return the "block length" for the hash function.
 int getDigestLength()
          Get the natural hash function output length (in bytes).
 void reset()
          Reset the object: this makes it suitable for a new hash computation.
 java.lang.String toString()
          Get the display name for this function (e.g.
 void update(byte in)
          Insert one more input data byte.
 void update(byte[] inbuf)
          Insert some more bytes.
 void update(byte[] inbuf, int off, int len)
          Insert some more bytes.
 

Method Detail

update

void update(byte in)
Insert one more input data byte.

Parameters:
in - the input byte

update

void update(byte[] inbuf)
Insert some more bytes.

Parameters:
inbuf - the data bytes

update

void update(byte[] inbuf,
            int off,
            int len)
Insert some more bytes.

Parameters:
inbuf - the data buffer
off - the data offset in inbuf
len - the data length (in bytes)

digest

byte[] digest()
Finalize the current hash computation and return the hash value in a newly-allocated array. The object is resetted.

Returns:
the hash output

digest

byte[] digest(byte[] inbuf)
Input some bytes, then finalize the current hash computation and return the hash value in a newly-allocated array. The object is resetted.

Parameters:
inbuf - the input data
Returns:
the hash output

digest

int digest(byte[] outbuf,
           int off,
           int len)
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.

Parameters:
outbuf - the output buffer
off - the output offset within outbuf
len - the requested hash output length (in bytes)
Returns:
the number of bytes actually written in outbuf

getDigestLength

int getDigestLength()
Get the natural hash function output length (in bytes).

Returns:
the digest output length (in bytes)

reset

void reset()
Reset the object: this makes it suitable for a new hash computation. The current computation, if any, is discarded.


copy

Digest copy()
Clone the current state. The returned object evolves independantly of this object.

Returns:
the clone

getBlockLength

int getBlockLength()

Return the "block length" for the hash function. This value is naturally defined for iterated hash functions (Merkle-Damgard). It is used in HMAC (that's what the HMAC specification names the "B" parameter).

If the function is "block-less" then this function may return -n where n is an integer such that the block length for HMAC ("B") will be inferred from the key length, by selecting the smallest multiple of n which is no smaller than the key length. For instance, for the Fugue-xxx hash functions, this function returns -4: the virtual block length B is the HMAC key length, rounded up to the next multiple of 4.

Returns:
the internal block length (in bytes), or -n

toString

java.lang.String toString()

Get the display name for this function (e.g. "SHA-1" for SHA-1).

Overrides:
toString in class java.lang.Object
See Also:
Object