/**
* \file cryptoEngine.h
* \brief Crypto wrapper interface of low-lovel implementations.
* \author Sergey Tolochko (s.tolochko@samsung.com)
* \version 0.1
* \date Created Oct 08, 2015
* \par In Samsung Ukraine R&D Center (SURC) under a contract between
* \par LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine) and
* \par "Samsung Elecrtronics Co", Ltd (Seoul, Republic of Korea)
* \par Copyright: (c) Samsung Electronics Co, Ltd 2012. All rights reserved.
**/

#ifndef __CRYPTO_API_H_INCLUDED__
#define __CRYPTO_API_H_INCLUDED__

#include <stdint.h>
#include <stddef.h>

#define EC_POINT_CONVERSION_UNCOMPRESSED 4

typedef void* crypto_t;

struct KeyGenInfo {
	uint32_t keyLen;
	uint32_t exponent;
};

typedef crypto_t (*new_func)(void);
typedef void (*free_func)(crypto_t);
typedef int32_t (*size_func)(crypto_t);
typedef int32_t (*generate_func)(crypto_t, const struct KeyGenInfo*);
typedef int32_t (*sign_func)(int32_t, const uint8_t *, uint32_t, uint8_t *, uint32_t *, crypto_t);
typedef int32_t (*verify_func)(int32_t, const uint8_t*, uint32_t, const uint8_t*, uint32_t, crypto_t);
typedef int32_t (*populate_func)(crypto_t*, const uint8_t *, size_t, const uint8_t *, size_t,
                                            const uint8_t *, size_t );
typedef int32_t (*encrypt_func)(crypto_t, int32_t, const uint8_t *, uint8_t *, int32_t);
typedef int32_t (*decrypt_func)(crypto_t, int32_t, const uint8_t *, uint8_t *, int32_t);

typedef struct __crypto_handlers_t {
    new_func        new;
    free_func       free;
    generate_func	generate;
    size_func       size;
    sign_func      	sign;
    verify_func    	verify;
    populate_func   populate;
    encrypt_func    public_encrypt;
    decrypt_func    private_decrypt;
} CRYPTO_API;

void CRYPTO_init(void);

CRYPTO_API CRYPTO_get_api(uint32_t type);

// Low-level accessors

int32_t CRYPTO_EC_get_public_key(const crypto_t ec, uint8_t **x, uint32_t *xlen, 
                                                uint8_t **y, uint32_t *ylen);
int32_t CRYPTO_EC_get_private_key(const crypto_t ec, uint8_t **prk, uint32_t *len);

int32_t CRYPTO_RSA_get_modulus(const crypto_t rsa, uint8_t **data, int32_t *len);
int32_t CRYPTO_RSA_get_public_exponent(const crypto_t rsa, uint8_t **data, int32_t *len);
int32_t CRYPTO_RSA_get_private_exponent(const crypto_t rsa, uint8_t **data, int32_t *len);
int32_t CRYPTO_RSA_get_prime1(const crypto_t rsa, uint8_t **data, int32_t *len);
int32_t CRYPTO_RSA_get_prime2(const crypto_t rsa, uint8_t **data, int32_t *len);
int32_t CRYPTO_RSA_get_exponent1(const crypto_t rsa, uint8_t **data, int32_t *len);
int32_t CRYPTO_RSA_get_exponent2(const crypto_t rsa, uint8_t **data, int32_t *len);
int32_t CRYPTO_RSA_get_coefficient(const crypto_t rsa, uint8_t **data, int32_t *len);

#endif /* __CRYPTO_API_H_INCLUDED__ */
