Class JceChaCha20Poly1305

java.lang.Object
org.bouncycastle.tls.crypto.impl.jcajce.JceChaCha20Poly1305
All Implemented Interfaces:
TlsAEADCipherImpl

public class JceChaCha20Poly1305 extends Object implements TlsAEADCipherImpl
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Cipher
     
    protected SecretKey
     
    protected final int
     
    protected final JcaTlsCrypto
     
    protected final Mac
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    JceChaCha20Poly1305(JcaTlsCrypto crypto, org.bouncycastle.jcajce.util.JcaJceHelper helper, boolean isEncrypting)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    doFinal(byte[] additionalData, byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset)
    Perform the cipher encryption/decryption returning the output in output.
    int
    getOutputSize(int inputLength)
    Return the maximum size of the output for input of inputLength bytes.
    void
    init(byte[] nonce, int macSize)
    Initialise the parameters for the AEAD operator.
    protected void
    initMAC(byte[] firstBlock)
     
    protected void
    runCipher(byte[] buf)
     
    void
    setKey(byte[] key, int keyOff, int keyLen)
    Set the key to be used by the AEAD cipher implementation supporting this service.
    protected void
    updateMAC(byte[] buf, int off, int len)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • crypto

      protected final JcaTlsCrypto crypto
    • cipher

      protected final Cipher cipher
    • mac

      protected final Mac mac
    • cipherMode

      protected final int cipherMode
    • cipherKey

      protected SecretKey cipherKey
  • Constructor Details

  • Method Details

    • doFinal

      public int doFinal(byte[] additionalData, byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws IOException
      Description copied from interface: TlsAEADCipherImpl
      Perform the cipher encryption/decryption returning the output in output.

      Note: we have to use doFinal() here as it is the only way to guarantee output from the underlying cipher.

      Specified by:
      doFinal in interface TlsAEADCipherImpl
      Parameters:
      additionalData - any additional data to be included in the MAC calculation.
      input - array holding input data to the cipher.
      inputOffset - offset into input array data starts at.
      inputLength - length of the input data in the array.
      output - array to hold the cipher output.
      outputOffset - offset into output array to start saving output.
      Returns:
      the amount of data written to output.
      Throws:
      IOException - in case of failure.
    • getOutputSize

      public int getOutputSize(int inputLength)
      Description copied from interface: TlsAEADCipherImpl
      Return the maximum size of the output for input of inputLength bytes.
      Specified by:
      getOutputSize in interface TlsAEADCipherImpl
      Parameters:
      inputLength - the length (in bytes) of the proposed input.
      Returns:
      the maximum size of the output.
    • init

      public void init(byte[] nonce, int macSize) throws IOException
      Description copied from interface: TlsAEADCipherImpl
      Initialise the parameters for the AEAD operator.
      Specified by:
      init in interface TlsAEADCipherImpl
      Parameters:
      nonce - the nonce.
      macSize - MAC size in bytes.
      Throws:
      IOException - if the parameters are inappropriate.
    • setKey

      public void setKey(byte[] key, int keyOff, int keyLen) throws IOException
      Description copied from interface: TlsAEADCipherImpl
      Set the key to be used by the AEAD cipher implementation supporting this service.
      Specified by:
      setKey in interface TlsAEADCipherImpl
      Parameters:
      key - array holding the AEAD cipher key.
      keyOff - offset into the array the key starts at.
      keyLen - length of the key in the array.
      Throws:
      IOException
    • initMAC

      protected void initMAC(byte[] firstBlock) throws InvalidKeyException
      Throws:
      InvalidKeyException
    • runCipher

      protected void runCipher(byte[] buf) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • updateMAC

      protected void updateMAC(byte[] buf, int off, int len)