File: mix.h

package info (click to toggle)
mixmaster 3.0b2-4
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 1,356 kB
  • ctags: 1,173
  • sloc: ansic: 18,314; sh: 1,285; yacc: 698; perl: 314; makefile: 161
file content (915 lines) | stat: -rw-r--r-- 25,169 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
/* Mixmaster version 3.0  --  (C) 1999 - 2004 Anonymizer Inc. and others.

   Mixmaster may be redistributed and modified under certain conditions.
   This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
   ANY KIND, either express or implied. See the file COPYRIGHT for
   details.


   Mixmaster Library API
   =====================

The Mixmaster library consists of a set of high-level functions that
generate or process remailer messages, lower-level functions that
manipulate data in various ways, and a number of functions that
provide an interface to the underlying cryptographic library.
Generally, a return value of 0 indicates success, and -1 an error.


Initialization
==============

int mix_init(char mixdir[]);

  This function initializes internal data of the Mixmaster library,
  such as the random number generator. This should be the first call
  to the Mixmaster library. It returns 0 on success. If the random
  number generator cannot be initialized, mix_init() terminates.

  The variable mixdir determines where the Mixmaster configuration
  files and the message pool are located. If mixdir is NULL, the
  library will use the directory specified in the environment variable
  $MIXPATH, the directory given at compile time if it exists, and the
  directory ~/Mix otherwise.


void mix_exit(void);

  A program must call mix_exit before exiting. This function writes back
  the state of the random number generator.


Using the Mixmaster DLL
=======================

In textmode applications, mix_init() can be used as described above.
In graphical applications, these functions are not needed. Instead,
the function rnd_mouse() should be called whenever the program gets
WM_MOUSEMOVE or other messages:

int rnd_mouse(UINT i, WPARAM w, LPARAM l);

  All events that a window gets may be passed to this function. It
  will extract the inherent randomness in user interaction, especially
  in mouse movements. It returns 100 if it has accumulated enough
  randomness to perform cryptographic operations, and a number between
  0 and 99 otherwise. This number can be used to provide graphical
  feedback on the progress of initializing the random number generator
  while asking the user to move the mouse. A runtime error will occur
  if any cryptographic functions are used before rnd_mouse() has
  signaled success.


Message I/O
===========

The library uses dynamically allocated buffers for messages and other
data. Functions for buffer manipulation are described in section
"Buffers" below.


BUFFER *buf_new(void);

  Buffers must be initialized before they can be used. buf_new() returns
  a pointer to a newly initialized buffer.


int buf_free(BUFFER *buf);

  When a buffer is no longer needed, it should be freed. This function
  returns the memory used for the buffer to the operating system.


int buf_read(BUFFER *message, FILE *infile);

  This function reads data from a stream and appends them to the buffer.

  Return values:
   0 on success,
   1 if the file is too large to store it in a buffer,
  -1 if no data could be read.


int buf_write(BUFFER *message, FILE *outfile);

  This function writes the entire buffer to the output stream.

  Return values:
   0 if the buffer could be written completely,
  -1 otherwise.

int buf_write_sync(BUFFER *message, FILE *outfile);

  This function does the same as buf_write but also does
  checks for return values of fflush, fsync and ***fclose***.

  Return values:
   0 if the buffer could be written, synced and closed completely,
  -1 otherwise.

Remailer Messages
=================

int mix_encrypt(int type, BUFFER *message, char *chain, int numcopies,
	BUFFER *feedback);

  This function creates a Mixmaster message and stores it the Mixmaster
  message pool.

  The type is one of the following:

   MSG_MAIL  electronic mail message
   MSG_POST  Usenet news article
   MSG_NULL  dummy message, will be discarded

  *chain is a string consisting of a comma-separated list of remailer
  names that the message will be sent through. '*' means that a remailer
  will be chosen at random. If *chain is NULL, mix_encrypt() will use the
  default chain.

  numcopies is a number between 1 and 10 that indicates how many
  (redundant) copies of the message should be sent. If numcopies is 0,
  the default value will be used. The default values for *chain and
  numcopies are read from the configuration file.

  If *feedback is not NULL, mix_encrypt() will write the chain(s) that
  have been selected as newline-separated strings, or a textual error
  message to *feedback. This text can be presented to the user as
  feedback.

  Return values:
   0 on success,
  -1 if the message could not be created.


int mix_decrypt(BUFFER *message);

  This is the remailer function, which reads Mixmaster and Cypherpunk
  remailer messages as well as help file and key requests. Remailer
  messages are decrypted and stored in the message pool. Replies to
  information requests are sent immediately.

  Return values:
   0  if the message has been processed successfully,
   1  if the message is of an unknown type,
  -1  if the message could not be processed.


int mix_send(void);

  This function causes the messages in the pool to be sent. Depending on
  the configuration, mix_send() may send only a certain fraction of the
  messages in the pool.

  Return value: The size of the pool after the messages have been sent.


void mix_regular(int force);

  This function is responsible for regular actions of the remailer such
  as sending messages from the pool, getting mail from POP3 servers and
  expiring log files.


Nymserver Client Functions
==========================

The nymserver functions use user_pass() to get the passphrase for
opening the nym database.

int nym_config(int mode, char *nym, char *nymserver, BUFFER *pseudonym,
	       char *sendchain, int sendnumcopies, BUFFER *chains,
	       BUFFER *options);

  Create, modify or delete a nym. mode is one of NYM_CREATE, NYM_MODIFY and
  NYM_DELETE.

  nym is the pseudonymous address or its local part. In the latter case,
  nymserver must contain a string that selects a nymserver.

  pseudonym is a text string or NULL.

  sendchain and sendnumcopies are the chain and number of copies of
  the Mixmaster message sent to the nymserver.

  chains contains a list of reply blocks, consisting of "To:",
  "Newsgroups:", "Null:", "Latency:", "Chain:" and arbitrary header lines
  such as "Subject:". The "Chain:" line contains a remailer selection
  string for type 1 remailers. The reply blocks are separated by empty
  lines.

  options contains nymserver options (any of "acksend", "signsend",
  "fixedsize", "disable", "fingerkey" with a "+" or "-" prefix) or is NULL.


int nym_encrypt(BUFFER *msg, char *nym, int type);

  Prepare the message msg of type MSG_MAIL or MSG_POST to be sent using
  the nym. After successful encryption, msg contains a message of type
  MSG_MAIL addressed to the nymserver.


int nym_decrypt(BUFFER *msg, char *nym, BUFFER *log);

  Decrypt nymserver replies and PGP messages. If msg contains a nymserver
  reply, the the recipient nym is stored in nym (unless nym is NULL), and
  msg is replaced with the plaintext message in the Unix mail folder
  format.

  If log is not NULL, nym_decrypt will compute a unique ID for each
  message and append it to log. If the ID already is contained in log,
  it will return an empty msg buffer.


Lower-Level Remailer Functions
==============================

t1_decrypt(BUFFER *in);

  Decrypts and processes a Cypherpunk remailer message.


t2_decrypt(BUFFER *in);

  Decrypts and processes a Mixmaster remailer message.


int mix_pool(BUFFER *msg, int type, long latent);

  Adds the message msg of type MSG_MAIL or MSG_POST to the pool.
  latent is 0 or the message latency in seconds.


OpenPGP encryption
==================

int pgp_encrypt(int mode, BUFFER *message, BUFFER *encr,
               BUFFER *sigid, BUFFER *pass, char *pubring,
	       char *secring);

  This function encrypts and signs a message according to OpenPGP (RFC 2440).

  mode is the bitwise or of one of PGP_ENCRYPT, PGP_CONVENTIONAL and PGP_SIGN,
  and any of PGP_TEXT, PGP_REMAIL and PGP_NOARMOR.

  PGP_CONVENTIONAL: the message is encrypted conventionally, using
            the passphrase encr. If PGP_NCONVENTIONAL is used instead,
            the new OpenPGP format is used.
  PGP_ENCRYPT: public key encryption is used. The message is encrypted to
            the first public key on the keyring a User ID of which contains
            the substring encr. encr may contain several lines with one
            address substring each.
  PGP_SIGN: the message is signed with the first key from the secret
            key ring whose user ID contains sigid as a substring, or the
            first key if sigid is NULL.
  PGP_TEXT: message is treated as text, without PGP_TEXT as binary.
  PGP_DETACHEDSIG: signature will not include the signed message.
  PGP_REMAIL: a random offset is subtracted from signature dates, and the
            ASCII armor is made to mimic PGP.
  PGP_NOARMOR: message armor is not applied.

  If none of PGP_SIGN, PGP_CONVENTIONAL and PGP_ENCRYPT is set, the
  message is only compressed and armored.

  pubring and secring can be NULL or specify the name of a key ring.

  Return values:
   0       on success,
  -1       no matching key found,
  PGP_PASS bad signature passphrase.


int pgp_mailenc(int mode, BUFFER *message, char *sigid,
		BUFFER *pass, char *pubring, char *secring);

  This function encrypts and signs an RFC 822 e-mail message according to
  RFC 2015 (OpenPGP/MIME). Signatures without encryption on non-MIME messages
  are "cleartext" signatures.


int pgp_decrypt(BUFFER *message, BUFFER *pass, BUFFER *sig, char *pubring,
               char *secring);

  This function decrypts the OpenPGP message and verifies its signature.
  pass must contain the passphrase if message is conventionally encrypted
  or the secret key is protected by a passphrase. Otherwise it can be
  NULL.

  If message is a detached signature, sig must contain the signed data.
  It sig is NULL, the message will be decrypted without signature
  verification.

  pgp_getmsg() writes a string containing the signing time and
  signer's user ID or the key ID of the unknown signature key to sig.

  pubring and secring can be NULL or specify the name of a key ring.

  Return values:
  PGP_OK      on success,
  PGP_ERR     the message can't be read,
  PGP_PASS    bad passphrase,
  PGP_NOMSG   message is not an OpenPGP message,
  PGP_SIGOK   success, and signature has been verified,
  PGP_SIGNKEY can't verify signature,
  PGP_SIGBAD  bad signature,
  PGP_NODATA  OpenPGP message does not contain user data.


int pgp_keygen(int algo, int bits, BUFFER *userid, BUFFER *pass, char *pubring,
               char *secring, int remail);

  Generate a new key pair with given userid, encrypt the secret key with
  pass if not NULL.  Use a fake date if remail is not zero. Assume an
  encrypted secring if remail == 2.  algo is PGP_ES_RSA or PGP_E_ELG.


Buffers
=======

Buffers contain binary data of arbitrary length. You can append data
to buffers, clear buffers, and read data from buffers sequentially.
As data are appended to a buffer, memory is allocated dynamically.

typedef unsigned char byte;

typedef struct
{
    byte *data;
    long length;
    long ptr;
    long size;
    byte sensitive;
} BUFFER;

For a buffer *b, b->data is a pointer to at least b->length+1 bytes of
memory. b->data[b->length] is guaranteed to contain a null byte, so that
string functions can be used directly on buffers that contain text.

ptr is a counter for reading data from the buffer. b->data[b->ptr] is
the first data byte that has not been read (0 <= ptr <= length).

If sensitive is 1, the buffer contents will be overwritten before the
memory is released.


int buf_reset(BUFFER *buf);

  This function empties the buffer and returns the memory it has used to
  the operating system. It does not free the buffer itself.


int buf_clear(BUFFER *buf);

  buf_clear() empties the buffer but does not free the memory it uses.
  This function should be used if data of a similar size will be stored
  to the buffer later.


int buf_eq(BUFFER *buf1, BUFFER *buf2);

  Return values:
   1 if the buffers contain identical data,
   0 otherwise.


int buf_append(BUFFER *buf, byte *msg, int len);

  This is the most basic function for appending data to a buffer. It is
  called by all other functions that write to buffers. buf_append()
  appends len bytes pointed to by msg to buf. New memory will be
  allocated for the buffer if necessary.

  If msg is NULL, the buffer is increased by len bytes, but no
  guarantee is made about the contents of the appended bytes.

  Return value:
   0 on success,
   does not return if allocation of memory fails.


int buf_appendc(BUFFER *buf, byte b);
  appends the byte b to buf.


int buf_appends(BUFFER *buf, char *s);
  appends the null-terminated string s to buf.


int buf_appendf(BUFFER *buf, char *fmt, ...);
  appends formatted output to buf.


int buf_sets(BUFFER *buf, char *s);
  sets buf to contain the null-terminated string s.


int buf_setf(BUFFER *buf, char *fmt, ...);
  sets buf to contain the formatted output.


int buf_nl(BUFFER *buf);
  appends a newline character to buf.


int buf_cat(BUFFER *buf, BUFFER *f);
  appends the entire contents of f to buf.


int buf_rest(BUFFER *buf, BUFFER *f);
  appends the unread data from f to buf.


int buf_set(BUFFER *buf, BUFFER *f);
  sets buf to a copy of the contents of f.


int buf_move(BUFFER *buf, BUFFER *f);
  sets buf to the contents of f, and resets f. This is equivalent to
  buf_set(buf, f); buf_reset(f); but more efficient.


int buf_appendrnd(BUFFER *buf, int n);
  appends n cryptographically strong pseudo-random bytes to buf.


int buf_setrnd(BUFFER *buf, int n);
  places n cryptographically strong pseudo-random bytes in buf.


int buf_appendzero(BUFFER *buf, int n);
  appends n null bytes to buf.


int buf_pad(BUFFER *buf, int size);
  pads the buffer with cryptographically strong pseudo-random data to
  length size. Aborts if size < buf->length.


int buf_appendi(BUFFER *b, int i);
  appends the two bytes representing i in big-endian byte order to buf.


int buf_appendi_lo(BUFFER *b, int i);
  appends the two bytes representing i in little-endian byte order to buf.


int buf_appendl(BUFFER *buf, long l);
  appends the four bytes representing l in big-endian byte order to buf.


int buf_appendl_lo(BUFFER *buf, long l);
  appends the four bytes representing l in little-endian byte order to buf.


int buf_prepare(BUFFER *buf, int size);
  sets buf to contain size bytes of arbitrary data.


int buf_get(BUFFER *buf, BUFFER *t, int n);

  This function sets buffer t to contain n bytes read from buf.

  Return values:
   0 on success,
  -1 if buf does not contain n unread bytes.


int buf_getc(BUFFER *buf);
  reads one byte from buf. Returns -1 if buf contains no unread data,
  the byte otherwise.


int buf_geti(BUFFER *buf);
  reads two bytes from buf. Returns -1 if buf buf does not contain two
  unread bytes, the integer represented by the bytes in big-endian
  byte order otherwise.


int buf_geti_lo(BUFFER *buf);
  reads two bytes from buf. Returns -1 if buf buf does not contain two
  unread bytes, the integer represented by the bytes in little-endian
  byte order otherwise.


long buf_getl(BUFFER *buf);
  reads four bytes from buf. Returns -1 if buf buf does not contain four
  unread bytes, the integer represented by the bytes in big-endian
  byte order otherwise.


long buf_getl_lo(BUFFER *buf);
  reads four bytes from buf. Returns -1 if buf buf does not contain four
  unread bytes, the integer represented by the bytes in little-endian
  byte order otherwise.


void buf_ungetc(BUFFER *buf);
  restores one character for reading.


int buf_appendb(BUFFER *buf, BUFFER *p);
  appends p (with length information) to buf.


int buf_getb(BUFFER *buf, BUFFER *p);
  gets length information, then p from buf.


int buf_getline(BUFFER *buf, BUFFER *line);

  This function reads one line of text from buf, and stores it (without
  the trailing newline) in the buffer line.

  Return values:
   0 if a line of text has been read,
   1 if the line read is empty,
  -1 if buf contains no unread data.


int buf_lookahead(BUFFER *buf, BUFFER *line);

  This function reads one line of text from buf, and stores it (without
  the trailing newline) in the buffer line, without increasing the read
  counter.

  Return values:
   0 if a line of text has been read,
   1 if the line read is empty,
  -1 if buf contains no unread data.


int buf_chop(BUFFER *buf);

  buf is assumed to contain one line of text. A trailing newline and any
  other lines of text buf may contain are removed.


int buf_isheader(BUFFER *buf);

  This function checks whether the first line of buf is a RFC 822 header line.

  Returns:
   0 if it is not a header line.
   1 if it is a header line.

int buf_getheader(BUFFER *buf, BUFFER *field, BUFFER *content);

  This function reads a RFC 822 header line from buf. The field name of
  the header line without the colon is stored in field, the line's
  contents in content.

  Returns:
   0 on success,
   1 at end of header,
  -1 if buf contains no unread data.


int buf_appendheader(BUFFER *buffer, BUFFER *field, BUFFER *content);

  This function appends the RFC 822 header consisting of field and content
  to buffer.


int buf_rewind(BUFFER *buf);

  This function sets the read counter of buf to the start of the buffer
  (equivalent to buf->ptr = 0).


Randomness
==========

byte rnd_byte(void);
  returns a random byte.


int rnd_number(int n);
  returns a random number in 0 .. n-1.


int rnd_bytes(byte *b, int n);
  stores n random bytes at b.


Interface to the crypto library PRNG
====================================

int rnd_init(void);

  initializes the PRNG from the random seed file. Called from mix_init().
  Return values:
   0 on success,
  -1 on error.


int rnd_final(void);

  writes the random seed file and ends the PRNG. Called from mix_exit().
  Return values:
   0 on success,
  -1 on error.


int rnd_seed(void);
  seeds the PRNG, using console input if necessary.


void rnd_update(byte *b, int n);
  adds n bytes from b to the PRNG, unless b == NULL, and adds randomness
  from the system environment.


extern int rnd_state;
  An application may set rnd_state = RND_WILLSEED before executing
  mix_init() to indicate that it will seed the PRNG later by making calls
  to rnd_update() and then to rnd_initialized(). In that case,
  rnd_seed() will not ask for user input. [This is what the DLL startup code
  does internally.]


String comparison
=================

These functions operate on null-terminated strings. They return truth
values.


int streq(const char *s1, const char *s2);

  Return values:
   1 if the strings s1 and s2 are equal,
   0 otherwise.


int strieq(const char *s1, const char *s2);

  Return values:
   1 if the strings s1 and s2 are equal except for case,
   0 otherwise.


int strleft(const char *s, const char *keyword);

  Return values:
   1 if keyword is the left part of s,
   0 otherwise.


int strileft(const char *s, const char *keyword);

  Return values:
   1 if keyword is the left part of s, except for case,
   0 otherwise.


int strfind(const char *s, const char *keyword);

  Return values:
   1 if keyword is contained in s,
   0 otherwise.


int strifind(const char *s, const char *keyword);

  Return values:
   1 if keyword is contained in s, except for case,
   0 otherwise.


RFC 822 Addresses
=================

void rfc822_addr(BUFFER *destination, BUFFER *list);
  stores a list of RFC 822 addresses from destination in list, separated
  by newlines.

void rfc822_name(BUFFER *line, BUFFER *name);
  stores the name given in the RFC 822 address in line in name.


Files and Pipes
===============

int mixfile(char path[PATHMAX], const char *name);
  stores the path to a given file in the Mixmaster directory in path[].


FILE *mix_openfile(const char *name, const char *a);
  opens a file in the Mixmaster directory.


LOCK *lockfile(char *filename);
  creates and locks a lockfile associated with filename.


int unlockfile(LOCK *lock);
  releases the lock and deletes the lockfile.


int lock(FILE *f);
  sets a lock on a file.


int unlock(FILE *f);
  releases a lock on a file.


FILE *openpipe(const char *prog);
  opens a pipe.


int closepipe(FILE *p);
  closes a pipe.


int sendmail(BUFFER *message, BUFFER *address, const char *from);

  This function sends a mail message. The From: line and the destination
  address may be contained in the message; in that case address and from
  must be NULL. address is checked against the destination block list.

int sendmail_loop(BUFFER *message, BUFFER *address, const char *from);

  Identical to sendmail() but adds an X-Loop: header line.


Printable Encoding
==================

int encode(BUFFER *buf, int linelen);

  buf is encoded in base 64 encoding [RFC 1421]. If linelen > 0, the
  resulting text is broken into lines of linelen characters.

  Return value: 0.


int decode(BUFFER *in, BUFFER *out);

  This function reads the unread data from in, as long as it is valid
  base 64 encoded text, and stores the decoded data in out.

  Return values:
   0 if the in could be decoded to the end,
  -1 otherwise.


int hdr_encode(BUFFER *in, int n);

  Encodes a header line according to the MIME standard. The header is
  broken into lines of at most n characters.


int mail_encode(BUFFER *in, int encoding);

  Encodes the mail headers of a message, and encodes the body according
  to encoding MIME_7BIT or MIME_8BIT.


void id_encode(byte id[16], byte *s);
  stores the hexadecimal representation of id in s.


void id_decode(byte *s, byte id[16]);
  sets id to the value of the hexadecimal string s.


Compression
===========

int buf_zip(BUFFER *buf, BUFFER *f, int b);

  compresses buffer f using GZIP with b bits (or a default value, if
  b == 0), and appends the result to buf.

  Return values:
   0 on success,
  -1 on error.


int buf_unzip(BUFFER *buf, int type);

  uncompresses a GZIP [RFC 1952] compressed buffer. If type == 1, uncompress
  a ZLIB[RFC 1950] compressed buffer.

  Return values:
   0 on success,
  -1 on error.


**************************************************************************/

#ifndef _MIXLIB_H
#define _MIXLIB_H

#include <stdio.h>
#include <time.h>
#ifdef WIN32
#include <windows.h>
#endif /* WIN32 */

typedef unsigned char byte;

typedef struct {
  byte *data;
  long length;
  long ptr;
  long size;
  byte sensitive;
} BUFFER;

int mix_init(char *);
void mix_exit(void);
void rnd_update(byte *b, int n);
void rnd_initialized(void);
#ifdef WIN32
int rnd_mouse(UINT i, WPARAM w, LPARAM l);
#endif /* WIN32 */

BUFFER *buf_new(void);
int buf_free(BUFFER *buf);
int buf_read(BUFFER *message, FILE *infile);
int buf_write(BUFFER *message, FILE *outfile);
int buf_write_sync(BUFFER *message, FILE *outfile);

#define MSG_MAIL 1
#define MSG_POST 2
#define MSG_NULL 0

extern char MIXDIR[];

int mix_encrypt(int type, BUFFER *message, char *chain, int numcopies,
		BUFFER *feedback);
int mix_decrypt(BUFFER *message);
int mix_send(void);

#define FORCE_POOL 1
#define FORCE_POP3 2
#define FORCE_DAILY 4
#define FORCE_MAILIN 8
void mix_check_timeskew(void);
int mix_regular(int force);
int mix_daemon(void);
int process_mailin(void);

#ifdef USE_PGP

#define NYM_CREATE 0
#define NYM_MODIFY 1
#define NYM_DELETE 2

int nym_config(int mode, char *nym, char *nymserver, BUFFER *pseudonym,
	       char *sendchain, int sendnumcopies, BUFFER *chains,
	       BUFFER *options);
int nym_encrypt(BUFFER *msg, char *nym, int type);
int nym_decrypt(BUFFER *msg, char *nym, BUFFER *log);

#define PGP_SIGN 1
#define PGP_ENCRYPT 2
#define PGP_CONVENTIONAL 4
#define PGP_REMAIL 8
#define PGP_TEXT 16
#define PGP_NOARMOR 32
#define PGP_DETACHEDSIG 64
#define PGP_NCONVENTIONAL 128
#define PGP_CONV3DES 256
#define PGP_CONVCAST 512

/* error codes */
#define PGP_OK 0		/* valid message, not signed */
#define PGP_SIGOK 1		/* valid signature */
#define PGP_NOMSG 2		/* is not an OpenPGP message */
#define PGP_NODATA 3		/* OpenPGP packet does not contain user data */
#define PGP_SIGNKEY 4		/* can't verify signature */
#define PGP_ERR -1		/* can't read message, no matching key found */
#define PGP_PASS -2		/* bad passphrase */
#define PGP_SIGBAD -3		/* bad signature */


/* algorithms */
#define PGP_ANY 0
#define PGP_ES_RSA 1
#define PGP_E_ELG 16
#define PGP_S_DSA 17

int pgp_encrypt(int mode, BUFFER *message, BUFFER *encr, BUFFER *sigid,
		BUFFER *pass, char *pubring, char *secring);
int pgp_decrypt(BUFFER *message, BUFFER *pass, BUFFER *sig, char *pubring,
		char *secring);
int pgp_keygen(int algo, int bits, BUFFER *userid, BUFFER *pass,
		  char *pubring, char *secring, int remail);
#endif /* USE_PGP */


/* parsedate */
time_t parsedate(char *p);



#ifdef WIN32

#define sleep(x) Sleep(x*1000)

#endif /* WIN32 */

#endif /* not _MIXLIB_H */