Class DerivationFunction
- java.lang.Object
- 
- javacardx.security.derivation.DerivationFunction
 
- 
- Direct Known Subclasses:
- DerivationFunction.OneShot
 
 public abstract class DerivationFunction extends Object TheDerivationFunctionclass is the abstract class for derivation functions. This encompasses actually both Key Derivation Function (KDF) and Pseudo Random Function (PRF). Implementations of Derivation Functions must extend this class and implement all the abstract methods.A tear or card reset event resets an initialized DerivationFunctionobject to the state it was in when previously initialized via a call toinit().Even if a transaction is in progress, update of intermediate result state in the implementation instance shall not participate in the transaction. - Since:
- 3.1
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classDerivationFunction.OneShotTheOneShotclass is a specialization of theDerivationFunctionclass intended to support efficient one-shot derivation function operations that may avoid persistent memory writes entirely.
 - 
Field SummaryFields Modifier and Type Field Description static shortALG_KDF_ANSI_X9_63Algorithm implementing the KDF Key Derivation Function defined in the standard ANSI X9.63.static shortALG_KDF_COUNTER_MODEAlgorithm implementing KDF in Counter Mode defined in NIST SP 800-108 (Recommendation for Key Derivation Using Pseudorandom Functions)static shortALG_KDF_DPI_MODEAlgorithm implementing KDF in Double Pipeline Iteration Mode defined in NIST SP 800-108 (Recommendation for Key Derivation Using Pseudorandom Functions)static shortALG_KDF_FEEDBACK_MODEAlgorithm implementing KDF in Feedback Mode defined in NIST SP 800-108 (Recommendation for Key Derivation Using Pseudorandom Functions)static shortALG_KDF_HKDFAlgorithm implementing the HKDF Key Derivation function defined in IETF RFC 5869.static shortALG_KDF_ICAO_MRTDAlgorithm implementing the KDF Key Derivation Function defined in the standard ICAO MRTD Doc 9303.static shortALG_KDF_IEEE_1363Algorithm implementing the KDF1 Key Derivation Function defined in the standard IEEE 1363-2000.static shortALG_PRF_TLS11Algorithm implementing the TLS version 1.1 Pseudo Random Function defined in IETF RFC 4346.static shortALG_PRF_TLS12Algorithm implementing the TLS version 1.2 Pseudo Random Function defined in IETF RFC 5246.
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedDerivationFunction()Protected constructor.
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract shortgetAlgorithm()Gets the Derivation Function algorithm.static DerivationFunctiongetInstance(short algorithm, boolean externalAccess)Creates aDerivationFunctionobject instance of the selected algorithm.abstract voidinit(AlgorithmParameterSpec params)Initializes theDerivationFunctionobject with the appropriate algorithm specific parameters.abstract shortlastBytes(byte[] buffer, short offset, short length)Generates derived data as specified by the derivation function algorithm and parameters.abstract shortlastBytes(SecretKey secret)Generates derived data as specified by the derivation function algorithm and parameters.abstract shortnextBytes(byte[] buffer, short offset, short length)Generates derived data as specified by the derivation function algorithm and parameters.abstract shortnextBytes(SecretKey secret)Generates derived data as specified by the derivation function algorithm and parameters.
 
- 
- 
- 
Field Detail- 
ALG_KDF_COUNTER_MODEpublic static final short ALG_KDF_COUNTER_MODE Algorithm implementing KDF in Counter Mode defined in NIST SP 800-108 (Recommendation for Key Derivation Using Pseudorandom Functions)- See Also:
- Constant Field Values
 
 - 
ALG_KDF_DPI_MODEpublic static final short ALG_KDF_DPI_MODE Algorithm implementing KDF in Double Pipeline Iteration Mode defined in NIST SP 800-108 (Recommendation for Key Derivation Using Pseudorandom Functions)- See Also:
- Constant Field Values
 
 - 
ALG_KDF_FEEDBACK_MODEpublic static final short ALG_KDF_FEEDBACK_MODE Algorithm implementing KDF in Feedback Mode defined in NIST SP 800-108 (Recommendation for Key Derivation Using Pseudorandom Functions)- See Also:
- Constant Field Values
 
 - 
ALG_PRF_TLS11public static final short ALG_PRF_TLS11 Algorithm implementing the TLS version 1.1 Pseudo Random Function defined in IETF RFC 4346.- See Also:
- Constant Field Values
 
 - 
ALG_PRF_TLS12public static final short ALG_PRF_TLS12 Algorithm implementing the TLS version 1.2 Pseudo Random Function defined in IETF RFC 5246.- See Also:
- Constant Field Values
 
 - 
ALG_KDF_IEEE_1363public static final short ALG_KDF_IEEE_1363 Algorithm implementing the KDF1 Key Derivation Function defined in the standard IEEE 1363-2000.- See Also:
- Constant Field Values
 
 - 
ALG_KDF_ICAO_MRTDpublic static final short ALG_KDF_ICAO_MRTD Algorithm implementing the KDF Key Derivation Function defined in the standard ICAO MRTD Doc 9303.- See Also:
- Constant Field Values
 
 - 
ALG_KDF_ANSI_X9_63public static final short ALG_KDF_ANSI_X9_63 Algorithm implementing the KDF Key Derivation Function defined in the standard ANSI X9.63.- See Also:
- Constant Field Values
 
 - 
ALG_KDF_HKDFpublic static final short ALG_KDF_HKDF Algorithm implementing the HKDF Key Derivation function defined in IETF RFC 5869.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getInstancepublic static DerivationFunction getInstance(short algorithm, boolean externalAccess) throws CryptoException Creates aDerivationFunctionobject instance of the selected algorithm.- Parameters:
- algorithm- the desired DerivationFunction algorithm. Valid codes listed in- ALG_*constants above, for example,- #ALG_KDF_COUNTER_MODE.
- externalAccess-- trueindicates that the instance will be shared among multiple applet instances and that the- DerivationFunctioninstance will also be accessed (via a- Shareableinterface) when the owner of the- DerivationFunctioninstance is not the currently selected applet. If- truethe implementation must not allocate CLEAR_ON_DESELECT transient space for internal data.
- Returns:
- the DerivationFunctionobject instance of the requested algorithm
- Throws:
- CryptoException- with the following reason codes:- CryptoException.NO_SUCH_ALGORITHMif the requested algorithm is not supported or shared access mode is not supported.
 
- See Also:
- getAlgorithm()
 
 - 
initpublic abstract void init(AlgorithmParameterSpec params) throws CryptoException Initializes theDerivationFunctionobject with the appropriate algorithm specific parameters.init()must be used to update theDerivationFunctionobject with new parameters. A caller may not make any assumption on theparamsobject usage by an implementation i.e either a reference is kept or not, either the fields are used or will be consumed later on. If theparamsobject is modified after invoking theinit()method, the behavior of thenextBytes()andlastBytes()methods is unspecified.The AlgorithmParameterSpecparamsinstance type is checked for consistency with theDerivationFunctionalgorithm. For instanceKDFCounterModeSpecmatches ALG_KDF_COUNTER_MODE.- Parameters:
- params- the derivation function algorithm parameters.
- Throws:
- CryptoException- with the following reason codes:- CryptoException.NO_SUCH_ALGORITHMif the algorithm parameter instance or any of the specified parameter is not supported.
 
 
 - 
getAlgorithmpublic abstract short getAlgorithm() Gets the Derivation Function algorithm.- Returns:
- the algorithm code defined above; if the algorithm is not one of
         the pre-defined algorithms, 0is returned.
- See Also:
- getInstance(short, boolean)
 
 - 
nextBytespublic abstract short nextBytes(byte[] buffer, short offset, short length) throws CryptoExceptionGenerates derived data as specified by the derivation function algorithm and parameters.The AlgorithmParameterSpecmay define a maximum data length that can be generated. If such limitation is defined, the sum oflengthfrom all calls to this method cannot exceed the maximum length and will throw an exception. TheDerivationFunctionwill then need to be reinitialized usinginit(AlgorithmParameterSpec)method.In addition to returning a shortresult, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResultclass, if supported by the platform.- Parameters:
- buffer- the output buffer
- offset- the offset into the output buffer
- length- the length of derived data to generate
- Returns:
- offset+length
- Throws:
- CryptoException- with the following reason codes:- CryptoException.INVALID_INITif at least one of the derivation function parameter has not been initialized.
- CryptoException.ILLEGAL_VALUEif it is not possible to generate the requested data due to a total generated length exceeding the maximum length defined by algorithm parameter.
 
 
 - 
nextBytespublic abstract short nextBytes(SecretKey secret) throws CryptoException Generates derived data as specified by the derivation function algorithm and parameters. The length of derived data to generate is equal to the length of the secret key passed in parameter.The AlgorithmParameterSpecmay define a maximum data length that can be generated. If such limitation is defined, the sum oflengthfrom all calls to this method cannot exceed the maximum length and will throw an exception. TheDerivationFunctionwill then need to be reinitialized usinginit(AlgorithmParameterSpec)method.In addition to returning a shortresult, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResultclass, if supported by the platform.- Parameters:
- secret- the- SecretKeyinstance which value has to be set with derived data.
- Returns:
- lengthof the key in bytes
- Throws:
- CryptoException- with the following reason codes:- CryptoException.INVALID_INITif at least one of the derivation function parameter has not been initialized.
- CryptoException.ILLEGAL_VALUEif it is not possible to generate the requested data to fully initialize the key value because generated length would exceed the maximum length defined by algorithm parameter.
 
 
 - 
lastBytespublic abstract short lastBytes(byte[] buffer, short offset, short length) throws CryptoExceptionGenerates derived data as specified by the derivation function algorithm and parameters.A call to this method also resets this DerivationFunctionobject to the state it was in when previously instantiated via a call togetInstance(short, boolean). That is, the object is reset and available to be initialized again by a call toinit(AlgorithmParameterSpec).The AlgorithmParameterSpecmay define a maximum data length that can be generated. If such limitation is defined, the sum oflengthfrom all calls to this method cannot exceed the maximum length and will throw an exception. TheDerivationFunctionwill then need to be reinitialized usinginit(AlgorithmParameterSpec)method.In addition to returning a shortresult, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResultclass, if supported by the platform.- Parameters:
- buffer- the output buffer
- offset- the offset into the output buffer
- length- the length of derived data to generate
- Returns:
- offset+length
- Throws:
- CryptoException- with the following reason codes:- CryptoException.INVALID_INITif at least one of the derivation function parameter has not been initialized.
- CryptoException.ILLEGAL_VALUEif it is not possible to generate the requested data due to a total generated length exceeding the maximum length defined by algorithm parameter.
 
 
 - 
lastBytespublic abstract short lastBytes(SecretKey secret) throws CryptoException Generates derived data as specified by the derivation function algorithm and parameters. The length of derived data to generate is equal to the length of the secret key passed in parameter.A call to this method also resets this DerivationFunctionobject to the state it was in when previously instantiated via a call togetInstance(short, boolean). That is, the object is reset and available to be initialized again by a call toinit(AlgorithmParameterSpec).The AlgorithmParameterSpecmay define a maximum data length that can be generated. If such limitation is defined, the sum oflengthfrom all calls to this method cannot exceed the maximum length and will throw an exception. TheDerivationFunctionwill then need to be reinitialized usinginit(AlgorithmParameterSpec)method.In addition to returning a shortresult, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResultclass, if supported by the platform.- Parameters:
- secret- the- SecretKeyinstance which value has to be set with derived data.
- Returns:
- lengthof the key in bytes
- Throws:
- CryptoException- with the following reason codes:- CryptoException.INVALID_INITif at least one of the derivation function parameter has not been initialized.
- CryptoException.ILLEGAL_VALUEif it is not possible to generate the requested data to fully initialize the key value because generated length would exceed the maximum length defined by algorithm parameter.
 
 
 
- 
 
-