2474 lines
74 KiB
C
2474 lines
74 KiB
C
/*
|
|
* This code is auto-generated, do not edit
|
|
*/
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "OEMCryptoCENC.h"
|
|
#include "api_support.h"
|
|
#include "bump_allocator.h"
|
|
#include "shared_memory_allocator.h"
|
|
#include "shared_memory_interface.h"
|
|
#include "special_cases.h"
|
|
#include "transport_interface.h"
|
|
|
|
OEMCRYPTO_API const char* OEMCrypto_SecurityLevel() {
|
|
char* result = NULL;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_SecurityLevel_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_SecurityLevel_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API const char* OEMCrypto_BuildInformation() {
|
|
char* result = NULL;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_BuildInformation_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_BuildInformation_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_SetSandbox(const uint8_t* sandbox_id,
|
|
size_t sandbox_id_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_SetSandbox_Request(request, sandbox_id, sandbox_id_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_SetSandbox_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_Initialize() {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_Initialize_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_Initialize_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_Terminate() {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_Terminate_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_Terminate_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
API_Terminate();
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_OpenSession(OEMCrypto_SESSION* session) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_OpenSession_Request(request, session);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_OpenSession_Response(response, &result, &session);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_CloseSession(OEMCrypto_SESSION session) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_CloseSession_Request(request, session);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_CloseSession_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GenerateDerivedKeys(
|
|
OEMCrypto_SESSION session, const SharedMemory* mac_key_context,
|
|
uint32_t mac_key_context_length, const SharedMemory* enc_key_context,
|
|
uint32_t enc_key_context_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GenerateDerivedKeys_Request(request, session, mac_key_context,
|
|
mac_key_context_length, enc_key_context,
|
|
enc_key_context_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GenerateDerivedKeys_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_DeriveKeysFromSessionKey(
|
|
OEMCrypto_SESSION session, const uint8_t* enc_session_key,
|
|
size_t enc_session_key_length, const SharedMemory* mac_key_context,
|
|
size_t mac_key_context_length, const SharedMemory* enc_key_context,
|
|
size_t enc_key_context_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_DeriveKeysFromSessionKey_Request(
|
|
request, session, enc_session_key, enc_session_key_length,
|
|
mac_key_context, mac_key_context_length, enc_key_context,
|
|
enc_key_context_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_DeriveKeysFromSessionKey_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session,
|
|
uint32_t* nonce) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GenerateNonce_Request(request, session, nonce);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GenerateNonce_Response(response, &result, &nonce);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GenerateSignature(
|
|
OEMCrypto_SESSION session, const SharedMemory* message,
|
|
size_t message_length, uint8_t* signature, size_t* signature_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GenerateSignature_Request(request, session, message, message_length,
|
|
signature, signature_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GenerateSignature_Response(response, &result, &signature,
|
|
&signature_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_LoadSRM(const uint8_t* buffer,
|
|
size_t buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadSRM_Request(request, buffer, buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadSRM_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_LoadKeys(
|
|
OEMCrypto_SESSION session, const SharedMemory* message,
|
|
size_t message_length, const SharedMemory* signature,
|
|
size_t signature_length, OEMCrypto_Substring enc_mac_keys_iv,
|
|
OEMCrypto_Substring enc_mac_keys, size_t key_array_length,
|
|
const OEMCrypto_KeyObject* key_array, OEMCrypto_Substring pst,
|
|
OEMCrypto_Substring srm_restriction_data,
|
|
OEMCrypto_LicenseType license_type) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadKeys_Request(request, session, message, message_length,
|
|
signature, signature_length, enc_mac_keys_iv,
|
|
enc_mac_keys, key_array_length, key_array, pst,
|
|
srm_restriction_data, license_type);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadKeys_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_LoadEntitledContentKeys(
|
|
OEMCrypto_SESSION session, const SharedMemory* message,
|
|
size_t message_length, size_t key_array_length,
|
|
const OEMCrypto_EntitledContentKeyObject* key_array) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadEntitledContentKeys_Request(
|
|
request, session, message, message_length, key_array_length, key_array);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadEntitledContentKeys_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_RefreshKeys(OEMCrypto_SESSION session, const SharedMemory* message,
|
|
size_t message_length, const SharedMemory* signature,
|
|
size_t signature_length, size_t key_array_length,
|
|
const OEMCrypto_KeyRefreshObject* key_array) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_RefreshKeys_Request(request, session, message, message_length,
|
|
signature, signature_length, key_array_length,
|
|
key_array);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_RefreshKeys_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_QueryKeyControl(
|
|
OEMCrypto_SESSION session, const uint8_t* content_key_id,
|
|
size_t content_key_id_length, uint8_t* key_control_block,
|
|
size_t* key_control_block_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_QueryKeyControl_Request(request, session, content_key_id,
|
|
content_key_id_length, key_control_block,
|
|
key_control_block_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_QueryKeyControl_Response(response, &result, &key_control_block,
|
|
&key_control_block_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_SelectKey(
|
|
OEMCrypto_SESSION session, const uint8_t* content_key_id,
|
|
size_t content_key_id_length, OEMCryptoCipherMode cipher_mode) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_SelectKey_Request(request, session, content_key_id,
|
|
content_key_id_length, cipher_mode);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_SelectKey_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_Generic_Encrypt(
|
|
OEMCrypto_SESSION session, const SharedMemory* in_buffer,
|
|
size_t in_buffer_length, const uint8_t* iv, OEMCrypto_Algorithm algorithm,
|
|
uint8_t* out_buffer) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_Generic_Encrypt_Request(request, session, in_buffer,
|
|
in_buffer_length, iv, algorithm, out_buffer);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_Generic_Encrypt_Response(response, &result, &in_buffer_length,
|
|
&out_buffer);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_Generic_Decrypt(
|
|
OEMCrypto_SESSION session, const SharedMemory* in_buffer,
|
|
size_t in_buffer_length, const uint8_t* iv, OEMCrypto_Algorithm algorithm,
|
|
uint8_t* out_buffer) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_Generic_Decrypt_Request(request, session, in_buffer,
|
|
in_buffer_length, iv, algorithm, out_buffer);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_Generic_Decrypt_Response(response, &result, &in_buffer_length,
|
|
&out_buffer);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_Generic_Sign(OEMCrypto_SESSION session, const SharedMemory* buffer,
|
|
size_t buffer_length, OEMCrypto_Algorithm algorithm,
|
|
uint8_t* signature, size_t* signature_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_Generic_Sign_Request(request, session, buffer, buffer_length,
|
|
algorithm, signature, signature_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_Generic_Sign_Response(response, &result, &signature,
|
|
&signature_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_Generic_Verify(
|
|
OEMCrypto_SESSION session, const SharedMemory* buffer, size_t buffer_length,
|
|
OEMCrypto_Algorithm algorithm, const SharedMemory* signature,
|
|
size_t signature_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_Generic_Verify_Request(request, session, buffer, buffer_length,
|
|
algorithm, signature, signature_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_Generic_Verify_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_UpdateUsageTable() {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_UpdateUsageTable_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_UpdateUsageTable_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_WrapKeyboxOrOEMCert(
|
|
const uint8_t* rot, size_t rotLength, uint8_t* wrappedRot,
|
|
size_t* wrappedRotLength, const uint8_t* transportKey,
|
|
size_t transportKeyLength) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_WrapKeyboxOrOEMCert_Request(request, rot, rotLength, wrappedRot,
|
|
wrappedRotLength, transportKey,
|
|
transportKeyLength);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_WrapKeyboxOrOEMCert_Response(response, &result, &wrappedRot,
|
|
&wrappedRotLength);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_InstallKeyboxOrOEMCert(const uint8_t* rot, size_t rotLength) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_InstallKeyboxOrOEMCert_Request(request, rot, rotLength);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_InstallKeyboxOrOEMCert_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCrypto_ProvisioningMethod OEMCrypto_GetProvisioningMethod() {
|
|
OEMCrypto_ProvisioningMethod result = OEMCrypto_ProvisioningError;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetProvisioningMethod_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetProvisioningMethod_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_IsKeyboxOrOEMCertValid() {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_IsKeyboxOrOEMCertValid_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_IsKeyboxOrOEMCertValid_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetDeviceID(uint8_t* device_id,
|
|
size_t* device_id_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetDeviceID_Request(request, device_id, device_id_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetDeviceID_Response(response, &result, &device_id,
|
|
&device_id_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData,
|
|
size_t* keyDataLength) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetKeyData_Request(request, keyData, keyDataLength);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetKeyData_Response(response, &result, &keyData, &keyDataLength);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_LoadTestKeybox(const uint8_t* buffer,
|
|
size_t buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadTestKeybox_Request(request, buffer, buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadTestKeybox_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetOEMPublicCertificate(
|
|
OEMCrypto_SESSION session, uint8_t* public_cert,
|
|
size_t* public_cert_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetOEMPublicCertificate_Request(request, session, public_cert,
|
|
public_cert_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetOEMPublicCertificate_Response(response, &result, &public_cert,
|
|
&public_cert_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetRandom(uint8_t* random_data,
|
|
size_t random_data_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetRandom_Request(request, random_data, random_data_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetRandom_Response(response, &result, &random_data,
|
|
&random_data_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API uint32_t OEMCrypto_APIVersion() {
|
|
uint32_t result = 0;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_APIVersion_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_APIVersion_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API uint8_t OEMCrypto_Security_Patch_Level() {
|
|
uint8_t result = 0;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_Security_Patch_Level_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_Security_Patch_Level_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetHDCPCapability(
|
|
OEMCrypto_HDCP_Capability* current, OEMCrypto_HDCP_Capability* maximum) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetHDCPCapability_Request(request, current, maximum);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetHDCPCapability_Response(response, &result, ¤t, &maximum);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API bool OEMCrypto_SupportsUsageTable() {
|
|
bool result = false;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_SupportsUsageTable_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_SupportsUsageTable_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API bool OEMCrypto_IsAntiRollbackHwPresent() {
|
|
bool result = false;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_IsAntiRollbackHwPresent_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_IsAntiRollbackHwPresent_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetNumberOfOpenSessions(size_t* count) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetNumberOfOpenSessions_Request(request, count);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetNumberOfOpenSessions_Response(response, &result, &count);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetMaxNumberOfSessions(size_t* max) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetMaxNumberOfSessions_Request(request, max);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetMaxNumberOfSessions_Response(response, &result, &max);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API uint32_t OEMCrypto_SupportedCertificates() {
|
|
uint32_t result = 0;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_SupportedCertificates_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_SupportedCertificates_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API bool OEMCrypto_IsSRMUpdateSupported() {
|
|
bool result = false;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_IsSRMUpdateSupported_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_IsSRMUpdateSupported_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_GetCurrentSRMVersion(uint16_t* version) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetCurrentSRMVersion_Request(request, version);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetCurrentSRMVersion_Response(response, &result, &version);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API uint32_t OEMCrypto_GetAnalogOutputFlags() {
|
|
uint32_t result = 0;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetAnalogOutputFlags_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetAnalogOutputFlags_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API uint32_t OEMCrypto_ResourceRatingTier() {
|
|
uint32_t result = 0;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_ResourceRatingTier_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_ResourceRatingTier_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey30(
|
|
OEMCrypto_SESSION session, const uint32_t* unaligned_nonce,
|
|
const SharedMemory* encrypted_message_key,
|
|
size_t encrypted_message_key_length, const SharedMemory* enc_rsa_key,
|
|
size_t enc_rsa_key_length, const uint8_t* enc_rsa_key_iv,
|
|
uint8_t* wrapped_rsa_key, size_t* wrapped_rsa_key_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_RewrapDeviceRSAKey30_Request(
|
|
request, session, unaligned_nonce, encrypted_message_key,
|
|
encrypted_message_key_length, enc_rsa_key, enc_rsa_key_length,
|
|
enc_rsa_key_iv, wrapped_rsa_key, wrapped_rsa_key_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_RewrapDeviceRSAKey30_Response(response, &result, &wrapped_rsa_key,
|
|
&wrapped_rsa_key_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey(
|
|
OEMCrypto_SESSION session, const SharedMemory* message,
|
|
size_t message_length, const SharedMemory* signature,
|
|
size_t signature_length, const uint32_t* unaligned_nonce,
|
|
const uint8_t* enc_rsa_key, size_t enc_rsa_key_length,
|
|
const uint8_t* enc_rsa_key_iv, uint8_t* wrapped_rsa_key,
|
|
size_t* wrapped_rsa_key_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_RewrapDeviceRSAKey_Request(
|
|
request, session, message, message_length, signature, signature_length,
|
|
unaligned_nonce, enc_rsa_key, enc_rsa_key_length, enc_rsa_key_iv,
|
|
wrapped_rsa_key, wrapped_rsa_key_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_RewrapDeviceRSAKey_Response(response, &result, &wrapped_rsa_key,
|
|
&wrapped_rsa_key_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_LoadDeviceRSAKey(
|
|
OEMCrypto_SESSION session, const SharedMemory* wrapped_rsa_key,
|
|
size_t wrapped_rsa_key_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadDeviceRSAKey_Request(request, session, wrapped_rsa_key,
|
|
wrapped_rsa_key_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadDeviceRSAKey_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_LoadTestRSAKey() {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadTestRSAKey_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadTestRSAKey_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GenerateRSASignature(
|
|
OEMCrypto_SESSION session, const SharedMemory* message,
|
|
size_t message_length, uint8_t* signature, size_t* signature_length,
|
|
RSA_Padding_Scheme padding_scheme) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GenerateRSASignature_Request(request, session, message,
|
|
message_length, signature,
|
|
signature_length, padding_scheme);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GenerateRSASignature_Response(response, &result, &signature,
|
|
&signature_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_CreateUsageTableHeader(
|
|
uint8_t* header_buffer, size_t* header_buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_CreateUsageTableHeader_Request(request, header_buffer,
|
|
header_buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_CreateUsageTableHeader_Response(response, &result, &header_buffer,
|
|
&header_buffer_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_LoadUsageTableHeader(const uint8_t* buffer, size_t buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadUsageTableHeader_Request(request, buffer, buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadUsageTableHeader_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_CreateNewUsageEntry(
|
|
OEMCrypto_SESSION session, uint32_t* usage_entry_number) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_CreateNewUsageEntry_Request(request, session, usage_entry_number);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_CreateNewUsageEntry_Response(response, &result,
|
|
&usage_entry_number);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_LoadUsageEntry(OEMCrypto_SESSION session, uint32_t usage_entry_number,
|
|
const uint8_t* buffer, size_t buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_LoadUsageEntry_Request(request, session, usage_entry_number, buffer,
|
|
buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_LoadUsageEntry_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_UpdateUsageEntry(
|
|
OEMCrypto_SESSION session, SharedMemory* header_buffer,
|
|
size_t* header_buffer_length, SharedMemory* entry_buffer,
|
|
size_t* entry_buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_UpdateUsageEntry_Request(request, session, header_buffer,
|
|
header_buffer_length, entry_buffer,
|
|
entry_buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_UpdateUsageEntry_Response(response, &result, &header_buffer,
|
|
&header_buffer_length, &entry_buffer,
|
|
&entry_buffer_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_DeactivateUsageEntry(
|
|
OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_DeactivateUsageEntry_Request(request, session, pst, pst_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_DeactivateUsageEntry_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session,
|
|
const uint8_t* pst,
|
|
size_t pst_length,
|
|
uint8_t* buffer,
|
|
size_t* buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_ReportUsage_Request(request, session, pst, pst_length, buffer,
|
|
buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_ReportUsage_Response(response, &result, &buffer, &buffer_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_DeleteUsageEntry(
|
|
OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length,
|
|
const uint8_t* message, size_t message_length, const uint8_t* signature,
|
|
size_t signature_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_DeleteUsageEntry_Request(request, session, pst, pst_length, message,
|
|
message_length, signature,
|
|
signature_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_DeleteUsageEntry_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_ForceDeleteUsageEntry(const uint8_t* pst, size_t pst_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_ForceDeleteUsageEntry_Request(request, pst, pst_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_ForceDeleteUsageEntry_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_MoveEntry(OEMCrypto_SESSION session,
|
|
uint32_t new_index) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_MoveEntry_Request(request, session, new_index);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_MoveEntry_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_ShrinkUsageTableHeader(
|
|
uint32_t new_entry_count, uint8_t* header_buffer,
|
|
size_t* header_buffer_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_ShrinkUsageTableHeader_Request(request, new_entry_count,
|
|
header_buffer, header_buffer_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_ShrinkUsageTableHeader_Response(response, &result, &header_buffer,
|
|
&header_buffer_length);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_CopyOldUsageEntry(
|
|
OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_CopyOldUsageEntry_Request(request, session, pst, pst_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_CopyOldUsageEntry_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_DeleteOldUsageTable() {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_DeleteOldUsageTable_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_DeleteOldUsageTable_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_RemoveSRM() {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_RemoveSRM_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_RemoveSRM_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API 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) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_CreateOldUsageEntry_Request(
|
|
request, time_since_license_received, time_since_first_decrypt,
|
|
time_since_last_decrypt, status, server_mac_key, client_mac_key, pst,
|
|
pst_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_CreateOldUsageEntry_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API uint32_t OEMCrypto_SupportsDecryptHash() {
|
|
uint32_t result = 0;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_SupportsDecryptHash_Request(request);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_SupportsDecryptHash_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult
|
|
OEMCrypto_SetDecryptHash(OEMCrypto_SESSION session, uint32_t frame_number,
|
|
const uint8_t* hash, size_t hash_length) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_SetDecryptHash_Request(request, session, frame_number, hash,
|
|
hash_length);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_SetDecryptHash_Response(response, &result);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|
|
|
|
OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetHashErrorCode(
|
|
OEMCrypto_SESSION session, uint32_t* failed_frame_number) {
|
|
OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
pthread_mutex_lock(&api_lock);
|
|
Message* request = API_InitializeRequest();
|
|
Message* response = NULL;
|
|
if (!request) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Pack_GetHashErrorCode_Request(request, session, failed_frame_number);
|
|
if (GetStatus(request) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
response = API_Transact(request);
|
|
if (!response) {
|
|
goto cleanup_and_return;
|
|
}
|
|
ODK_Unpack_GetHashErrorCode_Response(response, &result, &failed_frame_number);
|
|
|
|
if (GetStatus(response) != MESSAGE_STATUS_OK) {
|
|
api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
goto cleanup_and_return;
|
|
}
|
|
cleanup_and_return:
|
|
if (request) {
|
|
ODK_Transport_DeallocateMessage(request);
|
|
}
|
|
if (response) {
|
|
ODK_Transport_DeallocateMessage(response);
|
|
}
|
|
result = API_CheckResult(result);
|
|
pthread_mutex_unlock(&api_lock);
|
|
return result;
|
|
}
|