/**
* \file keyManager.h
* \brief Key management functions.
* \author Dmytro Podgornyi (d.podgornyi@samsung.com)
* \version 0.1
* \date Created May 28, 2013
* \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 __KEY_MANAGER_H_INCLUDED__
#define __KEY_MANAGER_H_INCLUDED__

#include <stdint.h>
#include <stddef.h>

/* DRK blob key types */
typedef enum
{
    /* RSA key */
    RSA_KEY = 0x10,
    /* Symmetric key */
    SYMM_KEY = 0x20,
    /* Elliptic key */
    EC_SK_KEY = 0x40,
    /* EC key */
    ECC_KEY = 0x80,
    /* HSM RSA key */
    RSA_ENC_KEY = 0x100,
} ProvAgentKeys_t;

typedef struct key_t KEY;

struct KeyGenInfo;
KEY* KEY_new(uint32_t type);
void KEY_free(KEY* key);
int32_t KEY_signature_size(const KEY* key);
int32_t KEY_generate_key(KEY* key, const struct KeyGenInfo *info);
int32_t KEY_populate_keys(KEY* key, const uint8_t *pubkey, size_t pubkeylen,
                            const uint8_t *prkey, size_t prkeylen);
int32_t KEY_populate_keypair(KEY* key, const uint8_t *keypair, size_t keypairLen);
int32_t KEY_check_keypair(KEY* key);

int32_t KEY_sign(KEY *key, int32_t digestId, uint8_t *digest, uint32_t digestLen, 
                 uint8_t *signature, uint32_t *signatureLen);
int32_t KEY_verify(KEY* key, int32_t digestId, uint8_t *digest, uint32_t digestLen,
                uint8_t *signature, uint32_t signatureLen);

int32_t KEY_build_keypair(const KEY *key, uint8_t *out, uint32_t *outLen);
int32_t KEY_build_public(const KEY *key, uint8_t *out, uint32_t *outLen);

int32_t KEY_public_encrypt(const KEY *key, int32_t len, const uint8_t *from, uint8_t *to, int32_t padding);
int32_t KEY_private_decrypt(const KEY *key, int32_t len, const uint8_t *from, uint8_t *to, int32_t padding);

#endif /* __KEY_MANAGER_H_INCLUDED__ */
