~ubuntu-branches/ubuntu/trusty/libotr2/trusty

« back to all changes in this revision

Viewing changes to toolkit/parse.h

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2012-11-05 01:06:26 UTC
  • Revision ID: package-import@ubuntu.com-20121105010626-4m3hldpaz3jfr3wb
Tags: upstream-3.2.1
ImportĀ upstreamĀ versionĀ 3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Off-the-Record Messaging Toolkit
 
3
 *  Copyright (C) 2004-2008  Ian Goldberg, Chris Alexander, Nikita Borisov
 
4
 *                           <otr@cypherpunks.ca>
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 */
 
19
 
 
20
#ifndef __PARSE_H__
 
21
#define __PARSE_H__
 
22
 
 
23
#include <gcrypt.h>
 
24
 
 
25
typedef struct s_KeyExchMsg {
 
26
    unsigned char *raw;         /* The base64-decoded data; must be free()d */
 
27
    unsigned char reply;
 
28
    gcry_mpi_t p, q, g, e;
 
29
    unsigned int keyid;
 
30
    gcry_mpi_t y;
 
31
    gcry_mpi_t r, s;
 
32
    unsigned char *sigstart;    /* Pointers into the "raw" array.  Don't */
 
33
    unsigned char *sigend;      /*   free() these. */
 
34
} * KeyExchMsg;
 
35
 
 
36
typedef struct s_DataMsg {
 
37
    unsigned char *raw;         /* The base64-decoded data; must be free()d */
 
38
    size_t rawlen;
 
39
    int flags;
 
40
    unsigned int sender_keyid;
 
41
    unsigned int rcpt_keyid;
 
42
    gcry_mpi_t y;
 
43
    unsigned char ctr[8];
 
44
    unsigned char *encmsg;      /* A copy; must be free()d */
 
45
    size_t encmsglen;
 
46
    unsigned char mac[20];
 
47
    unsigned char *mackeys;     /* A copy; must be free()d */
 
48
    size_t mackeyslen;
 
49
    unsigned char *macstart;    /* Pointers into the "raw" array.  Don't */
 
50
    unsigned char *macend;      /*   free() these. */
 
51
} * DataMsg;
 
52
 
 
53
typedef struct s_CommitMsg {
 
54
    unsigned char *raw;         /* The base64-decoded data; must be free()d */
 
55
    unsigned char *enckey;
 
56
    size_t enckeylen;
 
57
    unsigned char *hashkey;
 
58
    size_t hashkeylen;
 
59
} * CommitMsg;
 
60
 
 
61
typedef struct s_KeyMsg {
 
62
    unsigned char *raw;         /* The base64-decoded data; must be free()d */
 
63
    gcry_mpi_t y;
 
64
} * KeyMsg;
 
65
 
 
66
typedef struct s_RevealSigMsg {
 
67
    unsigned char *raw;         /* The base64-decoded data; must be free()d */
 
68
    unsigned char *key;
 
69
    size_t keylen;
 
70
    unsigned char *encsig;
 
71
    size_t encsiglen;
 
72
    unsigned char mac[20];
 
73
} * RevealSigMsg;
 
74
 
 
75
typedef struct s_SignatureMsg {
 
76
    unsigned char *raw;         /* The base64-decoded data; must be free()d */
 
77
    unsigned char *encsig;
 
78
    size_t encsiglen;
 
79
    unsigned char mac[20];
 
80
} * SignatureMsg;
 
81
 
 
82
/* Dump an unsigned int to a FILE * */
 
83
void dump_int(FILE *stream, const char *title, unsigned int val);
 
84
 
 
85
/* Dump an mpi to a FILE * */
 
86
void dump_mpi(FILE *stream, const char *title, gcry_mpi_t val);
 
87
 
 
88
/* Dump data to a FILE * */
 
89
void dump_data(FILE *stream, const char *title, const unsigned char *data,
 
90
        size_t datalen);
 
91
 
 
92
/* Parse a Key Exchange Message into a newly-allocated KeyExchMsg structure */
 
93
KeyExchMsg parse_keyexch(const char *msg);
 
94
 
 
95
/* Deallocate a KeyExchMsg and all of the data it points to */
 
96
void free_keyexch(KeyExchMsg keyexch);
 
97
 
 
98
/* Parse a D-H Commit Message into a newly-allocated CommitMsg structure */
 
99
CommitMsg parse_commit(const char *msg);
 
100
 
 
101
/* Parse a Data Message into a newly-allocated DataMsg structure */
 
102
DataMsg parse_datamsg(const char *msg);
 
103
 
 
104
/* Deallocate a CommitMsg and all of the data it points to */
 
105
void free_commit(CommitMsg cmsg);
 
106
 
 
107
/* Parse a Reveal Signature Message into a newly-allocated RevealSigMsg
 
108
 * structure */
 
109
RevealSigMsg parse_revealsig(const char *msg);
 
110
 
 
111
/* Deallocate a RevealSigMsg and all of the data it points to */
 
112
void free_revealsig(RevealSigMsg rmsg);
 
113
 
 
114
/* Parse a Signature Message into a newly-allocated SignatureMsg structure */
 
115
SignatureMsg parse_signature(const char *msg);
 
116
 
 
117
/* Deallocate a SignatureMsg and all of the data it points to */
 
118
void free_signature(SignatureMsg smsg);
 
119
 
 
120
/* Parse a D-H Key Message into a newly-allocated KeyMsg structure */
 
121
KeyMsg parse_key(const char *msg);
 
122
 
 
123
/* Deallocate a KeyMsg and all of the data it points to */
 
124
void free_key(KeyMsg cmsg);
 
125
 
 
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
 
129
 * free(). */
 
130
char *remac_datamsg(DataMsg datamsg, unsigned char mackey[20]);
 
131
 
 
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);
 
138
 
 
139
/* Deallocate a DataMsg and all of the data it points to */
 
140
void free_datamsg(DataMsg datamsg);
 
141
 
 
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);
 
144
 
 
145
#endif