2 * @file /cryptron/secure.c
4 * @brief Functions for handling the secure data type.
6 * $Author: Ladar Levison $
7 * $Website: http://lavabit.com $
12 #define HEADSIZE (sizeof(cryptogram_head_t))
14 size_t cryptogram_key_length(const cryptogram_t *cryptogram) {
15 cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
16 return head->length.key;
19 size_t cryptogram_mac_length(const cryptogram_t *cryptogram) {
20 cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
21 return head->length.mac;
24 size_t cryptogram_body_length(const cryptogram_t *cryptogram) {
25 cryptogram_head_t *head = (cryptogram_head_t *)cryptogram;
26 return head->length.body;
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);
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);
39 unsigned char * cryptogram_key_data(const cryptogram_t *cryptogram) {
40 return (unsigned char *)cryptogram + HEADSIZE;
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);
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);
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;
62 void cryptogram_free(cryptogram_t *cryptogram) {