/[pkg-mixmaster]/trunk/Mix/Src/mix3.h
ViewVC logotype

Contents of /trunk/Mix/Src/mix3.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98 - (show annotations) (download)
Mon Jul 22 17:54:48 2002 UTC (10 years, 10 months ago) by rabbi
File MIME type: text/plain
File size: 11632 byte(s)
Added support for AES in Type I messages. This should prevent lost mail if
a user attempts to send OpenPGP messages encrypted with AES.

Support for AES requires OpenSSL 0.9.7 (soon to be released.) The Install
script needs to be updated to enable AES if 0.9.7 or later is present.

Also, pgp_keylen now returns 0 instead of -1 for unknown symalgo. Output
of pgp_keylen is used in buf_appendrnd and in other functions without
checking, so they might be unhappy with -1. (We should really check for
this.)

Thanks to Disastry and Peter for working on this.
1 /* Mixmaster version 3 -- (C) 1999 Anonymizer Inc.
2
3 Mixmaster may be redistributed and modified under certain conditions.
4 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
5 ANY KIND, either express or implied. See the file COPYRIGHT for
6 details.
7
8 Function prototypes
9 $Id: mix3.h,v 1.6 2002/07/22 17:54:48 rabbi Exp $ */
10
11
12 #ifndef _MIX3_H
13 #define _MIX3_H
14 #define COPYRIGHT "Copyright Anonymizer Inc."
15
16 #include "config.h"
17 #include "mix.h"
18
19 #ifdef WIN32
20 #ifndef USE_SOCK
21 #define _WINSOCKAPI_ /* don't include winsock */
22 #endif
23 #include <windows.h>
24 #ifdef _MSC
25 #define snprintf _snprintf
26 #endif
27 #define DIRSEP '\\'
28 #define DIRSEPSTR "\\"
29 #else
30 #define DIRSEP '/'
31 #define DIRSEPSTR "/"
32 #endif
33
34 #define NOT_IMPLEMENTED {printf("Function not implemented.\n");return -1;}
35 #define SECONDSPERDAY 86400
36
37 /* Dynamically allocated buffers */
38
39 int buf_reset(BUFFER *buffer);
40 int buf_clear(BUFFER *buffer);
41 int buf_append(BUFFER *buffer, byte *mess, int len);
42 int buf_cat(BUFFER *to, BUFFER *from);
43 int buf_set(BUFFER *to, BUFFER *from);
44 int buf_rest(BUFFER *to, BUFFER *from);
45 int buf_appendrnd(BUFFER *to, int n);
46 int buf_appendzero(BUFFER *to, int n);
47 int buf_setc(BUFFER *buf, byte c);
48 int buf_appendc(BUFFER *to, byte b);
49 int buf_setrnd(BUFFER *b, int n);
50 int buf_setf(BUFFER *buffer, char *fmt, ...);
51 int buf_appendf(BUFFER *buffer, char *fmt, ...);
52 int buf_sets(BUFFER *buf, char *s);
53 int buf_appends(BUFFER *buffer, char *s);
54 int buf_nl(BUFFER *buffer);
55 int buf_pad(BUFFER *buffer, int size);
56 int buf_prepare(BUFFER *buffer, int size);
57 int buf_rewind(BUFFER *buffer);
58 int buf_getc(BUFFER *buffer);
59 void buf_ungetc(BUFFER *buffer);
60 int buf_get(BUFFER *buffer, BUFFER *to, int n);
61 int buf_getline(BUFFER *buffer, BUFFER *line);
62 int buf_chop(BUFFER *b);
63 void buf_move(BUFFER *dest, BUFFER *src);
64 byte *buf_data(BUFFER *buffer);
65 int buf_getheader(BUFFER *buffer, BUFFER *field, BUFFER *content);
66 int buf_appendheader(BUFFER *buffer, BUFFER *field, BUFFER *contents);
67 int buf_lookahead(BUFFER *buffer, BUFFER *line);
68 int buf_eq(BUFFER *b1, BUFFER *b2);
69 int buf_ieq(BUFFER *b1, BUFFER *b2);
70 void buf_cut_out(BUFFER *buffer, BUFFER *cut_out, BUFFER *rest,
71 int from, int len);
72
73 int buf_appendl(BUFFER *b, long l);
74 int buf_appendl_lo(BUFFER *b, long l);
75 long buf_getl(BUFFER *b);
76 long buf_getl_lo(BUFFER *b);
77 int buf_appendi(BUFFER *b, int i);
78 int buf_appendi_lo(BUFFER *b, int i);
79 int buf_geti(BUFFER *b);
80 int buf_geti_lo(BUFFER *b);
81
82 /* String comparison */
83 int strieq(const char *s1, const char *s2);
84 int strileft(const char *string, const char *keyword);
85 int striright(const char *string, const char *keyword);
86 int strifind(const char *string, const char *keyword);
87
88 int streq(const char *s1, const char *s2);
89 int strfind(const char *string, const char *keyword);
90 int strleft(const char *string, const char *keyword);
91
92 void strcatn(char *dest, const char *src, int n);
93
94 int bufleft(BUFFER *b, char *k);
95 int buffind(BUFFER *b, char *k);
96 int bufeq(BUFFER *b, char *k);
97
98 int bufileft(BUFFER *b, char *k);
99 int bufifind(BUFFER *b, char *k);
100 int bufiright(BUFFER *b, char *k);
101 int bufieq(BUFFER *b, char *k);
102
103 /* Utility functions */
104 void whoami(char *addr, char *defaultname);
105 int sendinfofile(char *name, char *log, BUFFER *address, BUFFER *subject);
106 int stats(BUFFER *out);
107 int conf(BUFFER *out);
108 void conf_premail(BUFFER *out);
109
110 void rfc822_addr(BUFFER *line, BUFFER *list);
111 void rfc822_name(BUFFER *line, BUFFER *name);
112 void sendmail_begin(void); /* begin mail sending session */
113 void sendmail_end(void); /* end mail sending session */
114 int sendmail(BUFFER *message, char *from, BUFFER *address);
115 int mixfile(char *path, const char *name);
116 int file_to_out(const char *name);
117 FILE *mix_openfile(const char *name, const char *a);
118 FILE *openpipe(const char *prog);
119 int closepipe(FILE *fp);
120
121 typedef struct {
122 char *name;
123 FILE *f;
124 } LOCK;
125
126 int lock(FILE *f);
127 int unlock(FILE *f);
128 LOCK *lockfile(char *filename);
129 int unlockfile(LOCK *lock);
130
131 int filtermsg(BUFFER *msg);
132 BUFFER *readdestblk( );
133 int doblock(BUFFER *line, BUFFER *filter, int logandreset);
134 int doallow(BUFFER *line, BUFFER *filter);
135 int allowmessage(BUFFER *in);
136
137 void errlog(int type, char *format,...);
138 void clienterr(BUFFER *msgbuf, char *err);
139 void logmail(char *mailbox, BUFFER *message);
140
141 void mix_status(char *fmt,...);
142 void mix_genericerror(void);
143
144 #define ERRORMSG 1
145 #define WARNING 2
146 #define NOTICE 3
147 #define LOG 4
148 #define DEBUGINFO 5
149
150 int decode(BUFFER *in, BUFFER *out);
151 int encode(BUFFER *b, int linelen);
152 void id_encode(byte id[], byte *s);
153 void id_decode(byte *s, byte id[]);
154
155 int decode_header(BUFFER *content);
156 int boundary(BUFFER *line, BUFFER *mboundary);
157 void get_parameter(BUFFER *content, char *attribute, BUFFER *value);
158 int get_type(BUFFER *content, BUFFER *type, BUFFER *subtype);
159 int mail_encode(BUFFER *in, int encoding);
160 int hdr_encode(BUFFER *in, int n);
161 int attachfile(BUFFER *message, BUFFER *filename);
162 int pgpmime_sign(BUFFER *message, BUFFER *uid, BUFFER *pass, char *secring);
163 int mime_attach(BUFFER *message, BUFFER *attachment, BUFFER *type);
164 void mimedecode(BUFFER *msg);
165 int qp_decode_message(BUFFER *msg);
166
167 #define MIME_8BIT 1 /* transport is 8bit */
168 #define MIME_7BIT 2 /* transport is 7bit */
169
170 /* randomness */
171 int rnd_bytes(byte *b, int n);
172 byte rnd_byte(void);
173 int rnd_number(int n);
174 int rnd_add(byte *b, int l);
175 int rnd_seed(void);
176 void rnd_time(void);
177
178 int rnd_init(void);
179 int rnd_final(void);
180 void rnd_error(void);
181
182 #define RND_QUERY 0
183 #define RND_NOTSEEDED -1
184 #define RND_SEEDED 1
185 #define RND_WILLSEED 2
186 extern int rnd_state; /* flag for PRNG status */
187
188 /* compression */
189 int buf_compress(BUFFER *b);
190 int buf_zip(BUFFER *out, BUFFER *in, int bits);
191 int buf_uncompress(BUFFER *b);
192 int buf_unzip(BUFFER *b, int type);
193
194 /* crypto functions */
195 int digest_md5(BUFFER *b, BUFFER *md);
196 int isdigest_md5(BUFFER *b, BUFFER *md);
197 int digestmem_md5(byte *b, int n, BUFFER *md);
198 int digest_sha1(BUFFER *b, BUFFER *md);
199 int digest_rmd160(BUFFER *b, BUFFER *md);
200
201 int keymgt(int force);
202 int key(BUFFER *b);
203 int adminkey(BUFFER *b);
204
205 #define ENCRYPT 1
206 #define DECRYPT 0
207 int buf_crypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
208
209 #ifdef USE_IDEA
210 int buf_ideacrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
211 #endif
212 int buf_bfcrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
213 int buf_3descrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
214 int buf_castcrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
215 #ifdef USE_AES
216 int buf_aescrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
217 #endif
218
219 int db_getseckey(byte keyid[], BUFFER *key);
220 int db_getpubkey(byte keyid[], BUFFER *key);
221 int pk_decrypt(BUFFER *encrypted, BUFFER *privkey);
222 int pk_encrypt(BUFFER *plaintext, BUFFER *privkey);
223 int check_seckey(BUFFER *buf, const byte id[]);
224 int check_pubkey(BUFFER *buf, const byte id[]);
225 int v2createkey(void);
226 int seckeytopub(BUFFER *pub, BUFFER *sec, byte keyid[]);
227
228 /* configuration, general remailer functions */
229 int mix_configline(char *line);
230 int mix_initialized(void);
231 int mix_daily(void);
232
233 /* message pool */
234 #define INTERMEDIATE 0
235 int pool_send(void);
236 int pool_read(BUFFER *pool);
237 int pool_add(BUFFER *msg, char *type);
238 FILE *pool_new(char *type, char *tmpname, char *path);
239 int mix_pool(BUFFER *msg, int type, long latent);
240 int pool_packetfile(char *fname, BUFFER *mid, int packetnum);
241 void pool_packetexp(void);
242 int idexp(void);
243 void pop3get(void);
244
245 typedef struct { /* added for binary id.log change */
246 char id[16];
247 long time;
248 } idlog_t;
249
250 /* statistics */
251 int stats_log(int);
252 int stats_out(int);
253
254 /* OpenPGP */
255 int pgp_keymgt(int force);
256 int pgp_armor(BUFFER *buf, int mode);
257 int pgp_dearmor(BUFFER *buf, BUFFER *out);
258 int pgp_pubkeycert(BUFFER *userid, char *keyring, BUFFER *pass,
259 BUFFER *out, int remail);
260 int pgp_signtxt(BUFFER *msg, BUFFER *uid, BUFFER *pass,
261 char *secring, int remail);
262 int pgp_isconventional(BUFFER *buf);
263 int pgp_mailenc(int mode, BUFFER *msg, char *sigid,
264 BUFFER *pass, char *pubring, char *secring);
265 int pgp_signhashalgo(BUFFER *algo, BUFFER *userid, char *secring,
266 BUFFER *pass);
267
268 /* menu */
269 int menu_initialized;
270 void menu_main(void);
271 void menu_folder(char command, char *name);
272 int menu_getuserpass(BUFFER *p, int mode);
273
274 int user_pass(BUFFER *b);
275 int user_confirmpass(BUFFER *b);
276 void user_delpass(void);
277
278 /* remailer */
279 typedef struct {
280 char name[20];
281 int version;
282 char addr[128];
283 byte keyid[16];
284 struct {
285 unsigned int mix:1;
286 unsigned int compress:1;
287
288 unsigned int cpunk:1;
289 unsigned int pgp:1;
290 unsigned int pgponly:1;
291 unsigned int latent:1;
292 unsigned int hash:1;
293 unsigned int ek:1;
294 unsigned int esub:1;
295
296 unsigned int nym:1;
297 unsigned int newnym:1;
298
299 unsigned int post:1;
300 unsigned int middle:1;
301 } flags;
302 struct rinfo {
303 int reliability;
304 int latency;
305 char history[13];
306 } info[2];
307 } REMAILER;
308
309 #define CHAINMAX 421
310 #define MAXREM 100
311 int mix2_rlist(REMAILER remailer[]);
312 int t1_rlist(REMAILER remailer[]);
313 int pgp_rlist(REMAILER remailer[], int n);
314 int chain_select(int hop[], char *chainstr, int maxrem, REMAILER *remailer,
315 int type, BUFFER *feedback);
316 int chain_rand(REMAILER *remailer, int maxrem,
317 int thischain[], int chainlen, int t);
318 int chain_randfinal(int type, REMAILER *remailer, int maxrem, int t);
319
320 float chain_reliability(char *chain, int chaintype,
321 char *reliability_string);
322 int mix2_encrypt(int type, BUFFER *message, char *chainstr, int numcopies,
323 BUFFER *feedback);
324 int t1_encrypt(int type, BUFFER *message, char *chainstr, int latency,
325 BUFFER *ek, BUFFER *feedback);
326
327 int t1_getreply(BUFFER *msg, BUFFER *ek, int len);
328
329 int t1_decrypt(BUFFER *in);
330 int t2_decrypt(BUFFER *in);
331
332 int mix2_decrypt(BUFFER *m);
333 int mix3_decrypt(BUFFER *m);
334
335 /* type 2 */
336 #define MAGIC0 0
337 #define MAGIC1 3
338
339 int v3_magic(byte *b);
340 int v2body(BUFFER *body);
341 int v2body_setlen(BUFFER *body);
342 int v2partial(BUFFER *body, BUFFER *mid, int packet, int numpackets);
343 int v2_merge(BUFFER *mid);
344 int mix_armor(BUFFER *in);
345 int mix_dearmor(BUFFER *armored, BUFFER *bin);
346
347 /* type 1 */
348 #define HDRMARK "::"
349 #define EKMARK "**"
350 #define HASHMARK "##"
351 int isline(BUFFER *line, char *text);
352
353 /* nym database */
354
355 #define NYM_WAITING 0
356 #define NYM_OK 1
357 #define NYM_DELETED 2
358 #define NYM_ANY -1
359
360 int nymlist_read(BUFFER *n);
361 int nymlist_write(BUFFER *list);
362 int nymlist_get(BUFFER *list, char *nym, BUFFER *config, BUFFER *ek,
363 BUFFER *options, BUFFER *name, BUFFER *rblocks, int *status);
364 int nymlist_append(BUFFER *list, char *nym, BUFFER *config, BUFFER *options,
365 BUFFER *name, BUFFER *chains, BUFFER *eklist, int status);
366 int nymlist_del(BUFFER *list, char *nym);
367 int nymlist_getnym(char *nym, BUFFER *config, BUFFER *ek, BUFFER *opt,
368 BUFFER *name, BUFFER *rblocks);
369 int nymlist_getstatus(char *nym);
370
371 /* Visual C lacks dirent */
372 #ifdef _MSC
373 typedef HANDLE DIR;
374
375 struct dirent {
376 char d_name[PATHMAX];
377 };
378
379 DIR *opendir(const char *name);
380 struct dirent *readdir(DIR *dir);
381 int closedir(DIR *dir);
382 #endif
383
384 /* sockets */
385 #if defined(WIN32) && defined(USE_SOCK)
386 #include <winsock.h>
387 int sock_init(void);
388 void sock_exit(void);
389
390 #else
391 typedef int SOCKET;
392
393 #define INVALID_SOCKET -1
394 SOCKET opensocket(char *hostname, int port);
395 int closesocket(SOCKET s);
396
397 #endif
398
399 #ifdef WIN32
400 int is_nt_service(void);
401 void set_nt_exit_event();
402 #endif
403
404 /* check for memory leaks */
405 #ifdef DEBUG
406 #define malloc mix3_malloc
407 #define free mix3_free
408 BUFFER *mix3_bufnew(char *, int, char*);
409 #if __GNUC__ >= 2
410 # define buf_new() mix3_bufnew(__FILE__, __LINE__, __PRETTY_FUNCTION__)
411 #else
412 # define buf_new() mix3_bufnew(__FILE__, __LINE__, "file")
413 #endif
414 #endif /* DEBUG */
415
416 #endif

  ViewVC Help
Powered by ViewVC 1.1.5