Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2013-06-20 08:42:36 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2013-06-20 08:42:36 +0400
commitce89320a24463a132f2dd4de6333657f49cb3722 (patch)
treec46c35183a441dba11552948c41c1286717aeff1 /core/src/main/java/org/bouncycastle/crypto/tls/TlsMac.java
parentd276ffb5b25193a449415d6555660bd0d28ce3a7 (diff)
Remove use of ByteArrayOutputStream in TlsMac
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto/tls/TlsMac.java')
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/tls/TlsMac.java30
1 files changed, 8 insertions, 22 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/tls/TlsMac.java b/core/src/main/java/org/bouncycastle/crypto/tls/TlsMac.java
index ec111302..35b4858d 100644
--- a/core/src/main/java/org/bouncycastle/crypto/tls/TlsMac.java
+++ b/core/src/main/java/org/bouncycastle/crypto/tls/TlsMac.java
@@ -15,7 +15,6 @@ import org.bouncycastle.util.Arrays;
*/
public class TlsMac
{
-
protected TlsContext context;
protected byte[] secret;
protected Mac mac;
@@ -51,7 +50,7 @@ public class TlsMac
this.digestOverhead = 8;
}
- if (context.getServerVersion().isSSL())
+ if (TlsUtils.isSSL(context))
{
this.mac = new SSL3Mac(digest);
@@ -102,30 +101,18 @@ public class TlsMac
*/
public byte[] calculateMac(long seqNo, short type, byte[] message, int offset, int length)
{
-
ProtocolVersion serverVersion = context.getServerVersion();
boolean isSSL = serverVersion.isSSL();
- ByteArrayOutputStream bosMac = new ByteArrayOutputStream(isSSL ? 11 : 13);
- try
+ byte[] macHeader = new byte[isSSL ? 11 : 13];
+ TlsUtils.writeUint64(seqNo, macHeader, 0);
+ TlsUtils.writeUint8(type, macHeader, 8);
+ if (!isSSL)
{
- TlsUtils.writeUint64(seqNo, bosMac);
- TlsUtils.writeUint8(type, bosMac);
-
- if (!isSSL)
- {
- TlsUtils.writeVersion(serverVersion, bosMac);
- }
-
- TlsUtils.writeUint16(length, bosMac);
- }
- catch (IOException e)
- {
- // This should never happen
- throw new IllegalStateException("Internal error during mac calculation");
+ TlsUtils.writeVersion(serverVersion, macHeader, 9);
}
+ TlsUtils.writeUint16(length, macHeader, macHeader.length - 2);
- byte[] macHeader = bosMac.toByteArray();
mac.update(macHeader, 0, macHeader.length);
mac.update(message, offset, length);
@@ -135,9 +122,8 @@ public class TlsMac
}
public byte[] calculateMacConstantTime(long seqNo, short type, byte[] message, int offset, int length,
- int fullLength, byte[] dummyData)
+ int fullLength, byte[] dummyData)
{
-
/*
* Actual MAC only calculated on 'length' bytes...
*/