public class ESDHKEKParameters
extends java.security.AlgorithmParametersSpi
This class represents parameters (OtherInfo structure) for the ephemaral static Diffie Hellman key material creation algorithm as described in RFC 2631.
RFC 2631 gives a special variant of the Diffie Hellman algorithm, based on the ANSI X9.42 draft. From the shared secret value ZZ shared keying material -- typically used as key encryption key (KEK) for encrypting (wrapping) a content encryption key (CEK) -- is created by repeatedly calculating the SHA-1 hash of ZZ and additional other information:
KM = H ( ZZ || OtherInfo)where
OtherInfo is specified as:
OtherInfo ::= SEQUENCE {
keyInfo KeySpecificInfo,
partyAInfo [0] OCTET STRING OPTIONAL,
suppPubInfo [2] OCTET STRING }
KeySpecificInfo ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
counter OCTET STRING SIZE (4..4) }
KeySpecificInfo specifies the CEK wrapping algorithm with which
this KEK will be used and a counter (32 bit number, represented in network
byte order, initial value is 1 for any ZZ) that is incremented by one every
time the above key generation function is run for a given KEK.
partyAInfo is a random string provided by the sender, especially
required in static-static mode (where the sender has a static key pair with the
public key placed in a certificate).
suppPubInfo id the length of the generated KEK , in bits, represented
as a 32 bit number in network byte order. E.g. for DESede it would be
the byte sequence 00 00 00 C0.
For generating a KEK, the KM above (SHA-1 hash of ZZ || OtherInfo) is calcualted as often as necessary to give the required keying material by concatenating the KM blocks resulting from the several steps. In each step the counter is incremented by 1. For DESede, e.g., which requires 192 bits of keying material, the algorithm must be run twice, once with a counter value of 1 (to generate K1', K2', and the first 32 bits of K3') and once with a counter value of 2 (to generate the last 32 bits of K3). K1',K2' and K3' are then parity adjusted to generate the 3 DES keys K1,K2 and K3. For RC2-128, which requires 128 bits of keying material, the algorithm is run once, with a counter value of 1, and the left-most 128 bits are directly converted to an RC2 key. Similarly, for RC2-40, which requires 40 bits of keying material, the algorithm is run once, with a counter value of 1, and the leftmost 40 bits are used as the key.
Please note that the parameters represented by this class are different from
the Diffie Hellman parameters (p,g,l) represeneted by class DHParameters (see ESDHKEKParameterSpec ESDHKEKParameterSpec} for more information).
This class can be used for converting ESDH OtherInfo parameters from its
encoding and its specification (represented by ESDHKEKParameterSpec ESDHKEKParameterSpec}), e.g.:
// OtherInfo for TripleDES key wrap
AlgorithmID tripleDesWrap = AlgorithmID.cms_3DES_wrap;
// key length of KEK:
int keyLength = 192;
// generate the OtherInfo
ESDHKEKParameterSpec otherInfo = new ESDHKEKParameterSpec(tripleDesWrap.getAlgorithm(), keyLength);
// perhaps some random partyAInfo from the sender:
otherInfo.setPartyAInfo(partyAInfo);
// now prepare for encoding (convert into ESDHKEKParameters):
esdhKEKParams = AlgorithmParameters.getInstance("ESDHKEK");
esdhKEKParams.init(otherInfo);
byte[] encodedParams = esdhKEKParams.getEncoded();
// convert back into specification:
esdhKEKParams.init(encodedParams);
esdhKEK = (ESDHKEKParameterSpec)esdhKEKParams.getParameterSpec(ESDHKEKParameterSpec.class);
ESDHKEKParameterSpec| Constructor and Description |
|---|
ESDHKEKParameters()
The default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected byte[] |
engineGetEncoded()
Returns the parameters as DER byte array.
|
protected byte[] |
engineGetEncoded(java.lang.String format)
Returns the parameters as DER byte array.
|
protected java.security.spec.AlgorithmParameterSpec |
engineGetParameterSpec(java.lang.Class paramSpec)
Returns the ESDH KEK parameters as transparent ESDH KEK parameter specification
of the given class type.
|
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec paramSpec)
Initializes this ESDHKEKParameters with the given ESDHKEKParameterSpec.
|
protected void |
engineInit(byte[] params)
Initializes this ESDHKEKParameters object from the given DER encoded byte array.
|
protected void |
engineInit(byte[] params,
java.lang.String format)
Inits the parameters from a DER encoded byte array.
|
protected java.lang.String |
engineToString()
Returns a String representation of the parameters.
|
void |
incrementCounter()
Increments the counter by 1.
|
void |
resetCounter()
Resets counter to its initial value 00 00 00 01.
|
public ESDHKEKParameters()
ESDHKEKParameters object.
Applications shall use
AlgorithmParameters.getInstance("ESDHKEK");
for obtaining ESDHKEKParameters.protected byte[] engineGetEncoded()
throws java.io.IOException
This method returns the OtherInfo structure in DER encoded format.
OtherInfo ::= SEQUENCE {
keyInfo KeySpecificInfo,
partyAInfo [0] OCTET STRING OPTIONAL,
suppPubInfo [2] OCTET STRING }
KeySpecificInfo ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
counter OCTET STRING SIZE (4..4) }
engineGetEncoded in class java.security.AlgorithmParametersSpijava.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.
Only calls engineGetEncoded()
for returning the ESDH KEK paramters as DER encoded byte array,
regardless of what is specified in the format string.
engineGetEncoded in class java.security.AlgorithmParametersSpiformat - 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
engineGetParameterSpec in class java.security.AlgorithmParametersSpiparamSpec - the desired parameter specification classjava.security.spec.InvalidParameterSpecException - if the paramters cannot be
converted to the desired parameter specificationESDHKEKParameterSpecprotected void engineInit(java.security.spec.AlgorithmParameterSpec paramSpec)
throws java.security.spec.InvalidParameterSpecException
engineInit in class java.security.AlgorithmParametersSpiparamSpec - the parameter specification, which has to be a ESDHKEKParameterSpecjava.security.spec.InvalidParameterSpecException - if the given parameter specification is
not a ESDHKEKParameterSpecprotected void engineInit(byte[] params)
throws java.io.IOException
engineInit in class java.security.AlgorithmParametersSpiparams - the DER encoded byte arrayjava.io.IOException - if an error occurs when decoding the given byte arrayprotected void engineInit(byte[] params,
java.lang.String format)
throws java.io.IOException
Only calls engineInit(params) for initializing this
ESDHKEKParamters object from the given DER encoded byte array, regardless
of what is specified in the format string.
engineInit in class java.security.AlgorithmParametersSpiparams - the DER encoded byte arrayformat - the encoding format; ignoredjava.io.IOException - if an error occurs when decoding the given byte arraypublic void resetCounter()
public void incrementCounter()
protected java.lang.String engineToString()
engineToString in class java.security.AlgorithmParametersSpi