Files
oemcrypto/oemcrypto/opk/oemcrypto_ta/oemcrypto_key_table.h
Fred Gylys-Colwell 0a16cb2594 Version 17 plus test updates and OPK v17
This is the first public release of OPK v17.
See the file CHANGELOG.md for details.
2022-04-13 19:36:27 -07:00

49 lines
2.3 KiB
C

/* Copyright 2019 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_OEMCRYPTO_KEY_TABLE_H_
#define OEMCRYPTO_TA_OEMCRYPTO_KEY_TABLE_H_
#include "oemcrypto_key.h"
#include "wtpi_config_interface.h"
/* Initializes the key table so the session can grab keys at a late point. */
void OPKI_InitializeKeyTable(void);
/* Gets the max number of keys. */
uint32_t OPKI_MaxNumberOfKeys(void);
/* Gets the number of currently used keys. Returns
OEMCrypto_ERROR_SYSTEM_INVALIDATED if the key table has not been initialized
and OEMCrypto_SUCCESS otherwise.
Caller retains ownership of |num_used_keys| and it must not be NULL. */
OEMCryptoResult OPKI_NumberOfUsedKeys(uint32_t* num_used_keys);
/* Grabs, gets, and initializes a SymmetricKey to an empty key handle.
If |key| points to an existing key, this method tries to free it before
continuing. If there is an error in generating the new key, this method will
free it before returning and set *|key| to NULL.
If successful, caller gains ownership of *|key| and it must not be NULL. */
OEMCryptoResult OPKI_CreateKey(SymmetricKey** key, SymmetricKeyType key_type,
KeySize key_size);
/* Given a pointer to a SymmetricKey*, attempts to free the SymmetricKey it
points to if it exists, and then sets the pointer to the SymmetricKey to
NULL. Returns OEMCrypto_ERROR_SYSTEM_INVALIDATED if the key table has not
been initialized, OEMCrypto_ERROR_INVALID_CONTEXT if the non-null
SymmetricKey has not been grabbed or if its index is invalid. Returns the
result of freeing the SymmetricKey otherwise. If there is an existing error
in the caller, in which case this is likely used for cleanup, that error will
be returned and the result of this shall be ignored. Caller retains ownership
of *|key| but **|key| will be destroyed if *|key| is not NULL. */
OEMCryptoResult OPKI_FreeKeyFromTable(SymmetricKey** key);
/* Clears and cleans up the key table. The key table must be reinitialized to be
used. Returns OEMCrypto_ERROR_TERMINATE_FAILED if the table has not been
initialized or if there are any active keys still. Returns OEMCrypto_SUCCESS
otherwise. */
OEMCryptoResult OPKI_TerminateKeyTable(void);
#endif /* OEMCRYPTO_TA_OEMCRYPTO_KEY_TABLE_H_ */