diff options
author | David Hook <dgh@cryptoworkshop.com> | 2013-05-13 05:59:55 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2013-05-13 05:59:55 +0400 |
commit | a9922353b97814b506b8e9ebfc4745610f7a8e21 (patch) | |
tree | 09dd5f84fe082ad40274cb64b297b081c83d3876 | |
parent | 24055cb0f9e489c823d58a0827b21cd60ec6c23c (diff) |
BJA-450 extra optimisation
-rw-r--r-- | src/main/java/org/bouncycastle/crypto/macs/HMac.java | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/main/java/org/bouncycastle/crypto/macs/HMac.java b/src/main/java/org/bouncycastle/crypto/macs/HMac.java index e9f070f9..d4345d9b 100644 --- a/src/main/java/org/bouncycastle/crypto/macs/HMac.java +++ b/src/main/java/org/bouncycastle/crypto/macs/HMac.java @@ -24,7 +24,8 @@ public class HMac private Digest digest; private int digestSize; private int blockLength; - private Memoable savedState; + private Memoable ipadState; + private Memoable opadState; private byte[] inputPad; private byte[] outputBuf; @@ -135,11 +136,18 @@ public class HMac xorPad(inputPad, blockLength, IPAD); xorPad(outputBuf, blockLength, OPAD); + if (digest instanceof Memoable) + { + opadState = ((Memoable)digest).copy(); + + ((Digest)opadState).update(outputBuf, 0, blockLength); + } + digest.update(inputPad, 0, inputPad.length); if (digest instanceof Memoable) { - savedState = ((Memoable)digest).copy(); + ipadState = ((Memoable)digest).copy(); } } @@ -167,7 +175,17 @@ public class HMac int outOff) { digest.doFinal(outputBuf, blockLength); - digest.update(outputBuf, 0, outputBuf.length); + + if (opadState != null) + { + ((Memoable)digest).reset(opadState); + digest.update(outputBuf, blockLength, digest.getDigestSize()); + } + else + { + digest.update(outputBuf, 0, outputBuf.length); + } + int len = digest.doFinal(out, outOff); for (int i = blockLength; i < outputBuf.length; i++) @@ -175,9 +193,9 @@ public class HMac outputBuf[i] = 0; } - if (savedState != null) + if (ipadState != null) { - ((Memoable)digest).reset(savedState); + ((Memoable)digest).reset(ipadState); } else { |