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

OpenSSLMessageDigestJDK

public class OpenSSLMessageDigestJDK extends MessageDigest
Implements the JDK MessageDigest interface using OpenSSL's EVP API.

Fields Summary
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 OpenSSLMessageDigestJDK(String algorithm)
Creates a new OpenSSLMessageDigest instance for the given algorithm name.

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

        super(algorithm);
        
        ctx = NativeCrypto.EVP_new();
        try {
            NativeCrypto.EVP_DigestInit(ctx, getAlgorithm().replace("-", "").toLowerCase());
        } catch (Exception ex) {
            throw new NoSuchAlgorithmException(ex.getMessage() + " (" + algorithm + ")");
        }
    
Methods Summary
protected byte[]engineDigest()

        byte[] result = new byte[NativeCrypto.EVP_DigestSize(ctx)];
        NativeCrypto.EVP_DigestFinal(ctx, result, 0);
        engineReset();
        return result;
    
protected intengineGetDigestLength()

        return NativeCrypto.EVP_DigestSize(ctx);
    
protected voidengineReset()

        NativeCrypto.EVP_DigestInit(ctx, getAlgorithm().replace("-", "").toLowerCase());
    
protected voidengineUpdate(byte input)

        singleByte[0] = input;
        engineUpdate(singleByte, 0, 1);
    
protected voidengineUpdate(byte[] input, int offset, int len)

        NativeCrypto.EVP_DigestUpdate(ctx, input, offset, len);
    
protected voidfinalize()

        super.finalize();
        NativeCrypto.EVP_free(ctx);
    
public static org.apache.harmony.xnet.provider.jsse.OpenSSLMessageDigestJDKgetInstance(java.lang.String algorithm)
Creates a new OpenSSLMessageDigestJDK instance for the given algorithm name.

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


                                           
          
        return new OpenSSLMessageDigestJDK(algorithm);