URI: 
       tmix.h - mixmaster - mixmaster 3.0 patched for libressl
  HTML git clone git://parazyd.org/mixmaster.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
       tmix.h (25220B)
       ---
            1 /* Mixmaster version 3.0  --  (C) 1999 - 2006 Anonymizer Inc. and others.
            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 
            9    Mixmaster Library API
           10    =====================
           11 
           12 The Mixmaster library consists of a set of high-level functions that
           13 generate or process remailer messages, lower-level functions that
           14 manipulate data in various ways, and a number of functions that
           15 provide an interface to the underlying cryptographic library.
           16 Generally, a return value of 0 indicates success, and -1 an error.
           17 
           18 
           19 Initialization
           20 ==============
           21 
           22 int mix_init(char mixdir[]);
           23 
           24   This function initializes internal data of the Mixmaster library,
           25   such as the random number generator. This should be the first call
           26   to the Mixmaster library. It returns 0 on success. If the random
           27   number generator cannot be initialized, mix_init() terminates.
           28 
           29   The variable mixdir determines where the Mixmaster configuration
           30   files and the message pool are located. If mixdir is NULL, the
           31   library will use the directory specified in the environment variable
           32   $MIXPATH, the directory given at compile time if it exists, and the
           33   directory ~/Mix otherwise.
           34 
           35 
           36 void mix_exit(void);
           37 
           38   A program must call mix_exit before exiting. This function writes back
           39   the state of the random number generator.
           40 
           41 
           42 Using the Mixmaster DLL
           43 =======================
           44 
           45 In textmode applications, mix_init() can be used as described above.
           46 In graphical applications, these functions are not needed. Instead,
           47 the function rnd_mouse() should be called whenever the program gets
           48 WM_MOUSEMOVE or other messages:
           49 
           50 int rnd_mouse(UINT i, WPARAM w, LPARAM l);
           51 
           52   All events that a window gets may be passed to this function. It
           53   will extract the inherent randomness in user interaction, especially
           54   in mouse movements. It returns 100 if it has accumulated enough
           55   randomness to perform cryptographic operations, and a number between
           56   0 and 99 otherwise. This number can be used to provide graphical
           57   feedback on the progress of initializing the random number generator
           58   while asking the user to move the mouse. A runtime error will occur
           59   if any cryptographic functions are used before rnd_mouse() has
           60   signaled success.
           61 
           62 
           63 Message I/O
           64 ===========
           65 
           66 The library uses dynamically allocated buffers for messages and other
           67 data. Functions for buffer manipulation are described in section
           68 "Buffers" below.
           69 
           70 
           71 BUFFER *buf_new(void);
           72 
           73   Buffers must be initialized before they can be used. buf_new() returns
           74   a pointer to a newly initialized buffer.
           75 
           76 
           77 int buf_free(BUFFER *buf);
           78 
           79   When a buffer is no longer needed, it should be freed. This function
           80   returns the memory used for the buffer to the operating system.
           81 
           82 
           83 int buf_read(BUFFER *message, FILE *infile);
           84 
           85   This function reads data from a stream and appends them to the buffer.
           86 
           87   Return values:
           88    0 on success,
           89    1 if the file is too large to store it in a buffer,
           90   -1 if no data could be read.
           91 
           92 
           93 int buf_write(BUFFER *message, FILE *outfile);
           94 
           95   This function writes the entire buffer to the output stream.
           96 
           97   Return values:
           98    0 if the buffer could be written completely,
           99   -1 otherwise.
          100 
          101 int buf_write_sync(BUFFER *message, FILE *outfile);
          102 
          103   This function does the same as buf_write but also does
          104   checks for return values of fflush, fsync and ***fclose***.
          105 
          106   Return values:
          107    0 if the buffer could be written, synced and closed completely,
          108   -1 otherwise.
          109 
          110 Remailer Messages
          111 =================
          112 
          113 int mix_encrypt(int type, BUFFER *message, char *chain, int numcopies,
          114         BUFFER *feedback);
          115 
          116   This function creates a Mixmaster message and stores it the Mixmaster
          117   message pool.
          118 
          119   The type is one of the following:
          120 
          121    MSG_MAIL  electronic mail message
          122    MSG_POST  Usenet news article
          123    MSG_NULL  dummy message, will be discarded
          124 
          125   *chain is a string consisting of a comma-separated list of remailer
          126   names that the message will be sent through. '*' means that a remailer
          127   will be chosen at random. If *chain is NULL, mix_encrypt() will use the
          128   default chain.
          129 
          130   numcopies is a number between 1 and 10 that indicates how many
          131   (redundant) copies of the message should be sent. If numcopies is 0,
          132   the default value will be used. The default values for *chain and
          133   numcopies are read from the configuration file.
          134 
          135   If *feedback is not NULL, mix_encrypt() will write the chain(s) that
          136   have been selected as newline-separated strings, or a textual error
          137   message to *feedback. This text can be presented to the user as
          138   feedback.
          139 
          140   Return values:
          141    0 on success,
          142   -1 if the message could not be created.
          143 
          144 
          145 int mix_decrypt(BUFFER *message);
          146 
          147   This is the remailer function, which reads Mixmaster and Cypherpunk
          148   remailer messages as well as help file and key requests. Remailer
          149   messages are decrypted and stored in the message pool. Replies to
          150   information requests are sent immediately.
          151 
          152   Return values:
          153    0  if the message has been processed successfully,
          154    1  if the message is of an unknown type,
          155   -1  if the message could not be processed.
          156 
          157 
          158 int mix_send(void);
          159 
          160   This function causes the messages in the pool to be sent. Depending on
          161   the configuration, mix_send() may send only a certain fraction of the
          162   messages in the pool.
          163 
          164   Return value: The size of the pool after the messages have been sent.
          165 
          166 
          167 int mix_regular(int force);
          168 
          169   This function is responsible for regular actions of the remailer such
          170   as sending messages from the pool, getting mail from POP3 servers and
          171   expiring log files.
          172 
          173 
          174 Nymserver Client Functions
          175 ==========================
          176 
          177 The nymserver functions use user_pass() to get the passphrase for
          178 opening the nym database.
          179 
          180 int nym_config(int mode, char *nym, char *nymserver, BUFFER *pseudonym,
          181                char *sendchain, int sendnumcopies, BUFFER *chains,
          182                BUFFER *options);
          183 
          184   Create, modify or delete a nym. mode is one of NYM_CREATE, NYM_MODIFY and
          185   NYM_DELETE.
          186 
          187   nym is the pseudonymous address or its local part. In the latter case,
          188   nymserver must contain a string that selects a nymserver.
          189 
          190   pseudonym is a text string or NULL.
          191 
          192   sendchain and sendnumcopies are the chain and number of copies of
          193   the Mixmaster message sent to the nymserver.
          194 
          195   chains contains a list of reply blocks, consisting of "To:",
          196   "Newsgroups:", "Null:", "Latency:", "Chain:" and arbitrary header lines
          197   such as "Subject:". The "Chain:" line contains a remailer selection
          198   string for type 1 remailers. The reply blocks are separated by empty
          199   lines.
          200 
          201   options contains nymserver options (any of "acksend", "signsend",
          202   "fixedsize", "disable", "fingerkey" with a "+" or "-" prefix) or is NULL.
          203 
          204 
          205 int nym_encrypt(BUFFER *msg, char *nym, int type);
          206 
          207   Prepare the message msg of type MSG_MAIL or MSG_POST to be sent using
          208   the nym. After successful encryption, msg contains a message of type
          209   MSG_MAIL addressed to the nymserver.
          210 
          211 
          212 int nym_decrypt(BUFFER *msg, char *nym, BUFFER *log);
          213 
          214   Decrypt nymserver replies and PGP messages. If msg contains a nymserver
          215   reply, the the recipient nym is stored in nym (unless nym is NULL), and
          216   msg is replaced with the plaintext message in the Unix mail folder
          217   format.
          218 
          219   If log is not NULL, nym_decrypt will compute a unique ID for each
          220   message and append it to log. If the ID already is contained in log,
          221   it will return an empty msg buffer.
          222 
          223 
          224 Lower-Level Remailer Functions
          225 ==============================
          226 
          227 t1_decrypt(BUFFER *in);
          228 
          229   Decrypts and processes a Cypherpunk remailer message.
          230 
          231 
          232 t2_decrypt(BUFFER *in);
          233 
          234   Decrypts and processes a Mixmaster remailer message.
          235 
          236 
          237 int mix_pool(BUFFER *msg, int type, long latent);
          238 
          239   Adds the message msg of type MSG_MAIL or MSG_POST to the pool.
          240   latent is 0 or the message latency in seconds.
          241 
          242 
          243 OpenPGP encryption
          244 ==================
          245 
          246 int pgp_encrypt(int mode, BUFFER *message, BUFFER *encr,
          247                BUFFER *sigid, BUFFER *pass, char *pubring,
          248                char *secring);
          249 
          250   This function encrypts and signs a message according to OpenPGP (RFC 2440).
          251 
          252   mode is the bitwise or of one of PGP_ENCRYPT, PGP_CONVENTIONAL and PGP_SIGN,
          253   and any of PGP_TEXT, PGP_REMAIL and PGP_NOARMOR.
          254 
          255   PGP_CONVENTIONAL: the message is encrypted conventionally, using
          256             the passphrase encr. If PGP_NCONVENTIONAL is used instead,
          257             the new OpenPGP format is used.
          258   PGP_ENCRYPT: public key encryption is used. The message is encrypted to
          259             the first public key on the keyring a User ID of which contains
          260             the substring encr. encr may contain several lines with one
          261             address substring each.
          262   PGP_SIGN: the message is signed with the first key from the secret
          263             key ring whose user ID contains sigid as a substring, or the
          264             first key if sigid is NULL.
          265   PGP_TEXT: message is treated as text, without PGP_TEXT as binary.
          266   PGP_DETACHEDSIG: signature will not include the signed message.
          267   PGP_REMAIL: a random offset is subtracted from signature dates, and the
          268             ASCII armor is made to mimic PGP.
          269   PGP_NOARMOR: message armor is not applied.
          270 
          271   If none of PGP_SIGN, PGP_CONVENTIONAL and PGP_ENCRYPT is set, the
          272   message is only compressed and armored.
          273 
          274   pubring and secring can be NULL or specify the name of a key ring.
          275 
          276   Return values:
          277    0       on success,
          278   -1       no matching key found,
          279   PGP_PASS bad signature passphrase.
          280 
          281 
          282 int pgp_mailenc(int mode, BUFFER *message, char *sigid,
          283                 BUFFER *pass, char *pubring, char *secring);
          284 
          285   This function encrypts and signs an RFC 822 e-mail message according to
          286   RFC 2015 (OpenPGP/MIME). Signatures without encryption on non-MIME messages
          287   are "cleartext" signatures.
          288 
          289 
          290 int pgp_decrypt(BUFFER *message, BUFFER *pass, BUFFER *sig, char *pubring,
          291                char *secring);
          292 
          293   This function decrypts the OpenPGP message and verifies its signature.
          294   pass must contain the passphrase if message is conventionally encrypted
          295   or the secret key is protected by a passphrase. Otherwise it can be
          296   NULL.
          297 
          298   If message is a detached signature, sig must contain the signed data.
          299   It sig is NULL, the message will be decrypted without signature
          300   verification.
          301 
          302   pgp_getmsg() writes a string containing the signing time and
          303   signer's user ID or the key ID of the unknown signature key to sig.
          304 
          305   pubring and secring can be NULL or specify the name of a key ring.
          306 
          307   Return values:
          308   PGP_OK      on success,
          309   PGP_ERR     the message can't be read,
          310   PGP_PASS    bad passphrase,
          311   PGP_NOMSG   message is not an OpenPGP message,
          312   PGP_SIGOK   success, and signature has been verified,
          313   PGP_SIGNKEY can't verify signature,
          314   PGP_SIGBAD  bad signature,
          315   PGP_NODATA  OpenPGP message does not contain user data.
          316 
          317 
          318 int pgp_keygen(int algo, int bits, BUFFER *userid, BUFFER *pass, char *pubring,
          319                char *secring, int remail);
          320 
          321   Generate a new key pair with given userid, encrypt the secret key with
          322   pass if not NULL.  Use a fake date if remail is not zero. Assume an
          323   encrypted secring if remail == 2.  algo is PGP_ES_RSA or PGP_E_ELG.
          324 
          325 
          326 Buffers
          327 =======
          328 
          329 Buffers contain binary data of arbitrary length. You can append data
          330 to buffers, clear buffers, and read data from buffers sequentially.
          331 As data are appended to a buffer, memory is allocated dynamically.
          332 
          333 typedef unsigned char byte;
          334 
          335 typedef struct
          336 {
          337     byte *data;
          338     long length;
          339     long ptr;
          340     long size;
          341     byte sensitive;
          342 } BUFFER;
          343 
          344 For a buffer *b, b->data is a pointer to at least b->length+1 bytes of
          345 memory. b->data[b->length] is guaranteed to contain a null byte, so that
          346 string functions can be used directly on buffers that contain text.
          347 
          348 ptr is a counter for reading data from the buffer. b->data[b->ptr] is
          349 the first data byte that has not been read (0 <= ptr <= length).
          350 
          351 If sensitive is 1, the buffer contents will be overwritten before the
          352 memory is released.
          353 
          354 
          355 int buf_reset(BUFFER *buf);
          356 
          357   This function empties the buffer and returns the memory it has used to
          358   the operating system. It does not free the buffer itself.
          359 
          360 
          361 int buf_clear(BUFFER *buf);
          362 
          363   buf_clear() empties the buffer but does not free the memory it uses.
          364   This function should be used if data of a similar size will be stored
          365   to the buffer later.
          366 
          367 
          368 int buf_eq(BUFFER *buf1, BUFFER *buf2);
          369 
          370   Return values:
          371    1 if the buffers contain identical data,
          372    0 otherwise.
          373 
          374 
          375 int buf_append(BUFFER *buf, byte *msg, int len);
          376 
          377   This is the most basic function for appending data to a buffer. It is
          378   called by all other functions that write to buffers. buf_append()
          379   appends len bytes pointed to by msg to buf. New memory will be
          380   allocated for the buffer if necessary.
          381 
          382   If msg is NULL, the buffer is increased by len bytes, but no
          383   guarantee is made about the contents of the appended bytes.
          384 
          385   Return value:
          386    0 on success,
          387    does not return if allocation of memory fails.
          388 
          389 
          390 int buf_appendc(BUFFER *buf, byte b);
          391   appends the byte b to buf.
          392 
          393 
          394 int buf_appends(BUFFER *buf, char *s);
          395   appends the null-terminated string s to buf.
          396 
          397 
          398 int buf_appendf(BUFFER *buf, char *fmt, ...);
          399   appends formatted output to buf.
          400 
          401 
          402 int buf_sets(BUFFER *buf, char *s);
          403   sets buf to contain the null-terminated string s.
          404 
          405 
          406 int buf_setf(BUFFER *buf, char *fmt, ...);
          407   sets buf to contain the formatted output.
          408 
          409 
          410 int buf_nl(BUFFER *buf);
          411   appends a newline character to buf.
          412 
          413 
          414 int buf_cat(BUFFER *buf, BUFFER *f);
          415   appends the entire contents of f to buf.
          416 
          417 
          418 int buf_rest(BUFFER *buf, BUFFER *f);
          419   appends the unread data from f to buf.
          420 
          421 
          422 int buf_set(BUFFER *buf, BUFFER *f);
          423   sets buf to a copy of the contents of f.
          424 
          425 
          426 int buf_move(BUFFER *buf, BUFFER *f);
          427   sets buf to the contents of f, and resets f. This is equivalent to
          428   buf_set(buf, f); buf_reset(f); but more efficient.
          429 
          430 
          431 int buf_appendrnd(BUFFER *buf, int n);
          432   appends n cryptographically strong pseudo-random bytes to buf.
          433 
          434 
          435 int buf_setrnd(BUFFER *buf, int n);
          436   places n cryptographically strong pseudo-random bytes in buf.
          437 
          438 
          439 int buf_appendzero(BUFFER *buf, int n);
          440   appends n null bytes to buf.
          441 
          442 
          443 int buf_pad(BUFFER *buf, int size);
          444   pads the buffer with cryptographically strong pseudo-random data to
          445   length size. Aborts if size < buf->length.
          446 
          447 
          448 int buf_appendi(BUFFER *b, int i);
          449   appends the two bytes representing i in big-endian byte order to buf.
          450 
          451 
          452 int buf_appendi_lo(BUFFER *b, int i);
          453   appends the two bytes representing i in little-endian byte order to buf.
          454 
          455 
          456 int buf_appendl(BUFFER *buf, long l);
          457   appends the four bytes representing l in big-endian byte order to buf.
          458 
          459 
          460 int buf_appendl_lo(BUFFER *buf, long l);
          461   appends the four bytes representing l in little-endian byte order to buf.
          462 
          463 
          464 int buf_prepare(BUFFER *buf, int size);
          465   sets buf to contain size bytes of arbitrary data.
          466 
          467 
          468 int buf_get(BUFFER *buf, BUFFER *t, int n);
          469 
          470   This function sets buffer t to contain n bytes read from buf.
          471 
          472   Return values:
          473    0 on success,
          474   -1 if buf does not contain n unread bytes.
          475 
          476 
          477 int buf_getc(BUFFER *buf);
          478   reads one byte from buf. Returns -1 if buf contains no unread data,
          479   the byte otherwise.
          480 
          481 
          482 int buf_geti(BUFFER *buf);
          483   reads two bytes from buf. Returns -1 if buf buf does not contain two
          484   unread bytes, the integer represented by the bytes in big-endian
          485   byte order otherwise.
          486 
          487 
          488 int buf_geti_lo(BUFFER *buf);
          489   reads two bytes from buf. Returns -1 if buf buf does not contain two
          490   unread bytes, the integer represented by the bytes in little-endian
          491   byte order otherwise.
          492 
          493 
          494 long buf_getl(BUFFER *buf);
          495   reads four bytes from buf. Returns -1 if buf buf does not contain four
          496   unread bytes, the integer represented by the bytes in big-endian
          497   byte order otherwise.
          498 
          499 
          500 long buf_getl_lo(BUFFER *buf);
          501   reads four bytes from buf. Returns -1 if buf buf does not contain four
          502   unread bytes, the integer represented by the bytes in little-endian
          503   byte order otherwise.
          504 
          505 
          506 void buf_ungetc(BUFFER *buf);
          507   restores one character for reading.
          508 
          509 
          510 int buf_appendb(BUFFER *buf, BUFFER *p);
          511   appends p (with length information) to buf.
          512 
          513 
          514 int buf_getb(BUFFER *buf, BUFFER *p);
          515   gets length information, then p from buf.
          516 
          517 
          518 int buf_getline(BUFFER *buf, BUFFER *line);
          519 
          520   This function reads one line of text from buf, and stores it (without
          521   the trailing newline) in the buffer line.
          522 
          523   Return values:
          524    0 if a line of text has been read,
          525    1 if the line read is empty,
          526   -1 if buf contains no unread data.
          527 
          528 
          529 int buf_lookahead(BUFFER *buf, BUFFER *line);
          530 
          531   This function reads one line of text from buf, and stores it (without
          532   the trailing newline) in the buffer line, without increasing the read
          533   counter.
          534 
          535   Return values:
          536    0 if a line of text has been read,
          537    1 if the line read is empty,
          538   -1 if buf contains no unread data.
          539 
          540 
          541 int buf_chop(BUFFER *buf);
          542 
          543   buf is assumed to contain one line of text. A trailing newline and any
          544   other lines of text buf may contain are removed.
          545 
          546 
          547 int buf_isheader(BUFFER *buf);
          548 
          549   This function checks whether the first line of buf is a RFC 822 header line.
          550 
          551   Returns:
          552    0 if it is not a header line.
          553    1 if it is a header line.
          554 
          555 int buf_getheader(BUFFER *buf, BUFFER *field, BUFFER *content);
          556 
          557   This function reads a RFC 822 header line from buf. The field name of
          558   the header line without the colon is stored in field, the line's
          559   contents in content.
          560 
          561   Returns:
          562    0 on success,
          563    1 at end of header,
          564   -1 if buf contains no unread data.
          565 
          566 
          567 int buf_appendheader(BUFFER *buffer, BUFFER *field, BUFFER *content);
          568 
          569   This function appends the RFC 822 header consisting of field and content
          570   to buffer.
          571 
          572 
          573 int buf_rewind(BUFFER *buf);
          574 
          575   This function sets the read counter of buf to the start of the buffer
          576   (equivalent to buf->ptr = 0).
          577 
          578 
          579 Randomness
          580 ==========
          581 
          582 byte rnd_byte(void);
          583   returns a random byte.
          584 
          585 
          586 int rnd_number(int n);
          587   returns a random number in 0 .. n-1.
          588 
          589 
          590 int rnd_bytes(byte *b, int n);
          591   stores n random bytes at b.
          592 
          593 
          594 Interface to the crypto library PRNG
          595 ====================================
          596 
          597 int rnd_init(void);
          598 
          599   initializes the PRNG from the random seed file. Called from mix_init().
          600   Return values:
          601    0 on success,
          602   -1 on error.
          603 
          604 
          605 int rnd_final(void);
          606 
          607   writes the random seed file and ends the PRNG. Called from mix_exit().
          608   Return values:
          609    0 on success,
          610   -1 on error.
          611 
          612 
          613 int rnd_seed(void);
          614   seeds the PRNG, using console input if necessary.
          615 
          616 
          617 void rnd_update(byte *b, int n);
          618   adds n bytes from b to the PRNG, unless b == NULL, and adds randomness
          619   from the system environment.
          620 
          621 
          622 extern int rnd_state;
          623   An application may set rnd_state = RND_WILLSEED before executing
          624   mix_init() to indicate that it will seed the PRNG later by making calls
          625   to rnd_update() and then to rnd_initialized(). In that case,
          626   rnd_seed() will not ask for user input. [This is what the DLL startup code
          627   does internally.]
          628 
          629 
          630 String comparison
          631 =================
          632 
          633 These functions operate on null-terminated strings. They return truth
          634 values.
          635 
          636 
          637 int streq(const char *s1, const char *s2);
          638 
          639   Return values:
          640    1 if the strings s1 and s2 are equal,
          641    0 otherwise.
          642 
          643 
          644 int strieq(const char *s1, const char *s2);
          645 
          646   Return values:
          647    1 if the strings s1 and s2 are equal except for case,
          648    0 otherwise.
          649 
          650 
          651 int strleft(const char *s, const char *keyword);
          652 
          653   Return values:
          654    1 if keyword is the left part of s,
          655    0 otherwise.
          656 
          657 
          658 int strileft(const char *s, const char *keyword);
          659 
          660   Return values:
          661    1 if keyword is the left part of s, except for case,
          662    0 otherwise.
          663 
          664 
          665 int strfind(const char *s, const char *keyword);
          666 
          667   Return values:
          668    1 if keyword is contained in s,
          669    0 otherwise.
          670 
          671 
          672 int strifind(const char *s, const char *keyword);
          673 
          674   Return values:
          675    1 if keyword is contained in s, except for case,
          676    0 otherwise.
          677 
          678 
          679 RFC 822 Addresses
          680 =================
          681 
          682 void rfc822_addr(BUFFER *destination, BUFFER *list);
          683   stores a list of RFC 822 addresses from destination in list, separated
          684   by newlines.
          685 
          686 void rfc822_name(BUFFER *line, BUFFER *name);
          687   stores the name given in the RFC 822 address in line in name.
          688 
          689 
          690 Files and Pipes
          691 ===============
          692 
          693 int mixfile(char path[PATHMAX], const char *name);
          694   stores the path to a given file in the Mixmaster directory in path[].
          695 
          696 
          697 FILE *mix_openfile(const char *name, const char *a);
          698   opens a file in the Mixmaster directory.
          699 
          700 
          701 LOCK *lockfile(char *filename);
          702   creates and locks a lockfile associated with filename.
          703 
          704 
          705 int unlockfile(LOCK *lock);
          706   releases the lock and deletes the lockfile.
          707 
          708 
          709 int lock(FILE *f);
          710   sets a lock on a file.
          711 
          712 
          713 int unlock(FILE *f);
          714   releases a lock on a file.
          715 
          716 
          717 FILE *openpipe(const char *prog);
          718   opens a pipe.
          719 
          720 
          721 int closepipe(FILE *p);
          722   closes a pipe.
          723 
          724 
          725 int sendmail(BUFFER *message, BUFFER *address, const char *from);
          726 
          727   This function sends a mail message. The From: line and the destination
          728   address may be contained in the message; in that case address and from
          729   must be NULL. address is checked against the destination block list.
          730 
          731 int sendmail_loop(BUFFER *message, BUFFER *address, const char *from);
          732 
          733   Identical to sendmail() but adds an X-Loop: header line.
          734 
          735 
          736 Printable Encoding
          737 ==================
          738 
          739 int encode(BUFFER *buf, int linelen);
          740 
          741   buf is encoded in base 64 encoding [RFC 1421]. If linelen > 0, the
          742   resulting text is broken into lines of linelen characters.
          743 
          744   Return value: 0.
          745 
          746 
          747 int decode(BUFFER *in, BUFFER *out);
          748 
          749   This function reads the unread data from in, as long as it is valid
          750   base 64 encoded text, and stores the decoded data in out.
          751 
          752   Return values:
          753    0 if the in could be decoded to the end,
          754   -1 otherwise.
          755 
          756 
          757 int hdr_encode(BUFFER *in, int n);
          758 
          759   Encodes a header line according to the MIME standard. The header is
          760   broken into lines of at most n characters.
          761 
          762 
          763 int mail_encode(BUFFER *in, int encoding);
          764 
          765   Encodes the mail headers of a message, and encodes the body according
          766   to encoding MIME_7BIT or MIME_8BIT.
          767 
          768 
          769 void id_encode(byte id[16], byte *s);
          770   stores the hexadecimal representation of id in s.
          771 
          772 
          773 void id_decode(byte *s, byte id[16]);
          774   sets id to the value of the hexadecimal string s.
          775 
          776 
          777 Compression
          778 ===========
          779 
          780 int buf_zip(BUFFER *buf, BUFFER *f, int b);
          781 
          782   compresses buffer f using GZIP with b bits (or a default value, if
          783   b == 0), and appends the result to buf.
          784 
          785   Return values:
          786    0 on success,
          787   -1 on error.
          788 
          789 
          790 int buf_unzip(BUFFER *buf, int type);
          791 
          792   uncompresses a GZIP [RFC 1952] compressed buffer. If type == 1, uncompress
          793   a ZLIB [RFC 1950] compressed buffer.
          794 
          795   Return values:
          796    0 on success,
          797   -1 on error.
          798 
          799 
          800 **************************************************************************/
          801 
          802 #ifndef _MIXLIB_H
          803 #define _MIXLIB_H
          804 
          805 #include <stdio.h>
          806 #include <time.h>
          807 #ifdef WIN32
          808 #include <windows.h>
          809 #endif /* WIN32 */
          810 
          811 typedef unsigned char byte;
          812 
          813 typedef struct {
          814   byte *data;
          815   long length;
          816   long ptr;
          817   long size;
          818   byte sensitive;
          819 } BUFFER;
          820 
          821 int mix_init(char *);
          822 void mix_exit(void);
          823 void rnd_update(byte *b, int n);
          824 void rnd_initialized(void);
          825 #ifdef WIN32
          826 int rnd_mouse(UINT i, WPARAM w, LPARAM l);
          827 #endif /* WIN32 */
          828 
          829 BUFFER *buf_new(void);
          830 int buf_free(BUFFER *buf);
          831 int buf_read(BUFFER *message, FILE *infile);
          832 int buf_write(BUFFER *message, FILE *outfile);
          833 int buf_write_sync(BUFFER *message, FILE *outfile);
          834 
          835 #define MSG_MAIL 1
          836 #define MSG_POST 2
          837 #define MSG_NULL 0
          838 
          839 extern char MIXDIR[];
          840 
          841 int mix_encrypt(int type, BUFFER *message, char *chain, int numcopies,
          842                 BUFFER *feedback);
          843 int mix_decrypt(BUFFER *message);
          844 int mix_send(void);
          845 
          846 #define FORCE_POOL 1
          847 #define FORCE_POP3 2
          848 #define FORCE_DAILY 4
          849 #define FORCE_MAILIN 8
          850 #define FORCE_STATS 16
          851 void mix_check_timeskew(void);
          852 int mix_regular(int force);
          853 int mix_daemon(void);
          854 int process_mailin(void);
          855 
          856 #ifdef USE_PGP
          857 
          858 #define NYM_CREATE 0
          859 #define NYM_MODIFY 1
          860 #define NYM_DELETE 2
          861 
          862 int nym_config(int mode, char *nym, char *nymserver, BUFFER *pseudonym,
          863                char *sendchain, int sendnumcopies, BUFFER *chains,
          864                BUFFER *options);
          865 int nym_encrypt(BUFFER *msg, char *nym, int type);
          866 int nym_decrypt(BUFFER *msg, char *nym, BUFFER *log);
          867 
          868 #define PGP_SIGN 1
          869 #define PGP_ENCRYPT 2
          870 #define PGP_CONVENTIONAL 4
          871 #define PGP_REMAIL 8
          872 #define PGP_TEXT 16
          873 #define PGP_NOARMOR 32
          874 #define PGP_DETACHEDSIG 64
          875 #define PGP_NCONVENTIONAL 128
          876 #define PGP_CONV3DES 256
          877 #define PGP_CONVCAST 512
          878 
          879 /* error codes */
          880 #define PGP_OK 0                /* valid message, not signed */
          881 #define PGP_SIGOK 1                /* valid signature */
          882 #define PGP_NOMSG 2                /* is not an OpenPGP message */
          883 #define PGP_NODATA 3                /* OpenPGP packet does not contain user data */
          884 #define PGP_SIGNKEY 4                /* can't verify signature */
          885 #define PGP_ERR -1                /* can't read message, no matching key found */
          886 #define PGP_PASS -2                /* bad passphrase */
          887 #define PGP_SIGBAD -3                /* bad signature */
          888 
          889 
          890 /* algorithms */
          891 #define PGP_ANY 0
          892 #define PGP_ES_RSA 1
          893 #define PGP_E_ELG 16
          894 #define PGP_S_DSA 17
          895 
          896 int pgp_encrypt(int mode, BUFFER *message, BUFFER *encr, BUFFER *sigid,
          897                 BUFFER *pass, char *pubring, char *secring);
          898 int pgp_decrypt(BUFFER *message, BUFFER *pass, BUFFER *sig, char *pubring,
          899                 char *secring);
          900 int pgp_keygen(int algo, int bits, BUFFER *userid, BUFFER *pass,
          901                   char *pubring, char *secring, int remail);
          902 #endif /* USE_PGP */
          903 
          904 
          905 /* parsedate */
          906 time_t parsedate(char *p);
          907 
          908 
          909 
          910 #ifdef WIN32
          911 
          912 #define sleep(x) Sleep((x)*1000)
          913 #define strcasecmp stricmp
          914 
          915 #endif /* WIN32 */
          916 
          917 #endif /* not _MIXLIB_H */