2
* Off-the-Record Messaging Toolkit
3
* Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of version 2 of the GNU General Public License as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
typedef struct s_KeyExchMsg {
26
unsigned char *raw; /* The base64-decoded data; must be free()d */
28
gcry_mpi_t p, q, g, e;
32
unsigned char *sigstart; /* Pointers into the "raw" array. Don't */
33
unsigned char *sigend; /* free() these. */
36
typedef struct s_DataMsg {
37
unsigned char *raw; /* The base64-decoded data; must be free()d */
40
unsigned int sender_keyid;
41
unsigned int rcpt_keyid;
44
unsigned char *encmsg; /* A copy; must be free()d */
46
unsigned char mac[20];
47
unsigned char *mackeys; /* A copy; must be free()d */
49
unsigned char *macstart; /* Pointers into the "raw" array. Don't */
50
unsigned char *macend; /* free() these. */
53
typedef struct s_CommitMsg {
54
unsigned char *raw; /* The base64-decoded data; must be free()d */
55
unsigned char *enckey;
57
unsigned char *hashkey;
61
typedef struct s_KeyMsg {
62
unsigned char *raw; /* The base64-decoded data; must be free()d */
66
typedef struct s_RevealSigMsg {
67
unsigned char *raw; /* The base64-decoded data; must be free()d */
70
unsigned char *encsig;
72
unsigned char mac[20];
75
typedef struct s_SignatureMsg {
76
unsigned char *raw; /* The base64-decoded data; must be free()d */
77
unsigned char *encsig;
79
unsigned char mac[20];
82
/* Dump an unsigned int to a FILE * */
83
void dump_int(FILE *stream, const char *title, unsigned int val);
85
/* Dump an mpi to a FILE * */
86
void dump_mpi(FILE *stream, const char *title, gcry_mpi_t val);
88
/* Dump data to a FILE * */
89
void dump_data(FILE *stream, const char *title, const unsigned char *data,
92
/* Parse a Key Exchange Message into a newly-allocated KeyExchMsg structure */
93
KeyExchMsg parse_keyexch(const char *msg);
95
/* Deallocate a KeyExchMsg and all of the data it points to */
96
void free_keyexch(KeyExchMsg keyexch);
98
/* Parse a D-H Commit Message into a newly-allocated CommitMsg structure */
99
CommitMsg parse_commit(const char *msg);
101
/* Parse a Data Message into a newly-allocated DataMsg structure */
102
DataMsg parse_datamsg(const char *msg);
104
/* Deallocate a CommitMsg and all of the data it points to */
105
void free_commit(CommitMsg cmsg);
107
/* Parse a Reveal Signature Message into a newly-allocated RevealSigMsg
109
RevealSigMsg parse_revealsig(const char *msg);
111
/* Deallocate a RevealSigMsg and all of the data it points to */
112
void free_revealsig(RevealSigMsg rmsg);
114
/* Parse a Signature Message into a newly-allocated SignatureMsg structure */
115
SignatureMsg parse_signature(const char *msg);
117
/* Deallocate a SignatureMsg and all of the data it points to */
118
void free_signature(SignatureMsg smsg);
120
/* Parse a D-H Key Message into a newly-allocated KeyMsg structure */
121
KeyMsg parse_key(const char *msg);
123
/* Deallocate a KeyMsg and all of the data it points to */
124
void free_key(KeyMsg cmsg);
126
/* Recalculate the MAC on the message, base64-encode the resulting MAC'd
127
* message, and put on the appropriate header and footer. Return a
128
* newly-allocated pointer to the result, which the caller will have to
130
char *remac_datamsg(DataMsg datamsg, unsigned char mackey[20]);
132
/* Assemble a new Data Message from its pieces. Return a
133
* newly-allocated string containing the base64 representation. */
134
char *assemble_datamsg(unsigned char mackey[20], int flags,
135
unsigned int sender_keyid, unsigned int rcpt_keyid, gcry_mpi_t y,
136
unsigned char ctr[8], unsigned char *encmsg, size_t encmsglen,
137
unsigned char *mackeys, size_t mackeyslen);
139
/* Deallocate a DataMsg and all of the data it points to */
140
void free_datamsg(DataMsg datamsg);
142
/* Convert a string of hex chars to a buffer of unsigned chars. */
143
void argv_to_buf(unsigned char **bufp, size_t *lenp, char *arg);