public int getPlaintextLimit(int ciphertextLimit) { return ciphertextLimit - writeMac.getSize(); }
public int getPlaintextLimit(int ciphertextLimit) { int result = ciphertextLimit; if (writeMac != null) { result -= writeMac.getSize(); } return result; }
public int getPlaintextLimit(int ciphertextLimit) { int result = ciphertextLimit; if (writeMac != null) { result -= writeMac.getSize(); } return result; }
public int getPlaintextLimit(int ciphertextLimit) { return ciphertextLimit - writeMac.getSize(); }
public int getPlaintextLimit(int ciphertextLimit) { int blockSize = encryptCipher.getBlockSize(); int macSize = writeMac.getSize(); int plaintextLimit = ciphertextLimit; // An explicit IV consumes 1 block if (useExplicitIV) { plaintextLimit -= blockSize; } // Leave room for the MAC, and require block-alignment if (encryptThenMAC) { plaintextLimit -= macSize; plaintextLimit -= plaintextLimit % blockSize; } else { plaintextLimit -= plaintextLimit % blockSize; plaintextLimit -= macSize; } // Minimum 1 byte of padding --plaintextLimit; return plaintextLimit; }
public int getPlaintextLimit(int ciphertextLimit) { int blockSize = encryptCipher.getBlockSize(); int macSize = writeMac.getSize(); int plaintextLimit = ciphertextLimit; // An explicit IV consumes 1 block if (useExplicitIV) { plaintextLimit -= blockSize; } // Leave room for the MAC, and require block-alignment if (encryptThenMAC) { plaintextLimit -= macSize; plaintextLimit -= plaintextLimit % blockSize; } else { plaintextLimit -= plaintextLimit % blockSize; plaintextLimit -= macSize; } // Minimum 1 byte of padding --plaintextLimit; return plaintextLimit; }
public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) { if (usesNonce) { updateIV(encryptCipher, true, seqNo); } byte[] outBuf = new byte[len + writeMac.getSize()]; encryptCipher.processBytes(plaintext, offset, len, outBuf, 0); byte[] mac = writeMac.calculateMac(seqNo, type, plaintext, offset, len); encryptCipher.processBytes(mac, 0, mac.length, outBuf, len); return outBuf; }
public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) { /* * draft-josefsson-salsa20-tls-04 2.1 Note that Salsa20 requires a 64-bit nonce. That * nonce is updated on the encryption of every TLS record, and is set to be the 64-bit TLS * record sequence number. In case of DTLS the 64-bit nonce is formed as the concatenation * of the 16-bit epoch with the 48-bit sequence number. */ if (usesNonce) { updateIV(encryptCipher, true, seqNo); } byte[] outBuf = new byte[len + writeMac.getSize()]; encryptCipher.processBytes(plaintext, offset, len, outBuf, 0); byte[] mac = writeMac.calculateMac(seqNo, type, plaintext, offset, len); encryptCipher.processBytes(mac, 0, mac.length, outBuf, len); return outBuf; }
public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) throws IOException { if (usesNonce) { updateIV(decryptCipher, false, seqNo); } int macSize = readMac.getSize(); if (len < macSize) { throw new TlsFatalAlert(AlertDescription.decode_error); } int plaintextLength = len - macSize; byte[] deciphered = new byte[len]; decryptCipher.processBytes(ciphertext, offset, len, deciphered, 0); checkMAC(seqNo, type, deciphered, plaintextLength, len, deciphered, 0, plaintextLength); return Arrays.copyOfRange(deciphered, 0, plaintextLength); }
public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) throws IOException { /* * draft-josefsson-salsa20-tls-04 2.1 Note that Salsa20 requires a 64-bit nonce. That * nonce is updated on the encryption of every TLS record, and is set to be the 64-bit TLS * record sequence number. In case of DTLS the 64-bit nonce is formed as the concatenation * of the 16-bit epoch with the 48-bit sequence number. */ if (usesNonce) { updateIV(decryptCipher, false, seqNo); } int macSize = readMac.getSize(); if (len < macSize) { throw new TlsFatalAlert(AlertDescription.decode_error); } int plaintextLength = len - macSize; byte[] deciphered = new byte[len]; decryptCipher.processBytes(ciphertext, offset, len, deciphered, 0); checkMAC(seqNo, type, deciphered, plaintextLength, len, deciphered, 0, plaintextLength); return Arrays.copyOfRange(deciphered, 0, plaintextLength); }
public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) throws IOException { if (readMac == null) { return Arrays.copyOfRange(ciphertext, offset, offset + len); } int macSize = readMac.getSize(); if (len < macSize) { throw new TlsFatalAlert(AlertDescription.decode_error); } int macInputLen = len - macSize; byte[] receivedMac = Arrays.copyOfRange(ciphertext, offset + macInputLen, offset + len); byte[] computedMac = readMac.calculateMac(seqNo, type, ciphertext, offset, macInputLen); if (!Arrays.constantTimeAreEqual(receivedMac, computedMac)) { throw new TlsFatalAlert(AlertDescription.bad_record_mac); } return Arrays.copyOfRange(ciphertext, offset, offset + macInputLen); } }
public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) throws IOException { if (readMac == null) { return Arrays.copyOfRange(ciphertext, offset, offset + len); } int macSize = readMac.getSize(); if (len < macSize) { throw new TlsFatalAlert(AlertDescription.decode_error); } int macInputLen = len - macSize; byte[] receivedMac = Arrays.copyOfRange(ciphertext, offset + macInputLen, offset + len); byte[] computedMac = readMac.calculateMac(seqNo, type, ciphertext, offset, macInputLen); if (!Arrays.constantTimeAreEqual(receivedMac, computedMac)) { throw new TlsFatalAlert(AlertDescription.bad_record_mac); } return Arrays.copyOfRange(ciphertext, offset, offset + macInputLen); } }
public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) int macSize = writeMac.getSize();
public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) int macSize = writeMac.getSize();
int macSize = readMac.getSize();
int macSize = readMac.getSize();