#ifndef DK_ABSTRACTION_H_
#define DK_ABSTRACTION_H_

#include <tee_internal_api.h>

/**
 * Allocates n bytes of contiguous memory. 
 * The specific behaviour is platform dependent, please check your platform
 * implementation for further details.
 * 
 * @param n The number of bytes to be allocated
 * 
 * @return A pointer to the beggining of allocated memery region or NULL if 
 * allocation failed.
*/
void* dk_malloc(size_t n);

/**
 * Changes the size of a previously allocated memory region to n bytes.
 * The specific behaviour is platform dependent, please check your platform
 * implementation for further details.
 * 
 * @param p A pointer to the beginning of a previously allocated memory region
 * @param n The number of bytes to be allocated
*/
void  dk_realloc(void* p, size_t n);

/**
 * Frees a previously allocated memory region. 
 * The specific behaviour is platform dependent, please check your platform
 * implementation for further details.
 * 
 * @param p A pointer to the beginning of a previously allocated memory region
*/
void  dk_free(void* p);

/**
 * Copies n bytes from a source buffer to a destination buffer. 
 * The specific behaviour is platform dependent, please check your platform
 * implementation for further details.
 * 
 * @param dest The destination buffer
 * @param src The source buffer
 * @param size The number of bytes being copied
*/
void  dk_memcpy(void* dest, void* src, size_t size);

/**
 * Sets the size first bytes of a buffer to value. 
 * The specific behaviour is platform dependent, please check your platform
 * implementation for further details.
 * 
 * @param dest The destination buffer
 * @param value The desired value
 * @param size The number of bytes being set
*/
void  dk_memset(void* dest, uint32_t value, size_t size);

/**
 * Compares the first n bytes of two buffers. 
 * The specific behaviour is platform dependent, please check your platform
 * implementation for further details.
 * 
 * @param buffer1 The first buffer
 * @param buffer2 The second buffer
 * @param size The number of bytes compared
*/
int   dk_memcmp(void* buffer1, void* buffer2, size_t size);

/**
 * Generated length random bytes and stores them in out. 
 * The specific behaviour is platform dependent, please check your platform
 * implementation for further details.
 * 
 * @param out The destination buffer
 * @param length The number of bytes being generated
*/
void dk_generate_random(void *out, uint32_t length);

// crypto?
// TODO: dk_rand?

#endif