EXPERIMENTAL: custom peer collector
[novacoin.git] / src / ies.h
1 /**
2  * reference: ecies.h
3  */
4
5 #ifndef _IES_H_
6 #define _IES_H_
7
8 #include <openssl/ssl.h>
9 #include <openssl/crypto.h>
10 #include <openssl/err.h>
11
12 typedef struct {
13     const EVP_CIPHER *cipher;
14     const EVP_MD *md;                 /* for mac tag */
15     const EVP_MD *kdf_md;         /* for KDF */
16     size_t stored_key_length;
17     const EC_KEY *user_key;
18 } ies_ctx_t;
19
20 typedef struct {
21     struct {
22         size_t key;
23         size_t mac;
24         size_t body;
25     } length;
26 } cryptogram_head_t;
27
28 typedef unsigned char * cryptogram_t;
29
30 void cryptogram_free(cryptogram_t *cryptogram);
31 unsigned char * cryptogram_key_data(const cryptogram_t *cryptogram);
32 unsigned char * cryptogram_mac_data(const cryptogram_t *cryptogram);
33 unsigned char * cryptogram_body_data(const cryptogram_t *cryptogram);
34 size_t cryptogram_key_length(const cryptogram_t *cryptogram);
35 size_t cryptogram_mac_length(const cryptogram_t *cryptogram);
36 size_t cryptogram_body_length(const cryptogram_t *cryptogram);
37 size_t cryptogram_data_sum_length(const cryptogram_t *cryptogram);
38 size_t cryptogram_total_length(const cryptogram_t *cryptogram);
39 cryptogram_t * cryptogram_alloc(size_t key, size_t mac, size_t body);
40 cryptogram_t * ecies_encrypt(const ies_ctx_t *ctx, const unsigned char *data, size_t length, char *error);
41 unsigned char * ecies_decrypt(const ies_ctx_t *ctx, const cryptogram_t *cryptogram, size_t *length, char *error);
42 ies_ctx_t *create_context(EC_KEY *user_key);
43
44 #endif /* _IES_H_ */