Renamed frame cipher -> segment cipher, frame key -> segment key.

This commit is contained in:
akwizgran
2012-01-17 21:44:28 +00:00
parent 6085b70b85
commit 249c82d30e
14 changed files with 170 additions and 169 deletions

View File

@@ -27,8 +27,8 @@ public class KeyDerivationTest extends BriarTestCase {
@Test
public void testSixKeysAreDistinct() {
List<ErasableKey> keys = new ArrayList<ErasableKey>();
keys.add(crypto.deriveFrameKey(secret, true));
keys.add(crypto.deriveFrameKey(secret, false));
keys.add(crypto.deriveSegmentKey(secret, true));
keys.add(crypto.deriveSegmentKey(secret, false));
keys.add(crypto.deriveTagKey(secret, true));
keys.add(crypto.deriveTagKey(secret, false));
keys.add(crypto.deriveMacKey(secret, true));

View File

@@ -27,26 +27,26 @@ import com.google.inject.Injector;
public class FrameReadWriteTest extends BriarTestCase {
private final CryptoComponent crypto;
private final Cipher tagCipher, frameCipher;
private final Cipher tagCipher, segCipher;
private final Mac mac;
private final Random random;
private final byte[] outSecret;
private final ErasableKey tagKey, frameKey, macKey;
private final Mac mac;
private final ErasableKey tagKey, segKey, macKey;
public FrameReadWriteTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
crypto = i.getInstance(CryptoComponent.class);
tagCipher = crypto.getTagCipher();
frameCipher = crypto.getFrameCipher();
segCipher = crypto.getSegmentCipher();
mac = crypto.getMac();
random = new Random();
// Since we're sending frames to ourselves, we only need outgoing keys
outSecret = new byte[32];
random.nextBytes(outSecret);
tagKey = crypto.deriveTagKey(outSecret, true);
frameKey = crypto.deriveFrameKey(outSecret, true);
segKey = crypto.deriveSegmentKey(outSecret, true);
macKey = crypto.deriveMacKey(outSecret, true);
mac = crypto.getMac();
}
@Test
@@ -69,13 +69,13 @@ public class FrameReadWriteTest extends BriarTestCase {
byte[] frame1 = new byte[321];
random.nextBytes(frame1);
// Copy the keys - the copies will be erased
ErasableKey frameCopy = frameKey.copy();
ErasableKey tagCopy = tagKey.copy();
ErasableKey segCopy = segKey.copy();
ErasableKey macCopy = macKey.copy();
// Write the frames
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out,
Long.MAX_VALUE, tagCipher, frameCipher, tagCopy, frameCopy,
Long.MAX_VALUE, tagCipher, segCipher, tagCopy, segCopy,
false);
OutgoingErrorCorrectionLayer correcter =
new NullOutgoingErrorCorrectionLayer(encrypter);
@@ -94,7 +94,7 @@ public class FrameReadWriteTest extends BriarTestCase {
assertEquals(0L, TagEncoder.decodeTag(tag, tagCipher, tagKey));
// Read the frames back
IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in,
tagCipher, frameCipher, tagKey, frameKey, false, recoveredTag);
tagCipher, segCipher, tagKey, segKey, false, recoveredTag);
IncomingErrorCorrectionLayer correcter1 =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader reader = new ConnectionReaderImpl(correcter1, mac,

View File

@@ -23,17 +23,17 @@ import com.google.inject.Injector;
public class IncomingEncryptionLayerImplTest extends BriarTestCase {
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
private final Cipher tagCipher, segCipher;
private final ErasableKey tagKey, segKey;
public IncomingEncryptionLayerImplTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
tagCipher = crypto.getTagCipher();
frameCipher = crypto.getFrameCipher();
segCipher = crypto.getSegmentCipher();
tagKey = crypto.generateTestKey();
frameKey = crypto.generateTestKey();
segKey = crypto.generateTestKey();
}
@Test
@@ -44,17 +44,17 @@ public class IncomingEncryptionLayerImplTest extends BriarTestCase {
// Calculate the ciphertext for the first segment
byte[] plaintext = new byte[FRAME_HEADER_LENGTH + 123 + MAC_LENGTH];
HeaderEncoder.encodeHeader(plaintext, 0L, 123, 0);
byte[] iv = IvEncoder.encodeIv(0L, frameCipher.getBlockSize());
byte[] iv = IvEncoder.encodeIv(0L, segCipher.getBlockSize());
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext = frameCipher.doFinal(plaintext, 0, plaintext.length);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext = segCipher.doFinal(plaintext, 0, plaintext.length);
// Calculate the ciphertext for the second segment
byte[] plaintext1 = new byte[FRAME_HEADER_LENGTH + 1234 + MAC_LENGTH];
HeaderEncoder.encodeHeader(plaintext1, 1L, 1234, 0);
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1, 0,
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext1 = segCipher.doFinal(plaintext1, 0,
plaintext1.length);
// Concatenate the ciphertexts, excluding the first tag
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -63,7 +63,7 @@ public class IncomingEncryptionLayerImplTest extends BriarTestCase {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
// Use the encryption layer to decrypt the ciphertext
IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in,
tagCipher, frameCipher, tagKey, frameKey, false, tag);
tagCipher, segCipher, tagKey, segKey, false, tag);
// First segment
Segment s = new SegmentImpl();
assertTrue(decrypter.readSegment(s));
@@ -91,10 +91,10 @@ public class IncomingEncryptionLayerImplTest extends BriarTestCase {
// Calculate the ciphertext for the first segment
byte[] plaintext = new byte[FRAME_HEADER_LENGTH + 123 + MAC_LENGTH];
HeaderEncoder.encodeHeader(plaintext, 0L, 123, 0);
byte[] iv = IvEncoder.encodeIv(0L, frameCipher.getBlockSize());
byte[] iv = IvEncoder.encodeIv(0L, segCipher.getBlockSize());
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext = frameCipher.doFinal(plaintext, 0, plaintext.length);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext = segCipher.doFinal(plaintext, 0, plaintext.length);
// Calculate the tag for the second segment
byte[] tag1 = new byte[TAG_LENGTH];
TagEncoder.encodeTag(tag1, 1L, tagCipher, tagKey);
@@ -103,8 +103,8 @@ public class IncomingEncryptionLayerImplTest extends BriarTestCase {
HeaderEncoder.encodeHeader(plaintext1, 1L, 1234, 0);
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1, 0,
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext1 = segCipher.doFinal(plaintext1, 0,
plaintext1.length);
// Concatenate the ciphertexts, excluding the first tag
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -114,7 +114,7 @@ public class IncomingEncryptionLayerImplTest extends BriarTestCase {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
// Use the encryption layer to decrypt the ciphertext
IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in,
tagCipher, frameCipher, tagKey, frameKey, true, tag);
tagCipher, segCipher, tagKey, segKey, true, tag);
// First segment
Segment s = new SegmentImpl();
assertTrue(decrypter.readSegment(s));

View File

@@ -23,17 +23,17 @@ import com.google.inject.Injector;
public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase {
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
private final Cipher tagCipher, segCipher;
private final ErasableKey tagKey, segKey;
public IncomingSegmentedEncryptionLayerTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
tagCipher = crypto.getTagCipher();
frameCipher = crypto.getFrameCipher();
segCipher = crypto.getSegmentCipher();
tagKey = crypto.generateTestKey();
frameKey = crypto.generateTestKey();
segKey = crypto.generateTestKey();
}
@Test
@@ -43,18 +43,18 @@ public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase {
HeaderEncoder.encodeHeader(plaintext, 0L, 123, 0);
byte[] ciphertext = new byte[TAG_LENGTH + plaintext.length];
TagEncoder.encodeTag(ciphertext, 0L, tagCipher, tagKey);
byte[] iv = IvEncoder.encodeIv(0L, frameCipher.getBlockSize());
byte[] iv = IvEncoder.encodeIv(0L, segCipher.getBlockSize());
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
frameCipher.doFinal(plaintext, 0, plaintext.length, ciphertext,
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
segCipher.doFinal(plaintext, 0, plaintext.length, ciphertext,
TAG_LENGTH);
// Calculate the ciphertext for the second segment
byte[] plaintext1 = new byte[FRAME_HEADER_LENGTH + 1234 + MAC_LENGTH];
HeaderEncoder.encodeHeader(plaintext1, 1L, 1234, 0);
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1, 0,
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext1 = segCipher.doFinal(plaintext1, 0,
plaintext1.length);
// Buffer the first segment and create a source for the second
Segment buffered = new SegmentImpl();
@@ -64,8 +64,8 @@ public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase {
SegmentSource in = new ByteArraySegmentSource(ciphertext1);
// Use the encryption layer to decrypt the ciphertext
IncomingEncryptionLayer decrypter =
new IncomingSegmentedEncryptionLayer(in, tagCipher, frameCipher,
tagKey, frameKey, false, buffered);
new IncomingSegmentedEncryptionLayer(in, tagCipher, segCipher,
tagKey, segKey, false, buffered);
// First segment
Segment s = new SegmentImpl();
assertTrue(decrypter.readSegment(s));
@@ -92,10 +92,10 @@ public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase {
HeaderEncoder.encodeHeader(plaintext, 0L, 123, 0);
byte[] ciphertext = new byte[TAG_LENGTH + plaintext.length];
TagEncoder.encodeTag(ciphertext, 0L, tagCipher, tagKey);
byte[] iv = IvEncoder.encodeIv(0L, frameCipher.getBlockSize());
byte[] iv = IvEncoder.encodeIv(0L, segCipher.getBlockSize());
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
frameCipher.doFinal(plaintext, 0, plaintext.length, ciphertext,
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
segCipher.doFinal(plaintext, 0, plaintext.length, ciphertext,
TAG_LENGTH);
// Calculate the ciphertext for the second frame, including its tag
byte[] plaintext1 = new byte[FRAME_HEADER_LENGTH + 1234 + MAC_LENGTH];
@@ -104,8 +104,8 @@ public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase {
TagEncoder.encodeTag(ciphertext1, 1L, tagCipher, tagKey);
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
frameCipher.doFinal(plaintext1, 0, plaintext1.length, ciphertext1,
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
segCipher.doFinal(plaintext1, 0, plaintext1.length, ciphertext1,
TAG_LENGTH);
// Buffer the first segment and create a source for the second
Segment buffered = new SegmentImpl();
@@ -115,8 +115,8 @@ public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase {
SegmentSource in = new ByteArraySegmentSource(ciphertext1);
// Use the encryption layer to decrypt the ciphertext
IncomingEncryptionLayer decrypter =
new IncomingSegmentedEncryptionLayer(in, tagCipher, frameCipher,
tagKey, frameKey, true, buffered);
new IncomingSegmentedEncryptionLayer(in, tagCipher, segCipher,
tagKey, segKey, true, buffered);
// First segment
Segment s = new SegmentImpl();
assertTrue(decrypter.readSegment(s));

View File

@@ -23,17 +23,17 @@ public class OutgoingEncryptionLayerImplTest extends BriarTestCase {
private static final int MAC_LENGTH = 32;
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
private final Cipher tagCipher, segCipher;
private final ErasableKey tagKey, segKey;
public OutgoingEncryptionLayerImplTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
tagCipher = crypto.getTagCipher();
frameCipher = crypto.getFrameCipher();
segCipher = crypto.getSegmentCipher();
tagKey = crypto.generateTestKey();
frameKey = crypto.generateTestKey();
segKey = crypto.generateTestKey();
}
@Test
@@ -42,17 +42,17 @@ public class OutgoingEncryptionLayerImplTest extends BriarTestCase {
byte[] tag = new byte[TAG_LENGTH];
TagEncoder.encodeTag(tag, 0L, tagCipher, tagKey);
// Calculate the expected ciphertext for the first segment
byte[] iv = new byte[frameCipher.getBlockSize()];
byte[] iv = new byte[segCipher.getBlockSize()];
byte[] plaintext = new byte[123 + MAC_LENGTH];
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext = frameCipher.doFinal(plaintext);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext = segCipher.doFinal(plaintext);
// Calculate the expected ciphertext for the second segment
byte[] plaintext1 = new byte[1234 + MAC_LENGTH];
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext1 = segCipher.doFinal(plaintext1);
// Concatenate the ciphertexts
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(tag);
@@ -62,7 +62,7 @@ public class OutgoingEncryptionLayerImplTest extends BriarTestCase {
// Use the encryption layer to encrypt the plaintext
out.reset();
OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out,
Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey,
Long.MAX_VALUE, tagCipher, segCipher, tagKey, segKey,
false);
Segment s = new SegmentImpl();
System.arraycopy(plaintext, 0, s.getBuffer(), 0, plaintext.length);
@@ -86,11 +86,11 @@ public class OutgoingEncryptionLayerImplTest extends BriarTestCase {
byte[] tag = new byte[TAG_LENGTH];
TagEncoder.encodeTag(tag, 0L, tagCipher, tagKey);
// Calculate the expected ciphertext for the first segment
byte[] iv = new byte[frameCipher.getBlockSize()];
byte[] iv = new byte[segCipher.getBlockSize()];
byte[] plaintext = new byte[123 + MAC_LENGTH];
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext = frameCipher.doFinal(plaintext);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext = segCipher.doFinal(plaintext);
// Calculate the expected tag for the second segment
byte[] tag1 = new byte[TAG_LENGTH];
TagEncoder.encodeTag(tag1, 1L, tagCipher, tagKey);
@@ -98,8 +98,8 @@ public class OutgoingEncryptionLayerImplTest extends BriarTestCase {
byte[] plaintext1 = new byte[1234 + MAC_LENGTH];
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext1 = segCipher.doFinal(plaintext1);
// Concatenate the ciphertexts
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(tag);
@@ -110,7 +110,7 @@ public class OutgoingEncryptionLayerImplTest extends BriarTestCase {
// Use the encryption layer to encrypt the plaintext
out.reset();
OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out,
Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey, true);
Long.MAX_VALUE, tagCipher, segCipher, tagKey, segKey, true);
Segment s = new SegmentImpl();
System.arraycopy(plaintext, 0, s.getBuffer(), 0, plaintext.length);
s.setLength(plaintext.length);

View File

@@ -25,17 +25,17 @@ public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase {
private static final int MAC_LENGTH = 32;
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
private final Cipher tagCipher, segCipher;
private final ErasableKey tagKey, segKey;
public OutgoingSegmentedEncryptionLayerTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
tagCipher = crypto.getTagCipher();
frameCipher = crypto.getFrameCipher();
segCipher = crypto.getSegmentCipher();
tagKey = crypto.generateTestKey();
frameKey = crypto.generateTestKey();
segKey = crypto.generateTestKey();
}
@Test
@@ -44,17 +44,17 @@ public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase {
byte[] tag = new byte[TAG_LENGTH];
TagEncoder.encodeTag(tag, 0L, tagCipher, tagKey);
// Calculate the expected ciphertext for the first segment
byte[] iv = new byte[frameCipher.getBlockSize()];
byte[] iv = new byte[segCipher.getBlockSize()];
byte[] plaintext = new byte[123 + MAC_LENGTH];
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext = frameCipher.doFinal(plaintext);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext = segCipher.doFinal(plaintext);
// Calculate the expected ciphertext for the second segment
byte[] plaintext1 = new byte[1234 + MAC_LENGTH];
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext1 = segCipher.doFinal(plaintext1);
// Concatenate the ciphertexts
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(tag);
@@ -65,7 +65,7 @@ public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase {
ByteArraySegmentSink sink = new ByteArraySegmentSink();
OutgoingEncryptionLayer encrypter =
new OutgoingSegmentedEncryptionLayer(sink, Long.MAX_VALUE,
tagCipher, frameCipher, tagKey, frameKey, false);
tagCipher, segCipher, tagKey, segKey, false);
Segment s = new SegmentImpl();
System.arraycopy(plaintext, 0, s.getBuffer(), 0, plaintext.length);
s.setLength(plaintext.length);
@@ -88,11 +88,11 @@ public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase {
byte[] tag = new byte[TAG_LENGTH];
TagEncoder.encodeTag(tag, 0L, tagCipher, tagKey);
// Calculate the expected ciphertext for the first segment
byte[] iv = new byte[frameCipher.getBlockSize()];
byte[] iv = new byte[segCipher.getBlockSize()];
byte[] plaintext = new byte[123 + MAC_LENGTH];
IvParameterSpec ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext = frameCipher.doFinal(plaintext);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext = segCipher.doFinal(plaintext);
// Calculate the expected tag for the second segment
byte[] tag1 = new byte[TAG_LENGTH];
TagEncoder.encodeTag(tag1, 1L, tagCipher, tagKey);
@@ -100,8 +100,8 @@ public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase {
byte[] plaintext1 = new byte[1234 + MAC_LENGTH];
IvEncoder.updateIv(iv, 1L);
ivSpec = new IvParameterSpec(iv);
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1);
segCipher.init(Cipher.ENCRYPT_MODE, segKey, ivSpec);
byte[] ciphertext1 = segCipher.doFinal(plaintext1);
// Concatenate the ciphertexts
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(tag);
@@ -113,7 +113,7 @@ public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase {
SegmentSink sink = new ByteArraySegmentSink();
OutgoingEncryptionLayer encrypter =
new OutgoingSegmentedEncryptionLayer(sink, Long.MAX_VALUE,
tagCipher, frameCipher, tagKey, frameKey, true);
tagCipher, segCipher, tagKey, segKey, true);
Segment s = new SegmentImpl();
System.arraycopy(plaintext, 0, s.getBuffer(), 0, plaintext.length);
s.setLength(plaintext.length);