Skip to content

Commit

Permalink
Improve handling of single byte in TemplateHashSpi
Browse files Browse the repository at this point in the history
  • Loading branch information
SalusaSecondus committed Aug 7, 2019
1 parent b61fa19 commit 39ff2a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Patches
* `amazon-corretto-crypto-provider.security` updated to work on both JDK8 and JDK9+
* Improve performance of single-byte handling in message digests.

### Maintenance
* Support using a different JDK for testing via the `TEST_JAVA_HOME` JVM property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class TemplateHashSpi extends MessageDigestSpi implements Cloneable
private static final int HASH_SIZE;
private static final byte[] INITIAL_CONTEXT;

private byte[] oneByteArray = null;
private InputBuffer<byte[], byte[]> buffer;

static {
Expand Down Expand Up @@ -117,7 +118,11 @@ public TemplateHashSpi() {

@Override
protected void engineUpdate(byte input) {
engineUpdate(new byte[] { input }, 0, 1);
if (oneByteArray == null) {
oneByteArray = new byte[1];
}
oneByteArray[0] = input;
engineUpdate(oneByteArray, 0, 1);
}

// Note that routines that interact with the native buffer need to be synchronized, to ensure that we don't cause
Expand Down

0 comments on commit 39ff2a1

Please sign in to comment.