Files
oemcrypto/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_persistent_storage.h
Fred Gylys-Colwell a11741f98d Initial OPK Partner Beta v16 Release
See https://developers.google.com/widevine/drm/client/opk
for documentation and an integration guide.
2021-12-16 00:18:35 +00:00

110 lines
4.4 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_WTPI_PERSISTENT_STORAGE_INTERFACE_H_
#define OEMCRYPTO_TA_WTPI_PERSISTENT_STORAGE_INTERFACE_H_
#include "stdint.h"
#include "OEMCryptoCENC.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup persistent Persistent Storage
*
* Partners implementing a porting layer may either
* 1. Implement this wtpi_persistent_storage.h and
* wtpi_clock_interface_layer2.h, and then use the reference implementation
* clock_and_gn_layer1.c for the clock and generation interfaces. This is
* preferred if the hardware secure timer resets to 0 whenever the device is
* inactive.
* or
* 2. Implement both wtpi_clock_interface_layer1.h and
* wtpi_generation_number_interface.h. This is preferred if the system has a
* hardware secure wall clock.
*
* @{
*/
/**
* Prepare to load the stored data. If the data is loaded asynchronously,
* this should initialize that process so that the next call to
* WTPI_LoadPersistentData does not block for too long.
*
* TODO(b/160022428): define and document "too long".
*
* The values should be stored in secure persistent storage. By *persistent* we
* mean that the value should not be changed by shutting down and later
* restarting the system. By *secure* we mean that the user should not be able
* to modify the values.
*
* Returns OEMCrypto_SUCCESS on success. On failure, initialization of the TA
* will fail.
*/
OEMCryptoResult WTPI_PrepareStoredPersistentData(void);
/**
* Load the persistent data. This is called once, on first use of the clock or
* generation number. This is expected to block until a value is available. It
* is the porting interface's responsibility to fail if this blocks too long. In
* order to support data layout changes across upgrade, this function should
* return less data than requested if necessary. If the available data is less
* than |*data_length|, it should fill |data| with the available data and it
* should change |*data_length| to be the amount of available data, and it
* should return OEMCrypto_SUCCESS. If there is more data available than will
* fit in |data|, then it should return OEMCrypto_ERROR_SHORT_BUFFER.
*
* The layer above this function is responsible for handling data format changes
* and backwards compatibility across upgrades.
*
* @retval OEMCrypto_SUCCESS data was loaded.
* @retval OPK_ERROR_NO_PERSISTENT_DATA No data available.
* @retval OEMCrypto_ERROR_SHORT_BUFFER more than |data_length| data available.
*
* @param[out] data: pointer to persistent data.
* @param[in/out] data_length: on input, the size of the data buffer, on out
* the amount of data that was loaded.
*/
OEMCryptoResult WTPI_LoadPersistentData(uint8_t* data, size_t* data_length);
/**
* Save the persistent data.
*
* If the data is saved asynchronously, then it is OK for the first
* call to this function to begin a save process and then return
* OEMCrypto_SUCCESS. Subsequent calls will verify that the previous save has
* completed successfully. If the previous save resulted in an error, then this
* call will return an error. If the previous call has not completed, then this
* call should block until the previous save finishes before initializing a new
* save. If the previous call was successful, then this call will initialize a
* new save and return OEMCrypto_SUCCESS. It is the porting interface's
* responsibility to fail if this blocks too long.
*
* If the data is saved synchronously, then this function should attempt to save
* the generation number and return OEMCrypto_SUCCESS if the save was
* successful.
*
* Returns OEMCrypto_SUCCESS on success. Other return values will fail the
* current attempt to save the usage table. If a failure actually indicates that
* the previous save had failed, then the usage table will be saved with a
* generation number skew of 1. When the usage table is loaded with a generation
* skew of 1, it will result in a warning, but not a failure.
*
*
* @param[in] data: persistent data.
* @param[in] data_length: the amount of data to save.
*/
OEMCryptoResult WTPI_StorePersistentData(const uint8_t* data,
size_t data_length);
/// @}
#ifdef __cplusplus
}
#endif
#endif /* OEMCRYPTO_TA_WTPI_PERSISTENT_STORAGE_INTERFACE_H_ */