Package org.bouncycastle.tls.crypto.impl
Class TlsBlockCipher
java.lang.Object
org.bouncycastle.tls.crypto.impl.TlsBlockCipher
- All Implemented Interfaces:
TlsCipher
A generic TLS 1.0-1.2 block cipher. This can be used for AES or 3DES for example.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final TlsCryptoParametersprotected final TlsBlockCipherImplprotected final TlsBlockCipherImplprotected final booleanprotected final byte[]protected final TlsSuiteMacprotected final booleanprotected final booleanprotected final TlsSuiteMac -
Constructor Summary
ConstructorsConstructorDescriptionTlsBlockCipher(TlsCryptoParameters cryptoParams, TlsBlockCipherImpl encryptCipher, TlsBlockCipherImpl decryptCipher, TlsHMAC clientMac, TlsHMAC serverMac, int cipherKeySize) -
Method Summary
Modifier and TypeMethodDescriptionprotected intcheckPaddingConstantTime(byte[] buf, int off, int len, int blockSize, int macSize) protected intchooseExtraPadBlocks(int max) decodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion, byte[] ciphertext, int offset, int len) Decode the passed in ciphertext using the current bulk cipher.encodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, byte[] plaintext, int offset, int len) Encode the passed in plaintext using the current bulk cipher.intgetCiphertextDecodeLimit(int plaintextLimit) Return the maximum input size for a ciphertext given a maximum output size for the plaintext of plaintextLimit bytes.intgetCiphertextEncodeLimit(int plaintextLength, int plaintextLimit) Return the maximum output size for a ciphertext given an actual input plaintext size of plaintextLength bytes and a maximum input plaintext size of plaintextLimit bytes.protected intgetCiphertextLength(int blockSize, int macSize, int maxPadding, int plaintextLength) intgetPlaintextLimit(int ciphertextLimit) Return the maximum size for the plaintext given ciphertextlimit bytes of ciphertext.protected intlowestBitSet(int x) voidvoidboolean
-
Field Details
-
cryptoParams
-
randomData
protected final byte[] randomData -
encryptThenMAC
protected final boolean encryptThenMAC -
useExplicitIV
protected final boolean useExplicitIV -
acceptExtraPadding
protected final boolean acceptExtraPadding -
useExtraPadding
protected final boolean useExtraPadding -
decryptCipher
-
encryptCipher
-
readMac
-
writeMac
-
-
Constructor Details
-
TlsBlockCipher
public TlsBlockCipher(TlsCryptoParameters cryptoParams, TlsBlockCipherImpl encryptCipher, TlsBlockCipherImpl decryptCipher, TlsHMAC clientMac, TlsHMAC serverMac, int cipherKeySize) throws IOException - Throws:
IOException
-
-
Method Details
-
getCiphertextDecodeLimit
public int getCiphertextDecodeLimit(int plaintextLimit) Description copied from interface:TlsCipherReturn the maximum input size for a ciphertext given a maximum output size for the plaintext of plaintextLimit bytes.- Specified by:
getCiphertextDecodeLimitin interfaceTlsCipher- Parameters:
plaintextLimit- the maximum output size for the plaintext.- Returns:
- the maximum input size of the ciphertext for plaintextlimit bytes of output.
-
getCiphertextEncodeLimit
public int getCiphertextEncodeLimit(int plaintextLength, int plaintextLimit) Description copied from interface:TlsCipherReturn the maximum output size for a ciphertext given an actual input plaintext size of plaintextLength bytes and a maximum input plaintext size of plaintextLimit bytes.- Specified by:
getCiphertextEncodeLimitin interfaceTlsCipher- Parameters:
plaintextLength- the actual input size for the plaintext.plaintextLimit- the maximum input size for the plaintext.- Returns:
- the maximum output size of the ciphertext for plaintextlimit bytes of input.
-
getPlaintextLimit
public int getPlaintextLimit(int ciphertextLimit) Description copied from interface:TlsCipherReturn the maximum size for the plaintext given ciphertextlimit bytes of ciphertext.- Specified by:
getPlaintextLimitin interfaceTlsCipher- Parameters:
ciphertextLimit- the maximum number of bytes of ciphertext.- Returns:
- the maximum size of the plaintext for ciphertextlimit bytes of input.
-
encodePlaintext
public TlsEncodeResult encodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, byte[] plaintext, int offset, int len) throws IOException Description copied from interface:TlsCipherEncode the passed in plaintext using the current bulk cipher.- Specified by:
encodePlaintextin interfaceTlsCipher- Parameters:
seqNo- sequence number of the message represented by plaintext.contentType- content type of the message represented by plaintext.recordVersion-ProtocolVersionused for the record.headerAllocation- extra bytes to allocate at start of returned byte array.plaintext- array holding input plaintext to the cipher.offset- offset into input array the plaintext starts at.len- length of the plaintext in the array.- Returns:
- A
TlsEncodeResultcontaining the result of encoding (after 'headerAllocation' unused bytes). - Throws:
IOException
-
decodeCiphertext
public TlsDecodeResult decodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion, byte[] ciphertext, int offset, int len) throws IOException Description copied from interface:TlsCipherDecode the passed in ciphertext using the current bulk cipher.- Specified by:
decodeCiphertextin interfaceTlsCipher- Parameters:
seqNo- sequence number of the message represented by ciphertext.recordType- content type used in the record for this message.recordVersion-ProtocolVersionused for the record.ciphertext- array holding input ciphertext to the cipher.offset- offset into input array the ciphertext starts at.len- length of the ciphertext in the array.- Returns:
- A
TlsDecodeResultcontaining the result of decoding. - Throws:
IOException
-
rekeyDecoder
- Specified by:
rekeyDecoderin interfaceTlsCipher- Throws:
IOException
-
rekeyEncoder
- Specified by:
rekeyEncoderin interfaceTlsCipher- Throws:
IOException
-
usesOpaqueRecordType
public boolean usesOpaqueRecordType()- Specified by:
usesOpaqueRecordTypein interfaceTlsCipher
-
checkPaddingConstantTime
protected int checkPaddingConstantTime(byte[] buf, int off, int len, int blockSize, int macSize) -
chooseExtraPadBlocks
protected int chooseExtraPadBlocks(int max) -
getCiphertextLength
protected int getCiphertextLength(int blockSize, int macSize, int maxPadding, int plaintextLength) -
lowestBitSet
protected int lowestBitSet(int x)
-