/*
 * @file target.h
 * @brief interfaces for target platform. To port this software to other
 *        platforms, developers need to implement all of these interfaces
 *        on the target platform.
 * Copyright (c) 2016, Samsung Electronics Corporation. All rights reserved.
 */

#ifndef __TARGET_H__
#define __TARGET_H__

#ifdef USE_QSEE
#include <comdef.h>
#include "qsee_log.h"
#elif USE_MOBICORE
#error "TEE SDK not defined"
#elif USE_BLOWFISH
#include <unistd.h>
#include <tee_internal_api.h>
#include <stdio.h>
#include <string.h>
#else
#error "TEE SDK not defined or not support yet..."
#endif


#include "tl_rsa_crypto.h"
/*========================== RSA Crypto =============================*/
int target_rsa_decrypt(RsaKeyParam_t *key,
                       uint8_t *cipher,
                       uint32_t cipherlen,
                       uint8_t *msg,
                       uint32_t *msglen);

int target_rsa_encrypt(RsaKeyParam_t *key,
                       uint8_t *msg,
                       uint32_t msglen,
                       uint8_t *cipher,
                       uint32_t *cipherlen);

/*======================== secure message ============================*/
int target_encrypt_cp_message(uint8_t* in_buf, uint32_t in_len,
                              uint8_t* out_buf, uint32_t* out_len);

int target_decrypt_cp_message(uint8_t* in_buf, uint32_t in_len,
                              uint8_t* out_buf, uint32_t* out_len);

int target_encrypt_tz_app_message(char *dest_app,
                                  uint8_t* in_buf, uint32_t in_len,
                                  uint8_t* out_buf, uint32_t* out_len);

int target_decrypt_tz_app_message(char *src_app,
                                  uint8_t* in_buf, uint32_t in_len,
                                  uint8_t* out_buf, uint32_t* out_len);

int target_aes_gcm_enc(uint8_t* plain_text, uint32_t plain_text_len,
                  uint8_t* cipher_text, uint32_t* cipher_text_len,
                  uint8_t *key, uint32_t key_sz,
                  uint8_t *tag, uint32_t *tag_sz);

int target_aes_gcm_dec(uint8_t* cipher_text, uint32_t cipher_text_len,
                  uint8_t* plain_text, uint32_t* plain_text_len,
                  uint8_t *key, uint32_t key_sz,
                  uint8_t *tag, uint32_t tag_sz);

/*========================== heap malloc and free ===================*/
void *target_malloc(uint32_t size);
void target_free(void *ptr);

/*========================== printf =================================*/
void target_printf(const char *s);

/*========================== file system ============================*/
int target_get_file_size(char *file, uint32_t *size);
int target_read_file(char *file, uint8_t *buf, uint32_t *size);
int target_write_file(char *file, uint8_t *buf, uint32_t size);
int target_remove_file(char *file);

/*========================== timer & time ============================*/
int target_get_uptime(void);
int64_t target_get_current(void);


/*========================== crypto ==================================*/
int target_get_derived_key(uint8_t*, uint32_t *);

#ifdef SAMPLE_TEST
int target_fs_test(void);
#endif

#endif /* __TARGET_H__*/
