/*
 * Copyright (C) 2016 Samsung Electronics. Co. Ltd,
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __SKPM_UTIL_H__
#define __SKPM_UTIL_H__

#include "platform.h"
#include "skpm.h"

#define MAX_SECURE_OBJECT_SIZE                  6000

#define SECURE_OBJECT_TYPE_SERVICE_KEY          1
#define SECURE_OBJECT_TYPE_KEY_LIST             2
#define SECURE_OBJECT_TYPE_KEYBLOB              3
#define SECURE_OBJECT_TYPE_ECC_KEY_INFO         4
#define SECURE_OBJECT_TYPE_RSA_KEY_INFO         5
#define SECURE_OBJECT_TYPE_TLS_SESSION_INFO     6

STATUS wrap_secure_object(const uint8_t *appId, const uint8_t *input, uint32_t input_size, uint8_t *output, uint32_t *output_size);
#if defined(USE_BLOWFISH) || defined(USE_QSEE)
STATUS unwrap_secure_object(const uint8_t *sourceTid, const uint8_t *input, uint32_t input_size, uint8_t *output, uint32_t *output_size);
#else
STATUS unwrap_secure_object(const uint8_t *input, uint32_t input_size, uint8_t *output, uint32_t *output_size);
#endif

STATUS wrapInternalData(uint8_t objectType, uint8_t *input, uint32_t inputSize, uint8_t *output, uint32_t *outputSize);
STATUS unwrapInternalData(uint8_t objectType, uint8_t *input, uint32_t inputSize, uint8_t *output, uint32_t *outputSize);

void secure_memclear(void * secure_data, size_t size);
void* tz_malloc(uint32_t size);
void tz_free(void *data);

int32_t parseTlvData(uint8_t *tlvData, uint32_t leftBuffSize, uint8_t *data, uint32_t dataBuffSize, uint32_t *dataSize);

#endif
