mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Use a constant for the tag size.
This commit is contained in:
@@ -16,7 +16,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
*/
|
||||
class SharedSecret {
|
||||
|
||||
private static final int IV_BYTES = 16;
|
||||
static final int IV_BYTES = 16;
|
||||
|
||||
private final IvParameterSpec iv;
|
||||
private final boolean alice;
|
||||
|
||||
@@ -92,7 +92,8 @@ DatabaseListener {
|
||||
|
||||
public synchronized ContactId acceptConnection(byte[] tag)
|
||||
throws DbException {
|
||||
if(tag.length != 16) throw new IllegalArgumentException();
|
||||
if(tag.length != Constants.TAG_BYTES)
|
||||
throw new IllegalArgumentException();
|
||||
if(!initialised) initialise();
|
||||
Bytes b = new Bytes(tag);
|
||||
ContactId contactId = tagToContact.remove(b);
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.sf.briar.transport;
|
||||
|
||||
interface Constants {
|
||||
|
||||
static final int TAG_BYTES = 16;
|
||||
static final int MAX_16_BIT_UNSIGNED = 65535; // 2^16 - 1
|
||||
static final long MAX_32_BIT_UNSIGNED = 4294967295L; // 2^32 - 1
|
||||
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import java.io.OutputStream;
|
||||
|
||||
interface PacketEncrypter {
|
||||
|
||||
/** Returns the output stream to which packets should be written. */
|
||||
OutputStream getOutputStream();
|
||||
|
||||
/** Encrypts the given tag and writes it to the underlying output stream. */
|
||||
void writeTag(byte[] tag) throws IOException;
|
||||
|
||||
/** Finishes writing the current packet. */
|
||||
void finishPacket() throws IOException;
|
||||
}
|
||||
|
||||
@@ -15,14 +15,12 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
class PacketEncrypterImpl extends FilterOutputStream
|
||||
implements PacketEncrypter {
|
||||
|
||||
private final OutputStream out;
|
||||
private final Cipher tagCipher, packetCipher;
|
||||
private final SecretKey packetKey;
|
||||
|
||||
PacketEncrypterImpl(OutputStream out, Cipher tagCipher,
|
||||
Cipher packetCipher, SecretKey tagKey, SecretKey packetKey) {
|
||||
super(out);
|
||||
this.out = out;
|
||||
this.tagCipher = tagCipher;
|
||||
this.packetCipher = packetCipher;
|
||||
this.packetKey = packetKey;
|
||||
@@ -31,7 +29,7 @@ implements PacketEncrypter {
|
||||
} catch(InvalidKeyException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
if(tagCipher.getOutputSize(16) != 16)
|
||||
if(tagCipher.getOutputSize(Constants.TAG_BYTES) != Constants.TAG_BYTES)
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
@@ -40,7 +38,8 @@ implements PacketEncrypter {
|
||||
}
|
||||
|
||||
public void writeTag(byte[] tag) throws IOException {
|
||||
if(tag.length != 16) throw new IllegalArgumentException();
|
||||
if(tag.length != Constants.TAG_BYTES)
|
||||
throw new IllegalArgumentException();
|
||||
IvParameterSpec iv = new IvParameterSpec(tag);
|
||||
try {
|
||||
out.write(tagCipher.doFinal(tag));
|
||||
|
||||
@@ -4,7 +4,7 @@ public class TagEncoder {
|
||||
|
||||
static byte[] encodeTag(int transportIdentifier, long connectionNumber,
|
||||
long packetNumber) {
|
||||
byte[] tag = new byte[16];
|
||||
byte[] tag = new byte[Constants.TAG_BYTES];
|
||||
// Encode the transport identifier as an unsigned 16-bit integer
|
||||
writeUint16(transportIdentifier, tag, 2);
|
||||
// Encode the connection number as an unsigned 32-bit integer
|
||||
|
||||
Reference in New Issue
Block a user