Class MD5Spi
- java.lang.Object
-
- java.security.MessageDigestSpi
-
- com.amazon.corretto.crypto.provider.MD5Spi
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class MD5Spi extends java.security.MessageDigestSpi implements java.lang.CloneableTemplate for hash function bindings. Unfortunately using openssl's common EVP interface for hash functions introduces significant performance overhead (to the point that the default JCE provider is faster for <= 32 byte hashes). As such we build direct bindings to the older interfaces for each of our supported hash functions - since these are nearly identical, though, we use templates on both the Java and C++ sides to accomplish this. To further improve performance, we avoid using the C++ heap to allocate the state datastructure for our hash function - instead, we allocate a java byte array and put the hash state in it directly. This is safe as long as 1) byte[]s are aligned properly (seems to be the case due to Java object headers) and 2) no native-side pointers exist pointing inside the hash function state structure. Since the latter is currently true and changing it would break the openssl ABI we should be safe. By doing this hack, then, we avoid malloc/free overheads as well as Java finalizer overhead, and can avoid a native call for initializing the hash function (by instead cloning a copy of the initial state of the hash function).
-
-
Constructor Summary
Constructors Constructor Description MD5Spi()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()protected byte[]engineDigest()protected intengineDigest(byte[] buf, int offset, int len)protected intengineGetDigestLength()protected voidengineReset()protected voidengineUpdate(byte input)protected voidengineUpdate(byte[] input, int offset, int length)protected voidengineUpdate(java.nio.ByteBuffer buf)
-
-
-
Method Detail
-
engineUpdate
protected void engineUpdate(byte input)
- Specified by:
engineUpdatein classjava.security.MessageDigestSpi
-
engineUpdate
protected void engineUpdate(byte[] input, int offset, int length)- Specified by:
engineUpdatein classjava.security.MessageDigestSpi
-
engineUpdate
protected void engineUpdate(java.nio.ByteBuffer buf)
- Overrides:
engineUpdatein classjava.security.MessageDigestSpi
-
engineGetDigestLength
protected int engineGetDigestLength()
- Overrides:
engineGetDigestLengthin classjava.security.MessageDigestSpi
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.security.MessageDigestSpi
-
engineDigest
protected byte[] engineDigest()
- Specified by:
engineDigestin classjava.security.MessageDigestSpi
-
engineDigest
protected int engineDigest(byte[] buf, int offset, int len) throws java.security.DigestException- Overrides:
engineDigestin classjava.security.MessageDigestSpi- Throws:
java.security.DigestException
-
engineReset
protected void engineReset()
- Specified by:
engineResetin classjava.security.MessageDigestSpi
-
-