/**
 * \file crypto_kdf.h
 * \brief
 * \author Vladislav Kovalenko v.kovalenko@samsung.com
 * \author Vladyslav Figol v.figol@samsung.com
 * \version 1.0
 * \date Created Jan 22, 2014 12:15
 * \par In Samsung Ukraine R&D Center (SURC) under a contract between
 * \par LLC "Samsung Electronics Ukraine Company" (Kyiv, Ukraine) and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
 * \par Copyright: (c) Samsung Electronics Co, Ltd 2013. All rights reserved.
 **/

#ifndef CUSTOM_SO_H
#define CUSTOM_SO_H

#include <stdint.h>

#include "wsm_types.h"

#define AES_GCM_TAG_SIZE    AES_BLOCK_SIZE
#define get_so_size(data_size) (data_size + AES_GCM_TAG_SIZE + IV_KEY_SIZE)

/**
 * @brief crypto_kdf_gcm_encrypt - encrypt data with derived key and AES GCM
 * @param src       - src buffer with plain text
 * @param srcSize   - size of src buffer (in bytes)
 * @param dst       - dst buffer for wrapped text
 * @param dstSize   - size of dst buffer (in bytes)
 * @param id        - identifier for secure key generation.
 * @param id_len    - size of identifier for secure key generation.
 * @return E_SUCCESS if Ok, else error code
 */
return_t wrap_so(const uint8_t   *src, uint32_t        srcSize, uint8_t         *dst,
                 uint32_t        *dstSize, const uint8_t   *id, uint32_t        id_len);

/**
 * \brief crypto_kdf_gcm_encrypt - encrypt data with derived key and AES GCM
 * \param src       - src buffer with plain text
 * \param srcSize   - size of src buffer (in bytes)
 * \param dst       - dst buffer for wrapped text
 * \param dstSize   - size of dst buffer (in bytes)
 * \param id        - identifier for secure key generation.
 * \param id_len    - size of identifier for secure key generation.
 * \return E_SUCCESS if Ok, else error code
 */
return_t wrap_so2(const uint8_t          *src, uint32_t        srcSize, uint8_t         *dst,
                  uint32_t        *dstSize, const uint8_t   *id, uint32_t        id_len);

/**
 * @brief qsee_unwrap_so
 * @param src       - src buffer with wrapped text
 * @param srcSize   - size of src buffer (in bytes)
 * @param dst       - dst buffer for unwrapped text
 * @param dstSize   - size of dst buffer (in bytes)
 * @param id        - identifier for secure key generation.
 * @param id_len    - size of identifier for secure key generation.
 * @return E_SUCCESS if Ok, else error code
 */
return_t unwrap_so(const uint8_t   *src, uint32_t        srcSize, uint8_t         *dst,
                   uint32_t        *dstSize, const uint8_t   *id, uint32_t        id_len);

/**
 * @brief qsee_unwrap_so2 (for qsee vp1 and vp2 backward compatibility)
 * @param src       - src buffer with wrapped text
 * @param srcSize   - size of src buffer (in bytes)
 * @param dst       - dst buffer for unwrapped text
 * @param dstSize   - size of dst buffer (in bytes)
 * @param id        - identifier for secure key generation.
 * @param id_len    - size of identifier for secure key generation.
 * @return E_SUCCESS if Ok, else error code
 */
return_t unwrap_so2(const uint8_t   *src, uint32_t        srcSize, uint8_t         *dst,
                    uint32_t        *dstSize, const uint8_t   *id, uint32_t        id_len);

#endif // CUSTOM_SO_H
