Bouncy Castle Cryptography Library 1.87

org.bouncycastle.jcajce.spec
Class BCChaCha20ParameterSpec

java.lang.Object
  extended byorg.bouncycastle.jcajce.spec.BCChaCha20ParameterSpec
All Implemented Interfaces:
java.security.spec.AlgorithmParameterSpec

public class BCChaCha20ParameterSpec
extends java.lang.Object
implements java.security.spec.AlgorithmParameterSpec

Parameters for the RFC 8439 (formerly RFC 7539) form of the ChaCha20 stream cipher - "ChaCha7539", also registered as "ChaCha20", in the BC provider: a 12 byte nonce and the initial value of the 32 bit block counter.

This is the BC equivalent of , which only exists from Java 11, and carries the same values with the same meaning; the BC provider accepts either. Starting the cipher at a given block is what, for example, the record number protection of DTLS 1.3 (RFC 9147 sec. 4.2.3) and the header protection of QUIC (RFC 9001 sec. 5.4.4) require.

The counter is an unsigned 32 bit value carried in an , so a negative counter addresses one of the blocks from 2^31 to 2^32 - 1. The cipher returns to this block, not block 0, after each .

An object has no way of carrying the counter, so a cipher initialised with a non-zero counter returns from , as the JDK's ChaCha20 cipher does, rather than parameters that would recreate the wrong key stream.


Constructor Summary
BCChaCha20ParameterSpec(byte[] nonce, int counter)
          Base constructor.
 
Method Summary
 int getCounter()
          Return the initial block counter.
 byte[] getNonce()
          Return the nonce.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BCChaCha20ParameterSpec

public BCChaCha20ParameterSpec(byte[] nonce,
                               int counter)
Base constructor.

Parameters:
nonce - the 12 byte nonce.
counter - the initial block counter, an unsigned 32 bit value.
Throws:
java.lang.NullPointerException - if nonce is null.
java.lang.IllegalArgumentException - if nonce is not 12 bytes long.
Method Detail

getNonce

public byte[] getNonce()
Return the nonce.

Returns:
a copy of the 12 byte nonce.

getCounter

public int getCounter()
Return the initial block counter.

Returns:
the initial block counter, an unsigned 32 bit value.

Bouncy Castle Cryptography Library 1.87