Bump version to 0.5.9
[novacoin.git] / src / cryptogram.cpp
1 /**
2  * @file /cryptron/secure.c
3  *
4  * @brief Functions for handling the secure data type.
5  *
6  * $Author: Ladar Levison $
7  * $Website: http://lavabit.com $
8  *
9  */
10
11 #include "ies.h"
12 #define HEADSIZE (sizeof(cryptogram_head_t))
13
14 size_t cryptogram_key_length(const cryptogram_t *cryptogram) {
15         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
16         return head->length.key;
17 }
18
19 size_t cryptogram_mac_length(const cryptogram_t *cryptogram) {
20         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
21         return head->length.mac;
22 }
23
24 size_t cryptogram_body_length(const cryptogram_t *cryptogram) {
25         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
26         return head->length.body;
27 }
28
29 size_t cryptogram_data_sum_length(const cryptogram_t *cryptogram) {
30         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
31         return (head->length.key + head->length.mac + head->length.body);
32 }
33
34 size_t cryptogram_total_length(const cryptogram_t *cryptogram) {
35         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
36         return HEADSIZE + (head->length.key + head->length.mac + head->length.body);
37 }
38
39 unsigned char * cryptogram_key_data(const cryptogram_t *cryptogram) {
40         return (unsigned char *)cryptogram + HEADSIZE;
41 }
42
43 unsigned char * cryptogram_mac_data(const cryptogram_t *cryptogram) {
44         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
45         return (unsigned char *)cryptogram + (HEADSIZE + head->length.key + head->length.body);
46 }
47
48 unsigned char * cryptogram_body_data(const cryptogram_t *cryptogram) {
49         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
50         return (unsigned char *)cryptogram + (HEADSIZE + head->length.key);
51 }
52
53 cryptogram_t * cryptogram_alloc(size_t key, size_t mac, size_t body) {
54         cryptogram_t *cryptogram = (cryptogram_t *) malloc(HEADSIZE + key + mac + body);
55         cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
56         head->length.key = key;
57         head->length.mac = mac;
58         head->length.body = body;
59         return cryptogram;
60 }
61
62 void cryptogram_free(cryptogram_t *cryptogram) {
63         free(cryptogram);
64         return;
65 }