public class OCBParameters
extends java.security.AlgorithmParametersSpi
(RFC 7253) does not provide
an ASN.1 specification for OCB parameters. This implementation interprets OCB ASN.1 parameters
similarly to that used for GCM
as ASN.1 SEQUENCE of nonce
value and tag length:
OCBParameters ::= SEQUENCE { nonce OCTET STRING, -- recommended size is 12 octets tagLen OCB-TAGlen DEFAULT 16 } OCB-TAGlen ::= INTEGER (1..16)The
tagLen
component specifies the length (in number of bytes; default 16)
of the message authentication code value.
OCBParameters can be generated by calling one of the AlgorithmParameters.getInstance
methods. Subsequently, the new AlgorithmParameters object must be initialized with a proper parameter
specification (OCBParameterSpec
) or a DER encoded byte array,
e.g.:
OCBParameterSpec ocbParamSpec = ...; AlgorithmParameters params = AlgorithmParameters.getInstance("OCB", "IAIK"); params.init(ocbParamsSpec);or
byte[] encodedParams = ...; AlgorithmParameters params = AlgorithmParameters.getInstance("OCB", "IAIK"); params.init(encodedParams); OCBParameterSpec ocbParamSpec = (OCBParameterSpec)params.getParameterSpec(OCBParameterSpec.class);
OCBParameterSpec
Constructor and Description |
---|
OCBParameters()
The default constructor.
|
OCBParameters(OCBParameterSpec paramSpec)
Creates OCB Parameters from the given parameter specification.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkKeyAndNonceReuse(boolean check)
Dis/Enables check for key/nonce reuse.
|
protected byte[] |
engineGetEncoded()
Gets the parameters as DER byte array.
|
protected byte[] |
engineGetEncoded(java.lang.String format)
Returns the parameters as a DER byte array.
|
protected java.security.spec.AlgorithmParameterSpec |
engineGetParameterSpec(java.lang.Class paramSpec)
Returns a OCB Parameter Specification of this OCB Parameters object.
|
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec paramSpec)
Initializes this AlgorithmParameters object with the given parameter specification.
|
protected void |
engineInit(byte[] params)
Initializes this OCBParameters object from the given DER encoded byte array.
|
protected void |
engineInit(byte[] params,
java.lang.String format)
Inits the parameters from an DER encoded byte array.
|
protected java.lang.String |
engineToString()
Returns a formatted string describing the OCB Parameters.
|
static void |
setIncludeDefaultTagLengthInEncding(boolean include)
Decides whether the tagLen component should be
included when encoding OCB parameters if it has the default value (16).
|
public OCBParameters()
AlgorithmParameters.getInstance
for obtaining an OCBParameters object.public OCBParameters(OCBParameterSpec paramSpec)
paramSpec
- the OCBParamaterSpecpublic static void setIncludeDefaultTagLengthInEncding(boolean include)
include
- whether to include a default tagLen value (16)
when encoding OCB parameters or not (by default the
default value is not included)public static void checkKeyAndNonceReuse(boolean check)
OCB shall not be used with same key and nonce multiple times. We cannot check any
key/nonce pair that may have been used in the past, but we can check if a Cipher
has been reinitialized before used for encryption a second time.
This means we only check if Cipher.init()
has been called before
any further Cipher.update()
or Cipher.doFinal()
after
an encryption operation has been finished; we do not check if an Cipher.init()
call has actually provided a new key/nonce combination.
check
- true
to enable key/nonce reuse check (default), false
to disable itprotected byte[] engineGetEncoded() throws java.io.IOException
engineGetEncoded
in class java.security.AlgorithmParametersSpi
java.io.IOException
- if an encoding error occursprotected byte[] engineGetEncoded(java.lang.String format) throws java.io.IOException
Format is ignored. Only DER encoding is supported at this time. This method
only calls engineGetEncoded()
, regardless of what
is specified in the format
string.
engineGetEncoded
in class java.security.AlgorithmParametersSpi
format
- the encoding format; ignoredjava.io.IOException
- if an encoding error occursprotected java.security.spec.AlgorithmParameterSpec engineGetParameterSpec(java.lang.Class paramSpec) throws java.security.spec.InvalidParameterSpecException
paramSpec
identifies the specification class in which the parameters should be returned, which might be
iaik.security.cipher.OCBParameterSpec
.engineGetParameterSpec
in class java.security.AlgorithmParametersSpi
paramSpec
- the specification class in which the parameters should be returned
(iaik.security.cipher.OCBParameterSpec
)java.security.spec.InvalidParameterSpecException
- if the requested parameter specification is inappropriate
for this parameter object.protected void engineInit(java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.spec.InvalidParameterSpecException
engineInit
in class java.security.AlgorithmParametersSpi
paramSpec
- the parameter specification - must be OCBParameterSpec
.java.security.spec.InvalidParameterSpecException
- if the given parameter specification is
inappropriate for the initialization of this AlgorithmParameters object.protected void engineInit(byte[] params) throws java.io.IOException
engineInit
in class java.security.AlgorithmParametersSpi
params
- the DER encoded byte arrayjava.io.IOException
- if an error occurs when decoding the given byte array or
the derived parameter values are invalidprotected void engineInit(byte[] params, java.lang.String format) throws java.io.IOException
engineInit(params)
for initializing this OCBParameters
object from the given DER encoded byte array, regardless of what is specified
in the format
string.
engineInit
in class java.security.AlgorithmParametersSpi
params
- the DER encoded byte arrayformat
- the encoding format; ignoredjava.io.IOException
- if an error occurs when decoding the given byte arrayprotected java.lang.String engineToString()
engineToString
in class java.security.AlgorithmParametersSpi