Files
oemcrypto/oemcrypto/opk/oemcrypto_ta/oemcrypto_key.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

87 lines
3.7 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_H_
#define OEMCRYPTO_TA_OEMCRYPTO_KEY_H_
#include "oemcrypto_key_control_block.h"
#include "oemcrypto_key_types.h"
#include "wtpi_config_macros.h"
#include "wtpi_crypto_and_key_management_interface_layer1.h"
#include "wtpi_crypto_asymmetric_interface.h"
typedef struct SymmetricKey {
SymmetricKeyType key_type;
/* key_handle is owned by the TEE. */
WTPI_K1_SymmetricKey_Handle key_handle;
KeySize key_size;
/* For entitlement or content keys only. */
uint8_t key_id[KEY_ID_MAX_SIZE];
uint8_t key_id_size;
KeyControlBlock key_control_block;
/* Index into either the content or entitlement key table in the oemcrypto
* session, or the entitled content key table in the entitled key session. */
uint32_t session_key_index;
bool is_entitled_content_key;
OEMCryptoCipherMode cipher_mode;
} SymmetricKey;
typedef struct AsymmetricKey {
AsymmetricKeyType key_type;
uint8_t wrapped_key[MAX_WRAPPED_ASYMMETRIC_KEY_SIZE];
size_t wrapped_key_length;
uint32_t ref_count;
/* This is the actual size of the asymmetric key in bytes when being loaded.
It is a shortcut to getting the key size without unwrapping the key first.
It is useful in cases where only the key size is needed but not the key
content. */
size_t key_size;
uint32_t allowed_schemes;
} AsymmetricKey;
/* Initializes the data fields in the |key| and sets |key|'s key_handle to
an empty handle.
Returns the result of WTPI_CreateKeyHandle if it fails and OEMCrypto_SUCCESS
otherwise.
|serialized_bytes_length| must be > 0 and |key_type| must be valid.
Caller retains ownership of all pointers and they must not be NULL. */
OEMCryptoResult OPKI_InitializeSymmetricKey(SymmetricKey* key,
SymmetricKeyType key_type,
KeySize key_size);
/* Initializes the data fields in the |key|.
Caller retains ownership of all pointers and they must not be NULL. */
OEMCryptoResult OPKI_InitializeAsymmetricKey(
AsymmetricKey* key, AsymmetricKeyType key_type, const uint8_t* wrapped_key,
size_t wrapped_key_length, size_t key_size, uint32_t allowed_schemes);
/* Frees the key handle associated with this key if it exists and then clears
the key. Returns the result of freeing the key handle.
Caller retains ownership of |key| and it must not be NULL. */
OEMCryptoResult OPKI_FreeSymmetricKey(SymmetricKey* key);
/* Clears the asymmetric *|key|.
Caller retains ownership of |key| and it must not be NULL. */
OEMCryptoResult OPKI_FreeAsymmetricKey(AsymmetricKey* key);
/* Checks to make sure that |key| isn't NULL, its key_type matches |key_type|.
*/
bool OPKI_CheckKey(SymmetricKey* key, SymmetricKeyType key_type);
/* Converts the OEMCrypto API OEMCrypto_PrivateKeyType value to the equivalent
OPK API AsymmetricKeyType value.
Returns true if the value was converted successfully, false otherwise.
Caller retains ownership of |asym_key_type| and it must not be NULL. */
bool OPKI_PrivateKeyTypeToAsymmetricKey(OEMCrypto_PrivateKeyType priv_key_type,
AsymmetricKeyType* asym_key_type);
/* Converts the OPK API AsymmetricKeyType value to the equivalent OEMCrypto API
OEMCrypto_PrivateKeyType value.
Returns true if the value was converted successfully, false otherwise. Caller
retains ownership of |priv_key_type| and it must not be NULL. */
bool OPKI_AsymmetricKeyToPrivateKeyType(
AsymmetricKeyType asym_key_type, OEMCrypto_PrivateKeyType* priv_key_type);
#endif /* OEMCRYPTO_TA_OEMCRYPTO_KEY_H_ */