Add utility for generating KDF contexts

Starting in v19, OEMCrypto implementers will need to implement KDF generation in OEMCrypto.  To make it easier, this adds a utility to generate them based on the request context.

PiperOrigin-RevId: 572693987
Change-Id: Ife382bf35ceede508499e3677de115ef12999dcc
This commit is contained in:
Jacob Trimble
2023-10-11 14:50:09 -07:00
committed by Robert Shih
parent e85a6b9616
commit 078e1f6555
4 changed files with 272 additions and 1 deletions

View File

@@ -55,6 +55,9 @@
*
* @defgroup common_types Common Types
* Enumerations and structures that are used by several OEMCrypto and ODK
*
* @defgroup odk_derivation Key Derivation Utils
* Utilities and constants relating to key derivation.
* functions.
*********************************************************************/
@@ -784,6 +787,83 @@ bool CheckApiVersionAtMost(const ODK_NonceValues* nonce_values,
/// @}
/// @addtogroup odk_derivation
/// @{
/**
* Contains the key label for the Mac key derivation. This contains
* |ODK_MacKeyLabelWithZeroLength| number of bytes.
*/
extern const uint8_t ODK_MacKeyLabelWithZero[];
/** Contains the number of bytes in |ODK_MacKeyLabelWithZero|. */
extern const size_t ODK_MacKeyLabelWithZeroLength;
/**
* Contains the key label for the Encryption key derivation. This contains
* |ODK_EncKeyLabelWithZeroLength| number of bytes.
*/
extern const uint8_t ODK_EncKeyLabelWithZero[];
/** Contains the number of bytes in |ODK_EncKeyLabelWithZero|. */
extern const size_t ODK_EncKeyLabelWithZeroLength;
/**
* Contains the suffix bytes (NIST 800-108 key length) for Mac key derivation.
* This value is appended after the context string. This contains
* ODK_MacKeySuffixLength number of bytes.
*/
extern const uint8_t ODK_MacKeySuffix[];
/** Contains the number of bytes in |ODK_MacKeySuffix|. */
extern const size_t ODK_MacKeySuffixLength;
/**
* Contains the suffix bytes (NIST 800-108 key length) for Encryption key
* derivation. This value is appended after the context string. This contains
* ODK_EncKeySuffixLength number of bytes.
*/
extern const uint8_t ODK_EncKeySuffix[];
/** Contains the number of bytes in |ODK_EncKeySuffix|. */
extern const size_t ODK_EncKeySuffixLength;
/**
* Generates the key-derivation contexts for the license exchange based on the
* given context value.
*
* NOTE: if the mac_key_context/enc_key_context pointer are null and/or input
* mac_key_context_length/enc_key_context_length is zero, this function returns
* OEMCrypto_ERROR_SHORT_BUFFER and sets output
* mac_key_context_length/enc_key_context_length to the size needed.
*
* @param[in] context: pointer to the context buffer.
* @param[in] context_length: the length of the context buffer.
* @param[out] mac_key_context: an output buffer to contain the MAC key context.
* @param[in,out] mac_key_context_length: on input, contains the number of bytes
* in |mac_key_context|; on return, will contain the context length.
* @param[out] enc_key_context: an output buffer to contain the encryption key
* context.
* @param[in,out] enc_key_context_length: on input, contains the number of bytes
* in |enc_key_context|; on return, will contain the context length.
*
* @retval OEMCrypto_SUCCESS
* @retval OEMCrypto_ERROR_SHORT_BUFFER: mac_key_context_length or
* enc_key_context_length is too small
* @retval OEMCrypto_ERROR_INVALID_CONTEXT
*
* @version
* This method is new in version 19 of the API.
*/
OEMCryptoResult ODK_GenerateKeyContexts(const uint8_t* context,
size_t context_length,
uint8_t* mac_key_context,
size_t* mac_key_context_length,
uint8_t* enc_key_context,
size_t* enc_key_context_length);
/// @}
#ifdef __cplusplus
}
#endif

View File

@@ -19,7 +19,7 @@ extern "C" {
#define ODK_MINOR_VERSION 0
/* ODK Version string. Date changed automatically on each release. */
#define ODK_RELEASE_DATE "ODK v19.0 2023-10-09"
#define ODK_RELEASE_DATE "ODK v19.0 2023-10-11"
/* The lowest version number for an ODK message. */
#define ODK_FIRST_VERSION 16