Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.java.security.hash
Class MD2  view MD2 download MD2.java

java.lang.Object
  extended bygnu.java.security.hash.BaseHash
      extended bygnu.java.security.hash.MD2
All Implemented Interfaces:
java.lang.Cloneable, IMessageDigest

public class MD2
extends BaseHash

An implementation of the MD2 message digest algorithm.

MD2 is not widely used. Unless it is needed for compatibility with existing systems, it is not recommended for use in new applications.

References:

  1. The MD2 Message-Digest Algorithm.
    B. Kaliski.
  2. The RFC ERRATA PAGE under section RFC 1319.


Field Summary
private static int BLOCK_LENGTH
          The MD2 algorithm operates on 128-bit blocks, or 16 bytes.
private  byte[] checksum
          The checksum computed so far.
private static int DIGEST_LENGTH
          An MD2 message digest is always 128-bits long, or 16 bytes.
private static java.lang.String DIGEST0
          The output of this message digest when no data has been input.
private static byte[] PI
          256 byte "random" permutation of the digits of pi.
private static java.lang.Boolean valid
          caches the result of the correctness test, once executed.
private  byte[] work
          Work array needed by encrypt method.
 
Fields inherited from class gnu.java.security.hash.BaseHash
blockSize, buffer, count, hashSize, name
 
Constructor Summary
  MD2()
          Creates a new MD2 digest ready for use.
private MD2(MD2 md2)
          Private constructor used for cloning.
 
Method Summary
 java.lang.Object clone()
          Returns a clone copy of this instance.
private  void encryptBlock(byte[] in, int off)
          Adds a new block (BLOCK_LENGTH bytes) to the running digest from the given byte array starting from the given offset.
protected  byte[] getResult()
          Constructs the result from the contents of the current context.
protected  byte[] padBuffer()
          Generates an array of padding bytes.
protected  void resetContext()
          Resets the instance for future re-use.
 boolean selfTest()
          A basic test.
protected  void transform(byte[] in, int off)
          Adds BLOCK_LENGTH bytes to the running digest.
private  void updateCheckSumAndEncryptBlock(byte[] in, int off)
          Optimized method that combines a checksum update and encrypt of a block.
 
Methods inherited from class gnu.java.security.hash.BaseHash
blockSize, digest, hashSize, name, reset, update, update, update
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIGEST_LENGTH

private static final int DIGEST_LENGTH
An MD2 message digest is always 128-bits long, or 16 bytes.

See Also:
Constant Field Values

BLOCK_LENGTH

private static final int BLOCK_LENGTH
The MD2 algorithm operates on 128-bit blocks, or 16 bytes.

See Also:
Constant Field Values

PI

private static final byte[] PI
256 byte "random" permutation of the digits of pi.


DIGEST0

private static final java.lang.String DIGEST0
The output of this message digest when no data has been input.

See Also:
Constant Field Values

valid

private static java.lang.Boolean valid
caches the result of the correctness test, once executed.


checksum

private byte[] checksum
The checksum computed so far.


work

private byte[] work
Work array needed by encrypt method. First BLOCK_LENGTH bytes are also used to store the running digest.

Constructor Detail

MD2

public MD2()
Creates a new MD2 digest ready for use.


MD2

private MD2(MD2 md2)

Private constructor used for cloning.

Method Detail

clone

public java.lang.Object clone()
Description copied from interface: IMessageDigest

Returns a clone copy of this instance.

Specified by:
clone in interface IMessageDigest
Specified by:
clone in class BaseHash

getResult

protected byte[] getResult()
Description copied from class: BaseHash

Constructs the result from the contents of the current context.

Specified by:
getResult in class BaseHash

resetContext

protected void resetContext()
Description copied from class: BaseHash
Resets the instance for future re-use.

Specified by:
resetContext in class BaseHash

selfTest

public boolean selfTest()
Description copied from interface: IMessageDigest

A basic test. Ensures that the digest of a pre-determined message is equal to a known pre-computed value.

Specified by:
selfTest in interface IMessageDigest
Specified by:
selfTest in class BaseHash

padBuffer

protected byte[] padBuffer()

Generates an array of padding bytes. The padding is defined as i bytes of value i, where i is the number of bytes to fill the last block of the message to BLOCK_LENGTH bytes (or BLOCK_LENGTH bytes when the last block was completely full).

Specified by:
padBuffer in class BaseHash

transform

protected void transform(byte[] in,
                         int off)

Adds BLOCK_LENGTH bytes to the running digest.

Specified by:
transform in class BaseHash

encryptBlock

private void encryptBlock(byte[] in,
                          int off)
Adds a new block (BLOCK_LENGTH bytes) to the running digest from the given byte array starting from the given offset.


updateCheckSumAndEncryptBlock

private void updateCheckSumAndEncryptBlock(byte[] in,
                                           int off)
Optimized method that combines a checksum update and encrypt of a block.