1/*
2 * Off-the-Record Messaging library
3 * Copyright (C) 2004-2012 Ian Goldberg, Chris Alexander, Willy Lew,
4 * Lisa Du, Nikita Borisov
5 * <otr@cypherpunks.ca>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of version 2.1 of the GNU Lesser General
9 * Public License as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef __CONTEXT_PRIV_H__
22#define __CONTEXT_PRIV_H__
23
24#include <gcrypt.h>
25
26#include "dh.h"
27#include "auth.h"
28#include "sm.h"
29
30typedef struct context_priv {
31 /* The part of the fragmented message we've seen so far */
32 char *fragment;
33
34 /* The length of fragment */
35 size_t fragment_len;
36
37 /* The total number of fragments in this message */
38 unsigned short fragment_n;
39
40 /* The highest fragment number we've seen so far for this message */
41 unsigned short fragment_k;
42
43 /* current keyid used by other side; this is set to 0 if we get
44 * a OTRL_TLV_DISCONNECTED message from them. */
45 unsigned int their_keyid;
46
47 /* Y[their_keyid] (their DH pubkey) */
48 gcry_mpi_t their_y;
49
50 /* Y[their_keyid-1] (their prev DH pubkey) */
51 gcry_mpi_t their_old_y;
52
53 /* current keyid used by us */
54 unsigned int our_keyid;
55
56 /* DH key[our_keyid] */
57 DH_keypair our_dh_key;
58
59 /* DH key[our_keyid-1] */
60 DH_keypair our_old_dh_key;
61
62 /* sesskeys[i][j] are the session keys derived from DH
63 * key[our_keyid-i] and mpi Y[their_keyid-j] */
64 DH_sesskeys sesskeys[2][2];
65
66 /* saved mac keys to be revealed later */
67 unsigned int numsavedkeys;
68 unsigned char *saved_mac_keys;
69
70 /* generation number: increment every time we go private, and never
71 * reset to 0 (unless we remove the context entirely) */
72 unsigned int generation;
73
74 /* The last time a Data Message was sent */
75 time_t lastsent;
76
77 /* The last time a Data Message was received */
78 time_t lastrecv;
79
80 /* The plaintext of the last Data Message sent */
81 char *lastmessage;
82
83 /* Is the last message eligible for retransmission? */
84 int may_retransmit;
85
86} ConnContextPriv;
87
88/* Create a new private connection context. */
89ConnContextPriv *otrl_context_priv_new();
90
91/* Frees up memory that was used in otrl_context_priv_new */
92void otrl_context_priv_force_finished(ConnContextPriv *context_priv);
93
94#endif
95