/**
 * @(#) trust-zone module  1.0 2015/12/12
 *
 * Copyright (c) 2014, IFAA and/or its affiliates. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * -Redistribution of source code must retain the above copyright notice, this
 *  list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduce the above copyright notice,
 *  this list of conditions and the following disclaimer in the documentation
 *  and/or other materials provided with the distribution.
 *
 * Neither the name of IFAA or the names of contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. IFAA, INC.
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL IFAA OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF IFAA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that this software is not designed, licensed or intended
 * for use in the design, construction, operation or maintenance of any
 * nuclear facility.
 *
 * ***********************************************************************************
 *
 * This head file defines the interfaces that library presents to client programs, and
 * is intended for call from Trusted Execution Application.
 */


#ifndef __GP_OEM_H__
#define __GP_OEM_H__

#include <tzWrappers/TzwCommon.h>
/**
 * @brief Retrieve unique device ID, the minimum length of returned device ID
 * should be 40 bytes.
 *
 * @param[out] deviceID The buffer that receives the device ID
 * @param[inout] size in bytes, of the buffer that deviceID points to
 *
 * @return TEE_Result
 */
EXTERNC TEE_Result TEE_GetDeviceId(void* deviceID, size_t* size);

/**
 * @brief Sign digest with preset RSA private key
 *
 * @note OEMs should use the below RSA modulus n and private key exponent d
 * during integration test with alipay, the algorithm used when signing the
 * digest should be `TEE_ALG_RSASSA_PKCS1_V1_5_SHA256`. In release version,
 * OEMs should generate a new RSA key pair(RSA 2048). The private key should
 * be kept secretly from being leaked. The public key should be deliverd to
 * alipay in PEM format.
 *
 * @param[in] digest The digest to be signed
 * @param[in] digestLen The length of digest in bytes
 * @param[out] signature The buffer receives the returned signature
 * @param[inout] signatureLen Size, in bytes, of the buffer that signature
 * points to
 *
 * @return TEE_Result
 */
EXTERNC TEE_Result TEE_AuthenticatorSignDigest(void* digest, size_t digestLen,
                                               void* signature,
                                               size_t* signatureLen);
/**
 * @brief Retrieves the version of authenticator
 *
 * This is the version of the private key used by TEE_AuthenticatorSignDigest,
 * which starts from 1. If the private key is leaked, the server will reject
 * that private key according to the version. A new key has to be applied in
 * TEE_AuthenticatorSignDigest and the version should be incremented by 1.
 *
 * @return version
 */
EXTERNC int32_t TEE_GetAuthenticatorVersion(void);

/**
 * @brief Retrieve last identified fingerprint ID from fingerprint sensor
 *
 * @param[out] id fingerprint ID
 *
 * @return TEE_ERROR_TIMEOUT: The function is called after 1 second delay
 * @return TEE_SUCCESS: success
 */
EXTERNC TEE_Result TEE_GetFpLastIdentifiedResult(int32_t* id);

/**
 * @brief This function is implemented by alipay, OEM should invoke this
 * function in TA's entry point.
 *
 * @note OEM should check the validity of the input and output buffer.
 *
 * @param[in] in The exact data from alipay's android application
 * @param[in] in_len The size of the buffer that in points
 * @param[out] out The buffer that receives output
 * @param[inout] out_len Size, in bytes, of the buffer that out points to.
 * Recommended value is 4K.
 *
 * @return TEE_Result
 */
EXTERNC TEE_Result alipay_tz_invoke_command(uint8_t* in, size_t in_len,
                                            uint8_t* out, size_t* out_len);

/**
 * @brief Retrieve enrolled fingerprint id list from fingerprint TA
 * @param.
 *
 */
EXTERNC TEE_Result TEE_GetFpList(uint8_t *idList, uint32_t *idListLen);

#endif // IFAA_OEM_H
