diff --git a/libwvdrmengine/oemcrypto/include/OEMCryptoCENC.h b/libwvdrmengine/oemcrypto/include/OEMCryptoCENC.h index f08a1b24..6eee9120 100644 --- a/libwvdrmengine/oemcrypto/include/OEMCryptoCENC.h +++ b/libwvdrmengine/oemcrypto/include/OEMCryptoCENC.h @@ -523,7 +523,7 @@ const uint32_t OEMCrypto_Partner_Defined_Hash = 2; #define OEMCrypto_LoadEntitledContentKeys _oecc92 /* - * OEMCrypto_SetSandbox + * OEMCrypto_SetSandbox * * Description: * This tells OEMCrypto which sandbox the current process belongs to. Any @@ -725,6 +725,71 @@ OEMCryptoResult OEMCrypto_GenerateDerivedKeys(OEMCrypto_SESSION session, const uint8_t* enc_key_context, uint32_t enc_key_context_length); +/* + * OEMCrypto_DeriveKeysFromSessionKey + * + * Description: + * Generates three secondary keys -- mac_key_server, mac_key_client, and + * encrypt_key -- for handling signing and content key decryption under the + * license server protocol for AES CTR mode. + * + * This function is similar to OEMCrypto_GenerateDerivedKeys, except that it + * uses a session key to generate the secondary keys instead of the Widevine + * Keybox device key. These two keys will be stored in secure memory until + * the next call to LoadKeys. The session key is passed in encrypted by the + * device RSA public key, and must be decrypted with the RSA private key + * before use. Once the enc_key and mac_keys have been generated, all calls + * to LoadKeys and RefreshKeys proceed in the same manner for license + * requests using RSA or using a Widevine keybox token. + * + * Verification: + * If the RSA key’s allowed_schemes is not kSign_RSASSA_PSS, then no keys are + * derived and the error OEMCrypto_ERROR_INVALID_RSA_KEY is returned. An RSA + * key cannot be used for both deriving session keys and also for PKCS1 + * signatures. + * + * Parameters: + * session (in) - crypto session identifier. + * enc_session_key (in) - session key, encrypted with the device RSA + * - key (from the device certifcate) using + * - RSA-OAEP. + * enc_session_key_length (in) - length of session_key, in bytes. + * mac_key_context (in) - pointer to memory containing context data for + * - computing the HMAC generation key. + * mac_key_context_length (in) - length of the HMAC key context data, in + * - bytes. + * enc_key_context (in) - pointer to memory containing context data for + * - computing the encryption key. + * enc_key_context_length (in) - length of the encryption key context data, in + * - bytes. + * + * Threading: + * This function may be called simultaneously with functions on other + * sessions, but not with other functions on this session. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_DEVICE_NOT_RSA_PROVISIONED + * OEMCrypto_ERROR_INVALID_SESSION + * OEMCrypto_ERROR_INVALID_CONTEXT + * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * + * Buffer Sizes + * OEMCrypto shall support message sizes of at least 8 KiB. + * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is + * larger than the supported size. + * + * Version: + * This method changed in API version 9. + */ +OEMCryptoResult OEMCrypto_DeriveKeysFromSessionKey( + OEMCrypto_SESSION session, const uint8_t* enc_session_key, + size_t enc_session_key_length, const uint8_t* mac_key_context, + size_t mac_key_context_length, const uint8_t* enc_key_context, + size_t enc_key_context_length); + /* * OEMCrypto_GenerateNonce * @@ -819,6 +884,39 @@ OEMCryptoResult OEMCrypto_GenerateSignature(OEMCrypto_SESSION session, uint8_t* signature, size_t* signature_length); +/* + * OEMCrypto_LoadSRM + * + * Description: + * Verify and install a new SRM file. The device shall install the new file + * only if verification passes. If verification fails, the existing SRM will + * be left in place. Verification is defined by DCP, and includes + * verification of the SRM’s signature and verification that the SRM version + * number will not be decreased. See the section HDCP SRM Update above for + * more details about the SRM. This function is for devices that support HDCP + * v2.2 or higher and wish to receive 4k content. + * + * Parameters: + * bufer (in): buffer containing the SRM + * buffer_length (in): length of the SRM, in bytes. + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * OEMCrypto_SUCCESS - if the file was valid and was installed. + * OEMCrypto_ERROR_INVALID_CONTEXT - if the SRM version is too low, or the + * file is corrupted. + * OEMCrypto_ERROR_SIGNATURE_FAILURE - If the signature is invalid. + * OEMCrypto_ERROR_BUFFER_TOO_LARGE - if the buffer is too large for the device. + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * + * Version: + * This method is new in API version 13. + */ +OEMCryptoResult OEMCrypto_LoadSRM(const uint8_t* buffer, + size_t buffer_length); + /* * OEMCrypto_LoadKeys * @@ -1637,6 +1735,255 @@ OEMCryptoResult OEMCrypto_CopyBuffer(const uint8_t* data_addr, OEMCrypto_DestBufferDesc* out_buffer, uint8_t subsample_flags); +/* + * OEMCrypto_Generic_Encrypt + * + * Description: + * This function encrypts a generic buffer of data using the current key. + * + * If the session has an entry in the Usage Table, then OEMCrypto will update + * the time_of_last_decrypt. If the status of the entry is "unused", then + * change the status to "active" and set the time_of_first_decrypt. + * + * Verification: + * The following checks should be performed. If any check fails, an error is + * returned, and the data is not encrypted. + * 1. The control bit for the current key shall have the Allow_Encrypt + * set. If not, return OEMCrypto_ERROR_UNKNOWN_FAILURE. + * 2. If the current key’s control block has a nonzero Duration field, then + * the API shall verify that the duration is greater than the session’s + * elapsed time clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. + * 3. If the current session has an entry in the Usage Table, and the status + * of that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. + * + * Parameters: + * session (in) - crypto session identifier. + * in_buffer (in) - pointer to memory containing data to be encrypted. + * buffer_length (in) - length of the buffer, in bytes. + * iv (in) - IV for encrypting data. Size is specified by the algorithm. + * algorithm (in) - Specifies which encryption algorithm to use. See + * OEMCrypto_Algorithm for valid values. + * out_buffer (out) - pointer to buffer in which encrypted data should be + * stored. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_KEY_EXPIRED + * OEMCrypto_ERROR_NO_DEVICE_KEY + * OEMCrypto_ERROR_INVALID_SESSION + * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * + * Buffer Sizes + * OEMCrypto shall support buffer sizes of at least 100 KiB for generic + * crypto operations. + * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is + * larger than the supported size. + * + * Threading: + * This function may be called simultaneously with functions on other sessions, + * but not with other functions on this session. + * + * Version: + * This method changed in API version 9. + */ +OEMCryptoResult OEMCrypto_Generic_Encrypt( + OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length, + const uint8_t* iv, OEMCrypto_Algorithm algorithm, uint8_t* out_buffer); + +/* + * OEMCrypto_Generic_Decrypt + * + * Description: + * This function decrypts a generic buffer of data using the current key. + * + * If the session has an entry in the Usage Table, then OEMCrypto will update + * the time_of_last_decrypt. If the status of the entry is "unused", then + * change the status to "active" and set the time_of_first_decrypt. + * + * Verification: + * The following checks should be performed. If any check fails, an error is + * returned, and the data is not decrypted. + * 1. The control bit for the current key shall have the Allow_Decrypt set. If + * not, return OEMCrypto_ERROR_DECRYPT_FAILED. + * 2. If the current key’s control block has the Data_Path_Type bit set, then + * return OEMCrypto_ERROR_DECRYPT_FAILED. + * 3. If the current key’s control block has a nonzero Duration field, then + * the API shall verify that the duration is greater than the session’s + * elapsed time + * clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. + * 4. If the current session has an entry in the Usage Table, and the status + * of that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. + * + * Parameters: + * session (in) - crypto session identifier. + * in_buffer (in) - pointer to memory containing data to be encrypted. + * buffer_length (in) - length of the buffer, in bytes. The algorithm may + * restrict buffer_length to be a multiple of block size. + * iv (in) - IV for encrypting data. Size is 128 bits. + * algorithm (in) - Specifies which encryption algorithm to use. + * out_buffer (out) - pointer to buffer in which decrypted data should be + * stored. + * + * Threading: + * This function may be called simultaneously with functions on other + * sessions, but not with other functions on this session. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_KEY_EXPIRED + * OEMCrypto_ERROR_DECRYPT_FAILED + * OEMCrypto_ERROR_NO_DEVICE_KEY + * OEMCrypto_ERROR_INVALID_SESSION + * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * + * Buffer Sizes + * OEMCrypto shall support buffer sizes of at least 100 KiB for generic + * crypto operations. + * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is + * larger than the supported size. + * + * Version: + * This method changed in API version 9. + */ +OEMCryptoResult OEMCrypto_Generic_Decrypt( + OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length, + const uint8_t* iv, OEMCrypto_Algorithm algorithm, uint8_t* out_buffer); + +/* + * OEMCrypto_Generic_Sign + * + * Description: + * This function signs a generic buffer of data using the current key. + * + * If the session has an entry in the Usage Table, then OEMCrypto will update + * the time_of_last_decrypt. If the status of the entry is "unused", then + * change the status to "active" and set the time_of_first_decrypt. + * + * Verification: + * The following checks should be performed. If any check fails, an error is + * returned, and the data is not signed. + * 1. The control bit for the current key shall have the Allow_Sign set. + * 2. If the current key’s control block has a nonzero Duration field, then + * the API shall verify that the duration is greater than the session’s + * elapsed time clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. + * 3. If the current session has an entry in the Usage Table, and the status of + * that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. + * + * Parameters: + * session (in) - crypto session identifier. + * in_buffer (in) - pointer to memory containing data to be encrypted. + * buffer_length (in) - length of the buffer, in bytes. + * algorithm (in) - Specifies which algorithm to use. + * signature (out) - pointer to buffer in which signature should be + * stored. May be null on the first call in order to find required buffer + * size. + * signature_length (in/out) - (in) length of the signature buffer, in bytes. + * (out) actual length of the signature + * + * + * + * Threading: + * This function may be called simultaneously with functions on other + * sessions, but not with other functions on this session. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_KEY_EXPIRED + * OEMCrypto_ERROR_SHORT_BUFFER if signature buffer is not large enough to + * hold the output signature. + * OEMCrypto_ERROR_NO_DEVICE_KEY + * OEMCrypto_ERROR_INVALID_SESSION + * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * + * Buffer Sizes + * OEMCrypto shall support buffer sizes of at least 100 KiB for generic + * crypto operations. + * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is + * larger than the supported size. + * + * Version: + * This method changed in API version 9. + */ +OEMCryptoResult OEMCrypto_Generic_Sign(OEMCrypto_SESSION session, + const uint8_t* in_buffer, + size_t buffer_length, + OEMCrypto_Algorithm algorithm, + uint8_t* signature, + size_t* signature_length); + +/* + * OEMCrypto_Generic_Verify + * + * Description: + * This function verifies the signature of a generic buffer of data using the + * current key. + * + * If the session has an entry in the Usage Table, then OEMCrypto will update + * the time_of_last_decrypt. If the status of the entry is "unused", then + * change the status to "active" and set the time_of_first_decrypt. + * + * Verification: + * The following checks should be performed. If any check fails, an error is + * returned. + * 1. The control bit for the current key shall have the Allow_Verify set. + * 2. The signature of the message shall be computed, and the API shall verify + * the computed signature matches the signature passed in. If not, return + * OEMCrypto_ERROR_SIGNATURE_FAILURE. + * 3. The signature verification shall use a constant-time algorithm (a + * signature mismatch will always take the same time as a successful + * comparison). + * 4. If the current key’s control block has a nonzero Duration field, then + * the API shall verify that the duration is greater than the session’s + * elapsed time clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. + * 5. If the current session has an entry in the Usage Table, and the status + * of that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. + * + * Parameters: + * session (in) - crypto session identifier. + * in_buffer (in) - pointer to memory containing data to be encrypted. + * buffer_length (in) - length of the buffer, in bytes. + * algorithm (in) - Specifies which algorithm to use. + * signature (in) - pointer to buffer in which signature resides. + * signature_length (in) - length of the signature buffer, in bytes. + * + * Threading: + * This function may be called simultaneously with functions on other + * sessions, but not with other functions on this session. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_KEY_EXPIRED + * OEMCrypto_ERROR_SIGNATURE_FAILURE + * OEMCrypto_ERROR_NO_DEVICE_KEY + * OEMCrypto_ERROR_INVALID_SESSION + * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * + * Buffer Sizes + * OEMCrypto shall support buffer sizes of at least 100 KiB for generic + * crypto operations. + * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is + * larger than the supported size. + * + * Version: + * This method changed in API version 9. + */ +OEMCryptoResult OEMCrypto_Generic_Verify(OEMCrypto_SESSION session, + const uint8_t* in_buffer, + size_t buffer_length, + OEMCrypto_Algorithm algorithm, + const uint8_t* signature, + size_t signature_length); + /* * OEMCrypto_WrapKeyboxOrOEMCert * @@ -1754,72 +2101,6 @@ OEMCryptoResult OEMCrypto_InstallKeyboxOrOEMCert(const uint8_t* rot, */ OEMCrypto_ProvisioningMethod OEMCrypto_GetProvisioningMethod(); -/* - * OEMCrypto_GetOEMPublicCertificate - * - * Description: - * This function should place the OEM public certificate in the buffer - * public_cert. After a call to this function, all methods using an RSA key - * should use the OEM certificate’s private RSA key. See the discussion of - * Provisioning 3.0 in the document "WV Modular DRM Security Itegration Guide - * for Common Encryption (CENC)". - * - * If the buffer is not large enough, OEMCrypto should update - * public_cert_length and return OEMCrypto_ERROR_SHORT_BUFFER. - * - * Parameters: - * session (in) - this function affects the specified session only. - * public_cert (out) - the buffer where the public certificate is stored. - * public_cert_length (in/out) - on input, this is the available size of the - * buffer. On output, this is the number of bytes needed for the - * certificate. - * - * Returns: - * OEMCrypto_SUCCESS - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_ERROR_SHORT_BUFFER - * - * Threading: - * This function may be called simultaneously with functions on other - * sessions, but not with other functions on this session. - * - * Version: - * This method is new API version 12. - */ -OEMCryptoResult OEMCrypto_GetOEMPublicCertificate(OEMCrypto_SESSION session, - uint8_t* public_cert, - size_t* public_cert_length); - -/* - * OEMCrypto_LoadTestKeybox - * - * Description: - * Temporarily use the standard test keybox in place of the factory - * provisioned keybox for all functions that use keybox keys or data. This - * allows a standard suite of unit tests to be run on a production device - * without permanently changing the keybox. This keybox will persist until - * the next call to OEMCrypto_Terminate or OEMCrypto_Initialize. Upon - * initialization, revert to using the factory provisioned keybox. - * - * The test keybox can be found in the reference implementation. - * - * Parameters - * buffer (in) - pointer to memory containing test keybox, in binary form. - * length (in) - length of the buffer, in bytes. - * - * Returns - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * - * Threading - * This function is not called simultaneously with any other functions. - * It will be called just after OEMCrypto_Initialize(). - * - * Version - * This method is added in API version 10. - */ -OEMCryptoResult OEMCrypto_LoadTestKeybox(const uint8_t *buffer, size_t length); - /* * OEMCrypto_IsKeyboxOrOEMCertValid * @@ -1911,6 +2192,72 @@ OEMCryptoResult OEMCrypto_GetDeviceID(uint8_t* deviceID, size_t* idLength); */ OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData, size_t* keyDataLength); +/* + * OEMCrypto_LoadTestKeybox + * + * Description: + * Temporarily use the standard test keybox in place of the factory + * provisioned keybox for all functions that use keybox keys or data. This + * allows a standard suite of unit tests to be run on a production device + * without permanently changing the keybox. This keybox will persist until + * the next call to OEMCrypto_Terminate or OEMCrypto_Initialize. Upon + * initialization, revert to using the factory provisioned keybox. + * + * The test keybox can be found in the reference implementation. + * + * Parameters + * buffer (in) - pointer to memory containing test keybox, in binary form. + * length (in) - length of the buffer, in bytes. + * + * Returns + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * + * Threading + * This function is not called simultaneously with any other functions. + * It will be called just after OEMCrypto_Initialize(). + * + * Version + * This method is added in API version 10. + */ +OEMCryptoResult OEMCrypto_LoadTestKeybox(const uint8_t *buffer, size_t length); + +/* + * OEMCrypto_GetOEMPublicCertificate + * + * Description: + * This function should place the OEM public certificate in the buffer + * public_cert. After a call to this function, all methods using an RSA key + * should use the OEM certificate’s private RSA key. See the discussion of + * Provisioning 3.0 in the document "WV Modular DRM Security Itegration Guide + * for Common Encryption (CENC)". + * + * If the buffer is not large enough, OEMCrypto should update + * public_cert_length and return OEMCrypto_ERROR_SHORT_BUFFER. + * + * Parameters: + * session (in) - this function affects the specified session only. + * public_cert (out) - the buffer where the public certificate is stored. + * public_cert_length (in/out) - on input, this is the available size of the + * buffer. On output, this is the number of bytes needed for the + * certificate. + * + * Returns: + * OEMCrypto_SUCCESS + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_ERROR_SHORT_BUFFER + * + * Threading: + * This function may be called simultaneously with functions on other + * sessions, but not with other functions on this session. + * + * Version: + * This method is new API version 12. + */ +OEMCryptoResult OEMCrypto_GetOEMPublicCertificate(OEMCrypto_SESSION session, + uint8_t* public_cert, + size_t* public_cert_length); + /* * OEMCrypto_GetRandom * @@ -1943,6 +2290,433 @@ OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData, size_t* keyDataLength); */ OEMCryptoResult OEMCrypto_GetRandom(uint8_t* randomData, size_t dataLength); +/* + * OEMCrypto_APIVersion() + * + * Description: + * This function returns the current API version number. Because this + * API is part of a shared library, the version number allows the calling + * application to avoid version mis-match errors. + * + * There is a possibility that some API methods will be backwards compatible, + * or backwards compatible at a reduced security level. + * + * There is no plan to introduce forward-compatibility. Applications will + * reject a library with a newer version of the API. + * + * Parameters: + * none + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Returns: + * The supported API, as specified in the header file OEMCryptoCENC.h. + * + * Version: + * This method should change in all API versions. + */ +uint32_t OEMCrypto_APIVersion(); + +/* + * OEMCrypto_BuildInformation + * + * Description: + * Report the build information of the OEMCrypto library as a short null + * terminated C string. The string should be at most 128 characters long. This + * string should be updated with each release or OEMCrypto build. + * + * Some SOC vendors deliver a binary OEMCrypto library to a device + * manufacturer. This means the OEMCrypto version may not be exactly in sync + * with the system’s versions. This string can be used to help track which + * version is installed on a device. + * + * It may be used for logging or bug tracking and may be bubbled up to the app + * so that it may track metrics on errors. + * + * Since the OEMCrypto API also changes its minor version number when there + * are minor corrections, it would be useful to include the API version number + * in this string, e.g. “15.1” or “15.2” if those minor versions are released. + * + * + * Parameters: + * none + * + * Returns: + * A printable null terminated C string, suitable for a single line in a log. + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Version: + * This method changed in each API version. + */ +const char* OEMCrypto_BuildInformation(); + +/* + * OEMCrypto_Security_Patch_Level() + * + * Description: + * This function returns the current patch level of the software running in + * the trusted environment. The patch level is defined by the OEM, and is + * only incremented when a security update has been added. + * + * Parameters: + * none + * + * Returns: + * The OEM defined version number. + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Version: + * This method was introduced in API version 11. + */ +uint8_t OEMCrypto_Security_Patch_Level(); + +/* + * OEMCrypto_SecurityLevel() + * + * Description: + * This function returns the security level of the OEMCrypto library. + * + * Since this function is spoofable, it is not relied on for security + * purposes. It is for information only. + * + * Returns: + * A null terminated string. Useful values are "L1", "L2" or "L3". + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Version: + * This method changed in API version 6. + */ +const char* OEMCrypto_SecurityLevel(); + +/* + * OEMCrypto_GetHDCPCapability() + * + * Description: + * Returns the maximum HDCP version supported by the device, and the HDCP + * version supported by the device and any connected display. + * + * Parameters: + * current (out) - this is the current HDCP version, based on the device + * itself, and the display to which it is connected. + * maximum (out) - this is the maximum supported HDCP version for the device, + * ignoring any attached device. + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Returns: + * OEMCrypto_SUCCESS + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * + * Version: + * This method changed in API version 10. + */ +OEMCryptoResult OEMCrypto_GetHDCPCapability(OEMCrypto_HDCP_Capability* current, + OEMCrypto_HDCP_Capability* maximum); + +/* + * OEMCrypto_SupportsUsageTable() + * + * Description: + * This is used to determine if the device can support a usage table. Since + * this function is spoofable, it is not relied on for security purposes. It + * is for information only. The usage table is described in the section + * above. + * + * Parameters: + * none + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Returns: + * Returns true if the device can maintain a usage table. Returns false + * otherwise. + * + * Version: + * This method changed in API version 9. + */ +bool OEMCrypto_SupportsUsageTable(); + +/* + * OEMCrypto_IsAntiRollbackHwPresent() + * + * Description: + + * Indicate whether there is hardware protection to prevent the rollback of + * the usage table. For example, this is true if the usage table is stored + * entirely on a secure file system that the user cannot read or write to. + * Another example is if the usage table has a generation number and the + * generation number is stored in secure memory that is not user accessible. + * + * Parameters: + * none. + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Returns: + * Returns true if oemcrypto uses anti-rollback hardware. Returns false + * otherwise. + * + * Version: + * This method is added in API version 10. + */ +bool OEMCrypto_IsAntiRollbackHwPresent(); + +/* + * OEMCrypto_GetNumberOfOpenSessions() + * + * Description: + * Returns the current number of open OEMCrypto sessions. The CDM and + * OEMCrypto consumers can query this value so they can use resources more + * effectively. + * + * Parameters: + * count (out) - the current number of OEMCrypto sessions. + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Returns: + * OEMCrypto_SUCCESS + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * + * Version: + * This method is added in API version 10. + */ +OEMCryptoResult OEMCrypto_GetNumberOfOpenSessions(size_t* count); + +/* + * OEMCrypto_GetMaxNumberOfSessions() + * + * Description: + * Returns the maximum number of concurrent OEMCrypto sessions supported by + * the device. The CDM and OEMCrypto consumers can query this value so they + * can use resources more effectively. If the maximum number of sessions + * depends on a dynamically allocated shared resource, the returned value + * should be a best estimate of the maximum number of sessions. + * + * OEMCrypto shall support a minimum of 10 sessions. Some applications use + * multiple sessions to pre-fetch licenses, so high end devices should + * support more sessions -- we recommend a minimum of 50 sessions. + * + * Parameters: + * maximum (out) - the maximum number of OEMCrypto sessions supported by the + * device. + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Returns: + * OEMCrypto_SUCCESS + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * + * Version: + * This method is added in API version 10. + */ +OEMCryptoResult OEMCrypto_GetMaxNumberOfSessions(size_t* max); + +/* + * OEMCrypto_SupportedCertificates() + * + * Description: + * Returns the type of certificates keys that this device supports. With very + * few exceptions, all devices should support at least 2048 bit RSA keys. + * High end devices should also support 3072 bit RSA keys. Devices that are + * cast receivers should also support RSA cast receiver certificates. + * + * Beginning with OEMCrypto v14, the provisioning server may deliver to the + * device an RSA key that uses the Carmichael totient. This does not change + * the RSA algorithm -- however the product of the private and public keys is + * not necessarily the Euler number phi. OEMCrypto should not reject such + * keys. + * + * Parameters: none + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Returns: + * Returns the bitwise or of the following flags. It is likely that high + * end devices will support both 2048 and 3072 bit keys while the widevine + * servers transition to new key sizes. + * + * 0x1 = OEMCrypto_Supports_RSA_2048bit - the device can load a DRM + * certificate with a 2048 bit RSA key. + * + * 0x2 = OEMCrypto_Supports_RSA_3072bit - the device can load a DRM + * certificate with a 3072 bit RSA key. + * + * 0x10 = OEMCrypto_Supports_RSA_CAST - the device can load a CAST + * certificate. These certificate are used with + * OEMCrypto_GenerateRSASignature with padding type set to 0x2, PKCS1 with + * block type 1 padding. + * + * Version: + * This method is added in API version 13. + */ +uint32_t OEMCrypto_SupportedCertificates(); + +/* + * OEMCrypto_IsSRMUpdateSupported + * + * Description: + * Returns true if the device supports SRM files and the file can be updated + * via the function OEMCrypto_LoadSRM. This also returns false for devices + * that do not support an SRM file, devices that do not support HDCP, and + * devices that have no external display support. + * + * Parameters: + * none + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * true - if LoadSRM is supported. + * false - otherwise. + * + * Version: + * This method is new in API version 13. + */ +bool OEMCrypto_IsSRMUpdateSupported(); + +/* + * OEMCrypto_GetCurrentSRMVersion + * + * Description: + * Returns the version number of the current SRM file. If the device does + * not support SRM files, this will return OEMCrypto_ERROR_NOT_IMPLEMENTED. + * If the device only supports local displays, it would return + * OEMCrypto_LOCAL_DISPLAY_ONLY. If the device has an SRM, but cannot use + * OEMCrypto to update the SRM, then this function would set version to be + * the current version number, and return OEMCrypto_SUCCESS, but it would + * return false from OEMCrypto_IsSRMUpdateSupported. + * + * Parameters: + * version (out): current SRM version number. + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_SUCCESS + * OEMCrypto_LOCAL_DISPLAY_ONLY - to indicate version was not set, and is not + * needed. + * + * Version: + * This method is new in API version 13. + */ +OEMCryptoResult OEMCrypto_GetCurrentSRMVersion(uint16_t* version); + +/* + * OEMCrypto_GetAnalogOutputFlags + * + * Description: + * Returns whether the device supports analog output or not. This + * information will be sent to the license server, and may be used to + * determine the type of license allowed. This function is for reporting + * only. It is paired with the key control block flags Disable_Analog_Output + * and CGMS. + * + * Parameters: + * none. + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * Returns a bitwise OR of the following flags. + * 0x0 = OEMCrypto_No_Analog_Output -- the device has no analog output. + * 0x1 = OEMCrypto_Supports_Analog_Output - the device does have analog + * output. + * 0x2 = OEMCrypto_Can_Disable_Analog_Ouptput - the device does have analog + * output, but it will disable analog output if required by the key + * control block. + * 0x4 = OEMCrypto_Supports_CGMS_A - the device supports signaling 2-bit + * CGMS-A, if required by the key control block + * + * Version: + * This method is new in API version 14. + */ +uint32_t OEMCrypto_GetAnalogOutputFlags(); + +/* + * OEMCrypto_ResourceRatingTier + * + * Description: + * This function returns a positive number indicating which resource rating it + * supports. This value will bubble up to the application level as a property + * in much the same way security level does. This will allow applications to + * estimate what resolution and bandwidth the device expects to support. + * + * OEMCrypto unit tests and Android GTS tests will verify that devices do + * support the resource values specified in the table below at the tier + * claimed by the device. If a device claims to be a low end device, the + * OEMCrypto unit tests will only verify the low end performance values. + * + * OEMCrypto implementers should consider the numbers below to be minimum + * values. + * + * These performance parameters are for OEMCrypto only. In particular, + * bandwidth and codec resolution are determined by the platform. + * + * Some parameters need more explanation. The Sample size is typically the + * size of one encoded frame. Converting this to resolution depends on the + * Codec, which is not specified by OEMCrypto. Some content has the sample + * broken into several subsamples. The “number of subsamples” restriction + * requires that any content can be broken into at least that many subsamples. + * However, this number may be larger if DecryptCENC returns + * OEMCrypto_ERROR_BUFFER_TOO_LARGE. In that case, the layer above OEMCrypto + * will break the sample into subsamples of size “Decrypt Buffer Size” as + * specified in the table below. The “Decrypt Buffer Size” means the size of + * one subsample that may be passed into DecryptCENC or CopyBuffer without + * returning error OEMCrypto_ERROR_BUFFER_TOO_LARGE. + * + * The number of keys per session is an indication of how many different track + * types there can be for a piece of content. Typically, content will have + * several keys corresponding to audio and video at different resolutions. If + * the content uses key rotation, there could be three keys -- previous + * interval, current interval, and next interval -- for each resolution. + * + * Concurrent playback sessions versus concurrent sessions: some applications + * will preload multiple licenses before the user picks which content to play. + * Each of these licenses corresponds to an open session. Once playback + * starts, some platforms support picture-in-picture or multiple displays. + * Each of these pictures would correspond to a separate playback session with + * active decryption. + * + * Decrypted frames per second -- strictly speaking, OEMCrypto only controls + * the decryption part of playback and cannot control the decoding and display + * part. However, devices that support the higher resource tiers should also + * support a higher frame rate. Platforms may enforce these values. For + * example Android will enforce a frame rate via a GTS test. + * + * Resource Rating Tier + * + * Parameters: + * none. + * + * Returns: + * Returns an integer indicating which resource tier the device supports. + * + * Threading: + * This function may be called simultaneously with any other functions. + * + * Version: + * This method is new in API version 15. + */ +int32_t OEMCrypto_ResourceRatingTier(); + /* * OEMCrypto_RewrapDeviceRSAKey30 * @@ -2370,909 +3144,6 @@ OEMCryptoResult OEMCrypto_GenerateRSASignature( uint8_t* signature, size_t* signature_length, RSA_Padding_Scheme padding_scheme); -/* - * OEMCrypto_DeriveKeysFromSessionKey - * - * Description: - * Generates three secondary keys -- mac_key_server, mac_key_client, and - * encrypt_key -- for handling signing and content key decryption under the - * license server protocol for AES CTR mode. - * - * This function is similar to OEMCrypto_GenerateDerivedKeys, except that it - * uses a session key to generate the secondary keys instead of the Widevine - * Keybox device key. These two keys will be stored in secure memory until - * the next call to LoadKeys. The session key is passed in encrypted by the - * device RSA public key, and must be decrypted with the RSA private key - * before use. Once the enc_key and mac_keys have been generated, all calls - * to LoadKeys and RefreshKeys proceed in the same manner for license - * requests using RSA or using a Widevine keybox token. - * - * Verification: - * If the RSA key’s allowed_schemes is not kSign_RSASSA_PSS, then no keys are - * derived and the error OEMCrypto_ERROR_INVALID_RSA_KEY is returned. An RSA - * key cannot be used for both deriving session keys and also for PKCS1 - * signatures. - * - * Parameters: - * session (in) - crypto session identifier. - * enc_session_key (in) - session key, encrypted with the device RSA - * - key (from the device certifcate) using - * - RSA-OAEP. - * enc_session_key_length (in) - length of session_key, in bytes. - * mac_key_context (in) - pointer to memory containing context data for - * - computing the HMAC generation key. - * mac_key_context_length (in) - length of the HMAC key context data, in - * - bytes. - * enc_key_context (in) - pointer to memory containing context data for - * - computing the encryption key. - * enc_key_context_length (in) - length of the encryption key context data, in - * - bytes. - * - * Threading: - * This function may be called simultaneously with functions on other - * sessions, but not with other functions on this session. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_DEVICE_NOT_RSA_PROVISIONED - * OEMCrypto_ERROR_INVALID_SESSION - * OEMCrypto_ERROR_INVALID_CONTEXT - * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * - * Buffer Sizes - * OEMCrypto shall support message sizes of at least 8 KiB. - * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is - * larger than the supported size. - * - * Version: - * This method changed in API version 9. - */ -OEMCryptoResult OEMCrypto_DeriveKeysFromSessionKey( - OEMCrypto_SESSION session, const uint8_t* enc_session_key, - size_t enc_session_key_length, const uint8_t* mac_key_context, - size_t mac_key_context_length, const uint8_t* enc_key_context, - size_t enc_key_context_length); - -/* - * OEMCrypto_APIVersion() - * - * Description: - * This function returns the current API version number. Because this - * API is part of a shared library, the version number allows the calling - * application to avoid version mis-match errors. - * - * There is a possibility that some API methods will be backwards compatible, - * or backwards compatible at a reduced security level. - * - * There is no plan to introduce forward-compatibility. Applications will - * reject a library with a newer version of the API. - * - * Parameters: - * none - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Returns: - * The supported API, as specified in the header file OEMCryptoCENC.h. - * - * Version: - * This method should change in all API versions. - */ -uint32_t OEMCrypto_APIVersion(); - -/* - * OEMCrypto_BuildInformation - * - * Description: - * Report the build information of the OEMCrypto library as a short null - * terminated C string. The string should be at most 128 characters long. This - * string should be updated with each release or OEMCrypto build. - * - * Some SOC vendors deliver a binary OEMCrypto library to a device - * manufacturer. This means the OEMCrypto version may not be exactly in sync - * with the system’s versions. This string can be used to help track which - * version is installed on a device. - * - * It may be used for logging or bug tracking and may be bubbled up to the app - * so that it may track metrics on errors. - * - * Since the OEMCrypto API also changes its minor version number when there - * are minor corrections, it would be useful to include the API version number - * in this string, e.g. “15.1” or “15.2” if those minor versions are released. - * - * - * Parameters: - * none - * - * Returns: - * A printable null terminated C string, suitable for a single line in a log. - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Version: - * This method changed in each API version. - */ -const char* OEMCrypto_BuildInformation(); - -/** - * OEMCrypto_Security_Patch_Level() - * - * Description: - * This function returns the current patch level of the software running in - * the trusted environment. The patch level is defined by the OEM, and is - * only incremented when a security update has been added. - * - * Parameters: - * none - * - * Returns: - * The OEM defined version number. - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Version: - * This method was introduced in API version 11. - */ -uint8_t OEMCrypto_Security_Patch_Level(); - -/* - * OEMCrypto_SecurityLevel() - * - * Description: - * This function returns the security level of the OEMCrypto library. - * - * Since this function is spoofable, it is not relied on for security - * purposes. It is for information only. - * - * Returns: - * A null terminated string. Useful values are "L1", "L2" or "L3". - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Version: - * This method changed in API version 6. - */ -const char* OEMCrypto_SecurityLevel(); - -/* - * OEMCrypto_GetHDCPCapability() - * - * Description: - * Returns the maximum HDCP version supported by the device, and the HDCP - * version supported by the device and any connected display. - * - * Parameters: - * current (out) - this is the current HDCP version, based on the device - * itself, and the display to which it is connected. - * maximum (out) - this is the maximum supported HDCP version for the device, - * ignoring any attached device. - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Returns: - * OEMCrypto_SUCCESS - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * - * Version: - * This method changed in API version 10. - */ -OEMCryptoResult OEMCrypto_GetHDCPCapability(OEMCrypto_HDCP_Capability* current, - OEMCrypto_HDCP_Capability* maximum); - -/* - * OEMCrypto_SupportsUsageTable() - * - * Description: - * This is used to determine if the device can support a usage table. Since - * this function is spoofable, it is not relied on for security purposes. It - * is for information only. The usage table is described in the section - * above. - * - * Parameters: - * none - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Returns: - * Returns true if the device can maintain a usage table. Returns false - * otherwise. - * - * Version: - * This method changed in API version 9. - */ -bool OEMCrypto_SupportsUsageTable(); - -/* - * OEMCrypto_IsAntiRollbackHwPresent() - * - * Description: - - * Indicate whether there is hardware protection to prevent the rollback of - * the usage table. For example, this is true if the usage table is stored - * entirely on a secure file system that the user cannot read or write to. - * Another example is if the usage table has a generation number and the - * generation number is stored in secure memory that is not user accessible. - * - * Parameters: - * none. - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Returns: - * Returns true if oemcrypto uses anti-rollback hardware. Returns false - * otherwise. - * - * Version: - * This method is added in API version 10. - */ -bool OEMCrypto_IsAntiRollbackHwPresent(); - -/* - * OEMCrypto_GetNumberOfOpenSessions() - * - * Description: - * Returns the current number of open OEMCrypto sessions. The CDM and - * OEMCrypto consumers can query this value so they can use resources more - * effectively. - * - * Parameters: - * count (out) - the current number of OEMCrypto sessions. - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Returns: - * OEMCrypto_SUCCESS - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * - * Version: - * This method is added in API version 10. - */ -OEMCryptoResult OEMCrypto_GetNumberOfOpenSessions(size_t* count); - -/* - * OEMCrypto_GetMaxNumberOfSessions() - * - * Description: - * Returns the maximum number of concurrent OEMCrypto sessions supported by - * the device. The CDM and OEMCrypto consumers can query this value so they - * can use resources more effectively. If the maximum number of sessions - * depends on a dynamically allocated shared resource, the returned value - * should be a best estimate of the maximum number of sessions. - * - * OEMCrypto shall support a minimum of 10 sessions. Some applications use - * multiple sessions to pre-fetch licenses, so high end devices should - * support more sessions -- we recommend a minimum of 50 sessions. - * - * Parameters: - * maximum (out) - the maximum number of OEMCrypto sessions supported by the - * device. - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Returns: - * OEMCrypto_SUCCESS - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * - * Version: - * This method is added in API version 10. - */ -OEMCryptoResult OEMCrypto_GetMaxNumberOfSessions(size_t* max); - -/* - * OEMCrypto_SupportedCertificates() - * - * Description: - * Returns the type of certificates keys that this device supports. With very - * few exceptions, all devices should support at least 2048 bit RSA keys. - * High end devices should also support 3072 bit RSA keys. Devices that are - * cast receivers should also support RSA cast receiver certificates. - * - * Beginning with OEMCrypto v14, the provisioning server may deliver to the - * device an RSA key that uses the Carmichael totient. This does not change - * the RSA algorithm -- however the product of the private and public keys is - * not necessarily the Euler number phi. OEMCrypto should not reject such - * keys. - * - * Parameters: none - * - * Threading: - * This function may be called simultaneously with any other functions. - * - * Returns: - * Returns the bitwise or of the following flags. It is likely that high - * end devices will support both 2048 and 3072 bit keys while the widevine - * servers transition to new key sizes. - * - * 0x1 = OEMCrypto_Supports_RSA_2048bit - the device can load a DRM - * certificate with a 2048 bit RSA key. - * - * 0x2 = OEMCrypto_Supports_RSA_3072bit - the device can load a DRM - * certificate with a 3072 bit RSA key. - * - * 0x10 = OEMCrypto_Supports_RSA_CAST - the device can load a CAST - * certificate. These certificate are used with - * OEMCrypto_GenerateRSASignature with padding type set to 0x2, PKCS1 with - * block type 1 padding. - * - * Version: - * This method is added in API version 13. - */ -uint32_t OEMCrypto_SupportedCertificates(); - -/* - * OEMCrypto_Generic_Encrypt - * - * Description: - * This function encrypts a generic buffer of data using the current key. - * - * If the session has an entry in the Usage Table, then OEMCrypto will update - * the time_of_last_decrypt. If the status of the entry is "unused", then - * change the status to "active" and set the time_of_first_decrypt. - * - * Verification: - * The following checks should be performed. If any check fails, an error is - * returned, and the data is not encrypted. - * 1. The control bit for the current key shall have the Allow_Encrypt - * set. If not, return OEMCrypto_ERROR_UNKNOWN_FAILURE. - * 2. If the current key’s control block has a nonzero Duration field, then - * the API shall verify that the duration is greater than the session’s - * elapsed time clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. - * 3. If the current session has an entry in the Usage Table, and the status - * of that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. - * - * Parameters: - * session (in) - crypto session identifier. - * in_buffer (in) - pointer to memory containing data to be encrypted. - * buffer_length (in) - length of the buffer, in bytes. - * iv (in) - IV for encrypting data. Size is specified by the algorithm. - * algorithm (in) - Specifies which encryption algorithm to use. See - * OEMCrypto_Algorithm for valid values. - * out_buffer (out) - pointer to buffer in which encrypted data should be - * stored. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_KEY_EXPIRED - * OEMCrypto_ERROR_NO_DEVICE_KEY - * OEMCrypto_ERROR_INVALID_SESSION - * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * - * Buffer Sizes - * OEMCrypto shall support buffer sizes of at least 100 KiB for generic - * crypto operations. - * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is - * larger than the supported size. - * - * Threading: - * This function may be called simultaneously with functions on other sessions, - * but not with other functions on this session. - * - * Version: - * This method changed in API version 9. - */ -OEMCryptoResult OEMCrypto_Generic_Encrypt( - OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length, - const uint8_t* iv, OEMCrypto_Algorithm algorithm, uint8_t* out_buffer); - -/* - * OEMCrypto_Generic_Decrypt - * - * Description: - * This function decrypts a generic buffer of data using the current key. - * - * If the session has an entry in the Usage Table, then OEMCrypto will update - * the time_of_last_decrypt. If the status of the entry is "unused", then - * change the status to "active" and set the time_of_first_decrypt. - * - * Verification: - * The following checks should be performed. If any check fails, an error is - * returned, and the data is not decrypted. - * 1. The control bit for the current key shall have the Allow_Decrypt set. If - * not, return OEMCrypto_ERROR_DECRYPT_FAILED. - * 2. If the current key’s control block has the Data_Path_Type bit set, then - * return OEMCrypto_ERROR_DECRYPT_FAILED. - * 3. If the current key’s control block has a nonzero Duration field, then - * the API shall verify that the duration is greater than the session’s - * elapsed time - * clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. - * 4. If the current session has an entry in the Usage Table, and the status - * of that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. - * - * Parameters: - * session (in) - crypto session identifier. - * in_buffer (in) - pointer to memory containing data to be encrypted. - * buffer_length (in) - length of the buffer, in bytes. The algorithm may - * restrict buffer_length to be a multiple of block size. - * iv (in) - IV for encrypting data. Size is 128 bits. - * algorithm (in) - Specifies which encryption algorithm to use. - * out_buffer (out) - pointer to buffer in which decrypted data should be - * stored. - * - * Threading: - * This function may be called simultaneously with functions on other - * sessions, but not with other functions on this session. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_KEY_EXPIRED - * OEMCrypto_ERROR_DECRYPT_FAILED - * OEMCrypto_ERROR_NO_DEVICE_KEY - * OEMCrypto_ERROR_INVALID_SESSION - * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * - * Buffer Sizes - * OEMCrypto shall support buffer sizes of at least 100 KiB for generic - * crypto operations. - * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is - * larger than the supported size. - * - * Version: - * This method changed in API version 9. - */ -OEMCryptoResult OEMCrypto_Generic_Decrypt( - OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length, - const uint8_t* iv, OEMCrypto_Algorithm algorithm, uint8_t* out_buffer); - -/* - * OEMCrypto_Generic_Sign - * - * Description: - * This function signs a generic buffer of data using the current key. - * - * If the session has an entry in the Usage Table, then OEMCrypto will update - * the time_of_last_decrypt. If the status of the entry is "unused", then - * change the status to "active" and set the time_of_first_decrypt. - * - * Verification: - * The following checks should be performed. If any check fails, an error is - * returned, and the data is not signed. - * 1. The control bit for the current key shall have the Allow_Sign set. - * 2. If the current key’s control block has a nonzero Duration field, then - * the API shall verify that the duration is greater than the session’s - * elapsed time clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. - * 3. If the current session has an entry in the Usage Table, and the status of - * that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. - * - * Parameters: - * session (in) - crypto session identifier. - * in_buffer (in) - pointer to memory containing data to be encrypted. - * buffer_length (in) - length of the buffer, in bytes. - * algorithm (in) - Specifies which algorithm to use. - * signature (out) - pointer to buffer in which signature should be - * stored. May be null on the first call in order to find required buffer - * size. - * signature_length (in/out) - (in) length of the signature buffer, in bytes. - * (out) actual length of the signature - * - * - * - * Threading: - * This function may be called simultaneously with functions on other - * sessions, but not with other functions on this session. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_KEY_EXPIRED - * OEMCrypto_ERROR_SHORT_BUFFER if signature buffer is not large enough to - * hold the output signature. - * OEMCrypto_ERROR_NO_DEVICE_KEY - * OEMCrypto_ERROR_INVALID_SESSION - * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * - * Buffer Sizes - * OEMCrypto shall support buffer sizes of at least 100 KiB for generic - * crypto operations. - * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is - * larger than the supported size. - * - * Version: - * This method changed in API version 9. - */ -OEMCryptoResult OEMCrypto_Generic_Sign(OEMCrypto_SESSION session, - const uint8_t* in_buffer, - size_t buffer_length, - OEMCrypto_Algorithm algorithm, - uint8_t* signature, - size_t* signature_length); - -/* - * OEMCrypto_Generic_Verify - * - * Description: - * This function verifies the signature of a generic buffer of data using the - * current key. - * - * If the session has an entry in the Usage Table, then OEMCrypto will update - * the time_of_last_decrypt. If the status of the entry is "unused", then - * change the status to "active" and set the time_of_first_decrypt. - * - * Verification: - * The following checks should be performed. If any check fails, an error is - * returned. - * 1. The control bit for the current key shall have the Allow_Verify set. - * 2. The signature of the message shall be computed, and the API shall verify - * the computed signature matches the signature passed in. If not, return - * OEMCrypto_ERROR_SIGNATURE_FAILURE. - * 3. The signature verification shall use a constant-time algorithm (a - * signature mismatch will always take the same time as a successful - * comparison). - * 4. If the current key’s control block has a nonzero Duration field, then - * the API shall verify that the duration is greater than the session’s - * elapsed time clock. If not, return OEMCrypto_ERROR_KEY_EXPIRED. - * 5. If the current session has an entry in the Usage Table, and the status - * of that entry is "inactive", then return OEMCrypto_ERROR_INVALID_SESSION. - * - * Parameters: - * session (in) - crypto session identifier. - * in_buffer (in) - pointer to memory containing data to be encrypted. - * buffer_length (in) - length of the buffer, in bytes. - * algorithm (in) - Specifies which algorithm to use. - * signature (in) - pointer to buffer in which signature resides. - * signature_length (in) - length of the signature buffer, in bytes. - * - * Threading: - * This function may be called simultaneously with functions on other - * sessions, but not with other functions on this session. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_KEY_EXPIRED - * OEMCrypto_ERROR_SIGNATURE_FAILURE - * OEMCrypto_ERROR_NO_DEVICE_KEY - * OEMCrypto_ERROR_INVALID_SESSION - * OEMCrypto_ERROR_INSUFFICIENT_RESOURCES - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * - * Buffer Sizes - * OEMCrypto shall support buffer sizes of at least 100 KiB for generic - * crypto operations. - * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is - * larger than the supported size. - * - * Version: - * This method changed in API version 9. - */ -OEMCryptoResult OEMCrypto_Generic_Verify(OEMCrypto_SESSION session, - const uint8_t* in_buffer, - size_t buffer_length, - OEMCrypto_Algorithm algorithm, - const uint8_t* signature, - size_t signature_length); - -/* - * OEMCrypto_DeactivateUsageEntry - * - * Description: - * This deactivates the usage entry associated with the current session. This - * means that the state of the usage entry is changed to InactiveUsed if it - * was Active, or InactiveUnused if it was Unused. This also increments the - * entry's generation number, and the header's master generation number. The - * entry's flag ForbidReport will be set. This flag prevents an application - * from generating a report of a deactivated license without first saving the - * entry. - * - * Devices that do not implement a Session Usage Table may return - * OEMCrypto_ERROR_NOT_IMPLEMENTED. - * - * Parameters: - * session (in): handle for the session to be used. - * pst (in) - pointer to memory containing Provider Session Token. - * pst_length (in) - length of the pst, in bytes. - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_INVALID_CONTEXT - no entry has matching PST. - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * - * Buffer Sizes - * OEMCrypto shall support pst sizes of at least 255 bytes. - * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is - * too large. - * - * Version: - * This method changed in API version 13. - * - */ -OEMCryptoResult OEMCrypto_DeactivateUsageEntry(OEMCrypto_SESSION session, - const uint8_t* pst, - size_t pst_length); - -/* - * OEMCrypto_ReportUsage - * - * Description: - * If the buffer_length is not sufficient to hold a report structure, set - * buffer_length and return OEMCrypto_ERROR_SHORT_BUFFER. - * - * If the an entry was not loaded or created with - * OEMCrypto_CreateNewUsageEntry or OEMCrypto_LoadUsageEntry, or if the pst - * does not match that in the entry, return the error - * OEMCrypto_ERROR_INVALID_CONTEXT. - * - * If the usage entry’s flag ForbidReport is set, indicating the entry has - * not been saved since the entry was deactivated, then the error - * OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE is returned and a report is not - * generated. Similarly, if any key in the session has been used since the - * last call to OEMCrypto_UpdateUsageEntry, then the report is not generated, - * and OEMCrypto returns the error OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE. - * - * The pst_report is filled out by subtracting the times in the Usage Entry - * from the current time on the secure clock. This is done in case the - * secure clock is not using UTC time, but is instead using something like - * seconds since clock installed. - * - * Valid values for status are: - * 0 = kUnused -- the keys have not been used to decrypt. - * 1 = kActive -- the keys have been used, and have not been deactivated. - * 2 = kInactive -- deprecated. Use kInactiveUsed or kInactiveUnused. - * 3 = kInactiveUsed -- the keys have been marked inactive after a decrypt. - * 4 = kInactiveUnused -- the keys have been marked inactive, no decrypt. - * - * The clock_security_level is reported as follows: - * 0 = Insecure Clock - clock just uses system time. - * 1 = Secure Timer - clock uses secure timer, which cannot be modified by - * user software, when OEMCrypto is active and the system time when - * OEMCrypto is inactive. - * 2 = Software Secure Clock - clock cannot be modified by user software - * when OEMCrypto is active or inactive. - * 3 = Hardware Secure Clock - clock cannot be modified by user software - * and there are security features that prevent the user from modifying the - * clock in hardware, such as a tamper proof battery. - * - * After pst_report has been filled in, the HMAC SHA1 signature is computed - * for the buffer from bytes 20 to the end of the pst field. The signature is - * computed using the client_mac_key which is stored in the usage table. The - * HMAC SHA1 signature is used to prevent a rogue application from using - * OMECrypto_GenerateSignature to forge a Usage Report. - * - * This function also copies the client_mac_key and server_mac_key from the - * Usage Table entry to the session. They will be used to verify a signature - * in OEMCrypto_DeleteUsageEntry below. This session will be associated with - * the entry in the Usage Table. - * - * Devices that do not implement a Session Usage Table may return - * OEMCrypto_ERROR_NOT_IMPLEMENTED. - * - * Parameters: - * session (in) - handle for the session to be used. - * pst (in) - pointer to memory containing Provider Session Token. - * pst_length (in) - length of the pst, in bytes. - * buffer (out) - pointer to buffer in which usage report should be - * stored. May be null on the first call in order to find required buffer - * size. - * buffer_length (in/out) - (in) length of the report buffer, in bytes. - * (out) actual length of the report - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_SHORT_BUFFER if report buffer is not large enough to hold - * the output report. - * OEMCrypto_ERROR_INVALID_SESSION no open session with that id. - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_ERROR_INVALID_CONTEXT - * OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE - if no call to UpdateUsageEntry since - * last call to Deactivate or since key use. - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * OEMCrypto_ERROR_WRONG_PST - report asked for wrong pst. - * - * Buffer Sizes - * OEMCrypto shall support pst sizes of at least 255 bytes. - * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is - * too large. - * - * Version: - * This method changed in API version 13. - */ -OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session, - const uint8_t* pst, size_t pst_length, - uint8_t* buffer, - size_t* buffer_length); - -/* - * OEMCrypto_DeleteOldUsageTable - * - * Description: - * This function will delete the old usage table, if possible, freeing any - * nonvolatile secure memory. This may return - * OEMCrypto_ERROR_NOT_IMPLEMENTED if the device did not support pre-v13 - * usage tables. - * - * This is only needed for devices that are upgrading from a previous version - * of OEMCrypto to v13. Devices that have an existing usage table with - * customer’s offline licenses will use this method to move entries from the - * old table to the new one. - * - * Parameters: - * none - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * - * Version: - * This method changed in API version 13. - */ -OEMCryptoResult OEMCrypto_DeleteOldUsageTable(); - -/* - * OEMCrypto_CreateOldUsageEntry - * - * Description: - * This forces the creation of an entry in the old usage table in order to - * test OEMCrypto_CopyOldUsageTable. OEMCrypto will create a new entry, set - * the status and compute the times at license receive, first decrypt and - * last decrypt. The mac keys will be copied to the entry. The mac keys are - * not encrypted, but will only correspond to a test license. - * - * Devices that have do not support usage tables, or devices that are will - * not be field upgraded to OEMCrypto v13 may return - * OEMCrypto_ERROR_NOT_IMPLEMENTED. - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * - * Version: - * This method changed in API version 13. - */ -OEMCryptoResult OEMCrypto_CreateOldUsageEntry(uint64_t time_since_license_received, - uint64_t time_since_first_decrypt, - uint64_t time_since_last_decrypt, - OEMCrypto_Usage_Entry_Status status, - uint8_t *server_mac_key, - uint8_t *client_mac_key, - const uint8_t* pst, - size_t pst_length); - -/* - * OEMCrypto_IsSRMUpdateSupported - * - * Description: - * Returns true if the device supports SRM files and the file can be updated - * via the function OEMCrypto_LoadSRM. This also returns false for devices - * that do not support an SRM file, devices that do not support HDCP, and - * devices that have no external display support. - * - * Parameters: - * none - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * true - if LoadSRM is supported. - * false - otherwise. - * - * Version: - * This method is new in API version 13. - */ -bool OEMCrypto_IsSRMUpdateSupported(); - -/* - * OEMCrypto_GetCurrentSRMVersion - * - * Description: - * Returns the version number of the current SRM file. If the device does - * not support SRM files, this will return OEMCrypto_ERROR_NOT_IMPLEMENTED. - * If the device only supports local displays, it would return - * OEMCrypto_LOCAL_DISPLAY_ONLY. If the device has an SRM, but cannot use - * OEMCrypto to update the SRM, then this function would set version to be - * the current version number, and return OEMCrypto_SUCCESS, but it would - * return false from OEMCrypto_IsSRMUpdateSupported. - * - * Parameters: - * version (out): current SRM version number. - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_SUCCESS - * OEMCrypto_LOCAL_DISPLAY_ONLY - to indicate version was not set, and is not - * needed. - * - * Version: - * This method is new in API version 13. - */ -OEMCryptoResult OEMCrypto_GetCurrentSRMVersion(uint16_t* version); - - -/* - * OEMCrypto_LoadSRM - * - * Description: - * Verify and install a new SRM file. The device shall install the new file - * only if verification passes. If verification fails, the existing SRM will - * be left in place. Verification is defined by DCP, and includes - * verification of the SRM’s signature and verification that the SRM version - * number will not be decreased. See the section HDCP SRM Update above for - * more details about the SRM. This function is for devices that support HDCP - * v2.2 or higher and wish to receive 4k content. - * - * Parameters: - * bufer (in): buffer containing the SRM - * buffer_length (in): length of the SRM, in bytes. - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_SUCCESS - if the file was valid and was installed. - * OEMCrypto_ERROR_INVALID_CONTEXT - if the SRM version is too low, or the - * file is corrupted. - * OEMCrypto_ERROR_SIGNATURE_FAILURE - If the signature is invalid. - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - if the buffer is too large for the device. - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * - * Version: - * This method is new in API version 13. - */ -OEMCryptoResult OEMCrypto_LoadSRM(const uint8_t* buffer, - size_t buffer_length); - -/* - * OEMCrypto_RemoveSRM - * - * Description: - * Delete the current SRM. Any valid SRM, regardless of version number, will - * be installable after this via OEMCrypto_LoadSRM. - * - * This function should not be implemented on production devices, and will - * only be used to verify unit tests on a test device. - * - * Parameters: - * none - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_SUCCESS - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * - * Version: - * This method is new in API version 13. - */ -OEMCryptoResult OEMCrypto_RemoveSRM(); - /* * OEMCrypto_CreateUsageTableHeader * @@ -3496,6 +3367,183 @@ OEMCryptoResult OEMCrypto_UpdateUsageEntry(OEMCrypto_SESSION session, uint8_t* entry_buffer, size_t* entry_buffer_length); +/* + * OEMCrypto_DeactivateUsageEntry + * + * Description: + * This deactivates the usage entry associated with the current session. This + * means that the state of the usage entry is changed to InactiveUsed if it + * was Active, or InactiveUnused if it was Unused. This also increments the + * entry's generation number, and the header's master generation number. The + * entry's flag ForbidReport will be set. This flag prevents an application + * from generating a report of a deactivated license without first saving the + * entry. + * + * Devices that do not implement a Session Usage Table may return + * OEMCrypto_ERROR_NOT_IMPLEMENTED. + * + * Parameters: + * session (in): handle for the session to be used. + * pst (in) - pointer to memory containing Provider Session Token. + * pst_length (in) - length of the pst, in bytes. + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_INVALID_CONTEXT - no entry has matching PST. + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * + * Buffer Sizes + * OEMCrypto shall support pst sizes of at least 255 bytes. + * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is + * too large. + * + * Version: + * This method changed in API version 13. + * + */ +OEMCryptoResult OEMCrypto_DeactivateUsageEntry(OEMCrypto_SESSION session, + const uint8_t* pst, + size_t pst_length); + +/* + * OEMCrypto_ReportUsage + * + * Description: + * If the buffer_length is not sufficient to hold a report structure, set + * buffer_length and return OEMCrypto_ERROR_SHORT_BUFFER. + * + * If the an entry was not loaded or created with + * OEMCrypto_CreateNewUsageEntry or OEMCrypto_LoadUsageEntry, or if the pst + * does not match that in the entry, return the error + * OEMCrypto_ERROR_INVALID_CONTEXT. + * + * If the usage entry’s flag ForbidReport is set, indicating the entry has + * not been saved since the entry was deactivated, then the error + * OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE is returned and a report is not + * generated. Similarly, if any key in the session has been used since the + * last call to OEMCrypto_UpdateUsageEntry, then the report is not generated, + * and OEMCrypto returns the error OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE. + * + * The pst_report is filled out by subtracting the times in the Usage Entry + * from the current time on the secure clock. This is done in case the + * secure clock is not using UTC time, but is instead using something like + * seconds since clock installed. + * + * Valid values for status are: + * 0 = kUnused -- the keys have not been used to decrypt. + * 1 = kActive -- the keys have been used, and have not been deactivated. + * 2 = kInactive -- deprecated. Use kInactiveUsed or kInactiveUnused. + * 3 = kInactiveUsed -- the keys have been marked inactive after a decrypt. + * 4 = kInactiveUnused -- the keys have been marked inactive, no decrypt. + * + * The clock_security_level is reported as follows: + * 0 = Insecure Clock - clock just uses system time. + * 1 = Secure Timer - clock uses secure timer, which cannot be modified by + * user software, when OEMCrypto is active and the system time when + * OEMCrypto is inactive. + * 2 = Software Secure Clock - clock cannot be modified by user software + * when OEMCrypto is active or inactive. + * 3 = Hardware Secure Clock - clock cannot be modified by user software + * and there are security features that prevent the user from modifying the + * clock in hardware, such as a tamper proof battery. + * + * After pst_report has been filled in, the HMAC SHA1 signature is computed + * for the buffer from bytes 20 to the end of the pst field. The signature is + * computed using the client_mac_key which is stored in the usage table. The + * HMAC SHA1 signature is used to prevent a rogue application from using + * OMECrypto_GenerateSignature to forge a Usage Report. + * + * This function also copies the client_mac_key and server_mac_key from the + * Usage Table entry to the session. They will be used to verify a signature + * in OEMCrypto_DeleteUsageEntry below. This session will be associated with + * the entry in the Usage Table. + * + * Devices that do not implement a Session Usage Table may return + * OEMCrypto_ERROR_NOT_IMPLEMENTED. + * + * Parameters: + * session (in) - handle for the session to be used. + * pst (in) - pointer to memory containing Provider Session Token. + * pst_length (in) - length of the pst, in bytes. + * buffer (out) - pointer to buffer in which usage report should be + * stored. May be null on the first call in order to find required buffer + * size. + * buffer_length (in/out) - (in) length of the report buffer, in bytes. + * (out) actual length of the report + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_SHORT_BUFFER if report buffer is not large enough to hold + * the output report. + * OEMCrypto_ERROR_INVALID_SESSION no open session with that id. + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_ERROR_INVALID_CONTEXT + * OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE - if no call to UpdateUsageEntry since + * last call to Deactivate or since key use. + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * OEMCrypto_ERROR_WRONG_PST - report asked for wrong pst. + * + * Buffer Sizes + * OEMCrypto shall support pst sizes of at least 255 bytes. + * OEMCrypto shall return OEMCrypto_ERROR_BUFFER_TOO_LARGE if the buffer is + * too large. + * + * Version: + * This method changed in API version 13. + */ +OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session, + const uint8_t* pst, size_t pst_length, + uint8_t* buffer, + size_t* buffer_length); + +/* + * OEMCrypto_MoveEntry + * + * Description: Moves the entry associated with the current session from one + * location in the usage table header to another. This function is used by + * the CDM layer to defragment the usage table. This does not modify any data + * in the entry, except the index and the generation number. The index in + * the session’s usage entry will be changed to new_index. The generation + * number in session’s usage entry and in the header for new_index will be + * increased to the master generation number, and then the master generation + * number is incremented. If there was an existing entry at the new location, + * it will be overwritten. It is an error to call this when the entry that + * was at new_index is associated with a currently open session. In this + * case, the error code OEMCrypto_ERROR_ENTRY_IN_USE is returned. It is the + * CDM layer’s responsibility to call UpdateUsageEntry after moving an entry. + * It is an error for new_index to be beyond the end of the existing usage + * table header. + * + * Devices that do not implement a Session Usage Table may return + * OEMCrypto_ERROR_NOT_IMPLEMENTED. + * + * Parameters: + * [in] session: handle for the session to be used. + * [in] new_index: new index to be used for the session’s usage entry + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * OEMCrypto_ERROR_BUFFER_TOO_LARGE + * + * Version: + * This method is new in API version 13. + */ +OEMCryptoResult OEMCrypto_MoveEntry(OEMCrypto_SESSION session, + uint32_t new_index); + /* * OEMCrypto_ShrinkUsageTableHeader * @@ -3543,46 +3591,6 @@ OEMCryptoResult OEMCrypto_ShrinkUsageTableHeader(uint32_t new_entry_count, uint8_t* header_buffer, size_t* header_buffer_length); -/* - * OEMCrypto_MoveEntry - * - * Description: Moves the entry associated with the current session from one - * location in the usage table header to another. This function is used by - * the CDM layer to defragment the usage table. This does not modify any data - * in the entry, except the index and the generation number. The index in - * the session’s usage entry will be changed to new_index. The generation - * number in session’s usage entry and in the header for new_index will be - * increased to the master generation number, and then the master generation - * number is incremented. If there was an existing entry at the new location, - * it will be overwritten. It is an error to call this when the entry that - * was at new_index is associated with a currently open session. In this - * case, the error code OEMCrypto_ERROR_ENTRY_IN_USE is returned. It is the - * CDM layer’s responsibility to call UpdateUsageEntry after moving an entry. - * It is an error for new_index to be beyond the end of the existing usage - * table header. - * - * Devices that do not implement a Session Usage Table may return - * OEMCrypto_ERROR_NOT_IMPLEMENTED. - * - * Parameters: - * [in] session: handle for the session to be used. - * [in] new_index: new index to be used for the session’s usage entry - * - * Threading: - * This function will not be called simultaneously with any session functions. - * - * Returns: - * OEMCrypto_SUCCESS success - * OEMCrypto_ERROR_NOT_IMPLEMENTED - * OEMCrypto_ERROR_UNKNOWN_FAILURE - * OEMCrypto_ERROR_BUFFER_TOO_LARGE - * - * Version: - * This method is new in API version 13. - */ -OEMCryptoResult OEMCrypto_MoveEntry(OEMCrypto_SESSION session, - uint32_t new_index); - /* * OEMCrypto_CopyOldUsageEntry * @@ -3618,103 +3626,94 @@ OEMCryptoResult OEMCrypto_CopyOldUsageEntry(OEMCrypto_SESSION session, size_t pst_length); /* - * OEMCrypto_GetAnalogOutputFlags + * OEMCrypto_DeleteOldUsageTable * * Description: - * Returns whether the device supports analog output or not. This - * information will be sent to the license server, and may be used to - * determine the type of license allowed. This function is for reporting - * only. It is paired with the key control block flags Disable_Analog_Output - * and CGMS. + * This function will delete the old usage table, if possible, freeing any + * nonvolatile secure memory. This may return + * OEMCrypto_ERROR_NOT_IMPLEMENTED if the device did not support pre-v13 + * usage tables. + * + * This is only needed for devices that are upgrading from a previous version + * of OEMCrypto to v13. Devices that have an existing usage table with + * customer’s offline licenses will use this method to move entries from the + * old table to the new one. * * Parameters: - * none. + * none * * Threading: * This function will not be called simultaneously with any session functions. * * Returns: - * Returns a bitwise OR of the following flags. - * 0x0 = OEMCrypto_No_Analog_Output -- the device has no analog output. - * 0x1 = OEMCrypto_Supports_Analog_Output - the device does have analog - * output. - * 0x2 = OEMCrypto_Can_Disable_Analog_Ouptput - the device does have analog - * output, but it will disable analog output if required by the key - * control block. - * 0x4 = OEMCrypto_Supports_CGMS_A - the device supports signaling 2-bit - * CGMS-A, if required by the key control block + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_ERROR_UNKNOWN_FAILURE * * Version: - * This method is new in API version 14. + * This method changed in API version 13. */ -uint32_t OEMCrypto_GetAnalogOutputFlags(); +OEMCryptoResult OEMCrypto_DeleteOldUsageTable(); /* - * OEMCrypto_ResourceRatingTier + * OEMCrypto_RemoveSRM * * Description: - * This function returns a positive number indicating which resource rating it - * supports. This value will bubble up to the application level as a property - * in much the same way security level does. This will allow applications to - * estimate what resolution and bandwidth the device expects to support. + * Delete the current SRM. Any valid SRM, regardless of version number, will + * be installable after this via OEMCrypto_LoadSRM. * - * OEMCrypto unit tests and Android GTS tests will verify that devices do - * support the resource values specified in the table below at the tier - * claimed by the device. If a device claims to be a low end device, the - * OEMCrypto unit tests will only verify the low end performance values. - * - * OEMCrypto implementers should consider the numbers below to be minimum - * values. - * - * These performance parameters are for OEMCrypto only. In particular, - * bandwidth and codec resolution are determined by the platform. - * - * Some parameters need more explanation. The Sample size is typically the - * size of one encoded frame. Converting this to resolution depends on the - * Codec, which is not specified by OEMCrypto. Some content has the sample - * broken into several subsamples. The “number of subsamples” restriction - * requires that any content can be broken into at least that many subsamples. - * However, this number may be larger if DecryptCENC returns - * OEMCrypto_ERROR_BUFFER_TOO_LARGE. In that case, the layer above OEMCrypto - * will break the sample into subsamples of size “Decrypt Buffer Size” as - * specified in the table below. The “Decrypt Buffer Size” means the size of - * one subsample that may be passed into DecryptCENC or CopyBuffer without - * returning error OEMCrypto_ERROR_BUFFER_TOO_LARGE. - * - * The number of keys per session is an indication of how many different track - * types there can be for a piece of content. Typically, content will have - * several keys corresponding to audio and video at different resolutions. If - * the content uses key rotation, there could be three keys -- previous - * interval, current interval, and next interval -- for each resolution. - * - * Concurrent playback sessions versus concurrent sessions: some applications - * will preload multiple licenses before the user picks which content to play. - * Each of these licenses corresponds to an open session. Once playback - * starts, some platforms support picture-in-picture or multiple displays. - * Each of these pictures would correspond to a separate playback session with - * active decryption. - * - * Decrypted frames per second -- strictly speaking, OEMCrypto only controls - * the decryption part of playback and cannot control the decoding and display - * part. However, devices that support the higher resource tiers should also - * support a higher frame rate. Platforms may enforce these values. For - * example Android will enforce a frame rate via a GTS test. - * - * Resource Rating Tier + * This function should not be implemented on production devices, and will + * only be used to verify unit tests on a test device. * * Parameters: - * none. - * - * Returns: - * Returns an integer indicating which resource tier the device supports. + * none * * Threading: - * This function may be called simultaneously with any other functions. + * This function will not be called simultaneously with any session functions. + * + * Returns: + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_SUCCESS + * OEMCrypto_ERROR_UNKNOWN_FAILURE * * Version: - * This method is new in API version 15. + * This method is new in API version 13. */ -int32_t OEMCrypto_ResourceRatingTier(); +OEMCryptoResult OEMCrypto_RemoveSRM(); + +/* + * OEMCrypto_CreateOldUsageEntry + * + * Description: + * This forces the creation of an entry in the old usage table in order to + * test OEMCrypto_CopyOldUsageTable. OEMCrypto will create a new entry, set + * the status and compute the times at license receive, first decrypt and + * last decrypt. The mac keys will be copied to the entry. The mac keys are + * not encrypted, but will only correspond to a test license. + * + * Devices that have do not support usage tables, or devices that are will + * not be field upgraded to OEMCrypto v13 may return + * OEMCrypto_ERROR_NOT_IMPLEMENTED. + * + * Threading: + * This function will not be called simultaneously with any session functions. + * + * Returns: + * OEMCrypto_SUCCESS success + * OEMCrypto_ERROR_NOT_IMPLEMENTED + * OEMCrypto_ERROR_UNKNOWN_FAILURE + * + * Version: + * This method changed in API version 13. + */ +OEMCryptoResult OEMCrypto_CreateOldUsageEntry(uint64_t time_since_license_received, + uint64_t time_since_first_decrypt, + uint64_t time_since_last_decrypt, + OEMCrypto_Usage_Entry_Status status, + uint8_t *server_mac_key, + uint8_t *client_mac_key, + const uint8_t* pst, + size_t pst_length); /* * OEMCrypto_SupportsDecryptHash