public class BCChaCha20ParameterSpec
extends java.lang.Object
implements java.security.spec.AlgorithmParameterSpec
This is the BC equivalent of javax.crypto.spec.ChaCha20ParameterSpec, 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 int, 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 doFinal.
An AlgorithmParameters object has no way of carrying the counter, so a cipher initialised with a
non-zero counter returns null from getParameters(), as the JDK's ChaCha20 cipher does, rather
than parameters that would recreate the wrong key stream.
| Constructor and Description |
|---|
BCChaCha20ParameterSpec(byte[] nonce,
int counter)
Base constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getCounter()
Return the initial block counter.
|
byte[] |
getNonce()
Return the nonce.
|
public BCChaCha20ParameterSpec(byte[] nonce,
int counter)
nonce - the 12 byte nonce.counter - the initial block counter, an unsigned 32 bit value.java.lang.NullPointerException - if nonce is null.java.lang.IllegalArgumentException - if nonce is not 12 bytes long.