
/*
 * =====================================================================================
 *
 *       Filename:  pebble_platform_interface.h
 *
 *    Description:  PEBBLE wrap/unwrap and AES encrypt/decrypt
 *
 *        Version:  1.0
 *        Created:  08/16/2020
 *       Revision:  none
 *       Compiler:  gcc
 *
 *        Company:  Samsung Electronics
 *        Copyright (c) 2020 by Samsung Electronics, All rights reserved.
 *
 * =====================================================================================
 */

#ifndef _PEBBLE_PLATFORM_INTERFACE_H_
#define _PEBBLE_PLATFORM_INTERFACE_H_

#include "tees_secure_object.h"

/**
 * PEBBLE includes
 */
#include "TZ_Vendor_tl.h"
#include "tz_pebble_interface.h"
#include "pebble_defs.h"
#include "pebble_hmac.h"

/**
 * Unwrap
 */
#define PEBBLE_UNWRAP_PROV_UUID                 {0,0,0,{0,0,0x50,0x65,0x42,0x62,0x6c,0x45}}
#define PEBBLE_UNWRAP_PROV_TA_AUTH_CRYPTOSUITE  "samsung_ta"

/**
 * @brief
 * unwrap
 *
 * @param[in]  *wrapped_ptr         - wrapped object
 * @param[in]  *wrapped_ptr_len     - wrapped object length
 * @param[in]  is_wrapped_key       - is wrapped object (only for QC)
 * @param[out] *unwrapped_ptr       - unwrapped object
 * @param[out] *unwrapped_ptr_len   - unwrapped object length
 *
 * @return PEBBLE status code
 */
pebble_return_code_t unwrap(uint8_t *wrapped_ptr, uint32_t *wrapped_ptr_len, uint32_t is_wrapped_key, uint8_t *unwrapped_ptr, uint32_t *unwrapped_ptr_len);

/**
 * @brief
 * wrap
 *
 * @param[in] *unwrapped_ptr    - wrapped object
 * @param[in] unwrapped_ptr_len - wrapped object length
 * @param[out] *wrapped_ptr     - wrapped object
 * @param[out] *wrapped_ptr_len - wrapped object length
 *
 * @return PEBBLE status code
 */
pebble_return_code_t wrap(uint8_t *unwrapped_ptr, uint32_t unwrapped_ptr_len, uint8_t *wrapped_ptr, uint32_t *wrapped_ptr_len);

/**
 * @brief
 * aes_encrypt_with_params -  platform interface to
 * TZ_Vendor_tl.c: TZ_aes_encrypt_with_params
 *
 * @param[in]   *encKey         - key
 * @param[in]   encKeyLen       - key length
 * @param[in]   *plaintext      - data to be encrypted
 * @param[in]   plaintextLen    - data length
 * @param[out]  *ciphertext     - encrypted data
 * @param[out]  *pCiphertextLen - length of encrypted data
 * @param[in]   mode            - cipher mode (EBC/CBC)
 * @param[in]   pad             - padding scheme (ISO10126/PKCS7/NO PAD)
 * @param[in]   *piv            - initial vector
 * @param[in]   iv_size         - length of initial vector
 *
 * @return status code
 */
uint32_t aes_encrypt_with_params(
    uint8_t * enckey,
    uint32_t encKeyLen,
    uint8_t * plaintext,
    uint32_t plaintextLen,
    uint8_t * ciphertext,
    uint32_t * pCiphertextLen,
    CIPHER_MODE_ET mode,
    CIPHER_PAD_ET pad,
    uint8_t * piv,
    uint32_t iv_size
);

/**
 * @brief
 * aes_decrypt_with_params - platform interface to
 * TZ_Vendor_tl.c: TZ_aes_decrypt_with_params
 *
 * @param[in]   *decKey         - key
 * @param[in]   decKeyLen       - key length
 * @param[in]   *ciphertext     - data to be decrypted
 * @param[in]   *pCiphertextLen - lenght of data to be decrypted
 * @param[out]  *plaintext      - decrypted data
 * @param[out]  * plaintextLen  - length of decrypted data
 * @param[in]   mode            - cipher mode (EBC/CBC)
 * @param[in]   pad             - padding scheme (ISO10126/PKCS7/NO PAD)
 * @param[in]   *piv            - initial vector
 * @param[in]   iv_size         - length of initial vector
 *
 * @return status code
 */
uint32_t aes_decrypt_with_params(
    uint8_t * deckey,
    uint32_t decKeyLen,
    uint8_t * ciphertext,
    uint32_t ciphertextLen,
    uint8_t * plaintext,
    uint32_t * pPlaintextLen,
    CIPHER_MODE_ET mode,
    CIPHER_PAD_ET pad,
    uint8_t * piv,
    uint32_t iv_size
);
#endif /* _PEBBLE_PLATFORM_INTERFACE_H_ */
