FileDocCategorySizeDatePackage
OpenSSLMessageDigest.javaAPI DocAndroid 1.5 API3090Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.provider.jsse

OpenSSLMessageDigest

public class OpenSSLMessageDigest extends Object implements org.bouncycastle.crypto.ExtendedDigest
Implements the BouncyCastle Digest interface using OpenSSL's EVP API.

Fields Summary
private String
algorithm
Holds the name of the hashing algorithm, e.g. "SHA-1";
private int
ctx
Holds a pointer to the native message digest context.
private byte[]
singleByte
Holds a dummy buffer for writing single bytes to the digest.
Constructors Summary
private OpenSSLMessageDigest(String algorithm)
Creates a new OpenSSLMessageDigest instance for the given algorithm name.

param
algorithm The name of the algorithm, e.g. "SHA1".

        this.algorithm = algorithm;
        ctx = NativeCrypto.EVP_new();
        try {
            NativeCrypto.EVP_DigestInit(ctx, algorithm.replace("-", "").toLowerCase());
        } catch (Exception ex) {
            throw new RuntimeException(ex.getMessage() + " (" + algorithm + ")");
        }
    
Methods Summary
public intdoFinal(byte[] out, int outOff)

        int i = NativeCrypto.EVP_DigestFinal(ctx, out, outOff);
        reset();
        return i;
    
protected voidfinalize()

        super.finalize();
        NativeCrypto.EVP_free(ctx);
    
public java.lang.StringgetAlgorithmName()

        return algorithm;
    
public intgetByteLength()

        return NativeCrypto.EVP_DigestBlockSize(ctx);
    
public intgetDigestSize()

        return NativeCrypto.EVP_DigestSize(ctx);
    
public static org.apache.harmony.xnet.provider.jsse.OpenSSLMessageDigestgetInstance(java.lang.String algorithm)
Creates a new OpenSSLMessageDigest instance for the given algorithm name.

param
algorithm The name of the algorithm, e.g. "SHA1".
return
The new OpenSSLMessageDigest instance.
throws
RuntimeException In case of problems.


                                           
         
        return new OpenSSLMessageDigest(algorithm);
    
public voidreset()

        NativeCrypto.EVP_DigestInit(ctx, algorithm.replace("-", "").toLowerCase());
    
public voidupdate(byte in)

        singleByte[0] = in;
        NativeCrypto.EVP_DigestUpdate(ctx, singleByte, 0, 1);
    
public voidupdate(byte[] in, int inOff, int len)

        NativeCrypto.EVP_DigestUpdate(ctx, in, inOff, len);