See https://developers.google.com/widevine/drm/client/opk for documentation and an integration guide. See CHANGELOG.md for details about recent changes.
92 lines
3.5 KiB
C
92 lines
3.5 KiB
C
/* Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
|
|
source code may only be used and distributed under the Widevine
|
|
License Agreement. */
|
|
|
|
#ifndef OEMCRYPTO_TA_KEY_MAPPING_INTERFACE_H_
|
|
#define OEMCRYPTO_TA_KEY_MAPPING_INTERFACE_H_
|
|
|
|
#include "wtpi_crypto_and_key_management_interface_layer1.h"
|
|
#include "wtpi_crypto_and_key_management_interface_layer2.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include "oemcrypto_key_types.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* This header file defines the interfaces for pairing/unpairing a
|
|
* WTPI_K1_SymmetricKey_Handle defined in Crypto and Key Management layer 1,
|
|
* with a WTPI_K2_SymmetricKey_Handle defined in Crypto and Key Management layer
|
|
* 2. This is used by both the REFERENCE implementation of hardware-backed
|
|
* Crypto and Key Management layer 1(wtpi_crypto_and_key_management_layer1_hw.c)
|
|
* and the TEST implementation of hardware-backed Crypto and Key Management
|
|
* layer 2(wtpi_crypto_and_key_management_layer2_hw.c).
|
|
*
|
|
* Partners using the reference implementation
|
|
* wtpi_crypto_and_key_management_layer1_hw.c and implementing their own
|
|
* wtpi_crypto_and_key_management_interface_layer2.h may need to implement this
|
|
* interface as well.
|
|
*/
|
|
|
|
/**
|
|
* Given a layer 1 key handle, looks up for the layer 2 key handle which is
|
|
* paired with this layer 1 key handle. Returns NULL if the key has not been
|
|
* loaded into the layer 2 key table. If this is the case and |reload_required|
|
|
* is true, it loads the key to layer 2 key table and returns the layer 2 handle
|
|
* of the loaded key.
|
|
* Also returns NULL if there is any error during look-up.
|
|
*/
|
|
WTPI_K2_SymmetricKey_Handle KM_LookupKeyHandle(
|
|
WTPI_K1_SymmetricKey_Handle k1_key_handle, bool reload_required);
|
|
|
|
/**
|
|
* Pairs a layer 1 key handle with a layer 2 key handle. Both handles eventually
|
|
* point to the same key. This allows a layer 1 function with a layer 1 key
|
|
* handle to retrieve the corresponding layer 2 key handle and then make a call
|
|
* to the layer 2 interface.
|
|
* Returns OEMCrypto_ERROR_INVALID_CONTEXT if any of the key handles is invalid,
|
|
* and OEMCrypto_SUCCESS otherwise.
|
|
*/
|
|
OEMCryptoResult KM_PairKeyHandle(WTPI_K1_SymmetricKey_Handle k1_key_handle,
|
|
WTPI_K2_SymmetricKey_Handle k2_key_handle);
|
|
|
|
/**
|
|
* Evicts a layer 2 key in slot |k2_index|. It is also responsible for unpairing
|
|
* the handles and releasing layer 2 key handles after eviction.
|
|
* Returns OEMCrypto_ERROR_INVALID_CONTEXT if |k2_index| is invalid,
|
|
* OEMCrypto_ERROR_INSUFFICIENT_RESOURCES if no key can be evicted, and
|
|
* OEMCrypto_SUCCESS otherwise.
|
|
*/
|
|
OEMCryptoResult KM_EvictLayer2KeyByIndex(uint32_t k2_index);
|
|
|
|
/**
|
|
* Sets the key eviction handler. The handler takes a key slot to be evicted and
|
|
* returns OEMCryptoResult.
|
|
*/
|
|
void KM_SetLayer2KeyEvictionCallback(OEMCryptoResult (*callback)(uint32_t));
|
|
|
|
/**
|
|
* Returns true if |k2_index| it a valid key slot. Otherwise returns false.
|
|
*/
|
|
bool KM_IsLayer2KeyIndexValid(uint32_t k2_index);
|
|
|
|
/**
|
|
* Gets the key slot from |key_handle|, and places it in |k2_index|.
|
|
* Returns OEMCrypto_ERROR_INVALID_CONTEXT if any of the pointers are NULL or
|
|
* |key_handle| is invalid, and OEMCrypto_SUCCESS otherwise.
|
|
* Caller retains ownership of all pointers.
|
|
*/
|
|
OEMCryptoResult KM_GetLayer2KeyIndex(WTPI_K2_SymmetricKey_Handle key_handle,
|
|
uint32_t* k2_index);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* OEMCRYPTO_TA_KEY_MAPPING_INTERFACE_H_ */
|