3 * $Id: tripe.h,v 1.18 2004/04/03 12:35:13 mdw Exp $
5 * Main header file for TrIPE
7 * (c) 2001 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Trivial IP Encryption (TrIPE).
14 * TrIPE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * TrIPE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with TrIPE; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.18 2004/04/03 12:35:13 mdw
33 * Support elliptic curve key exchange.
35 * Revision 1.17 2003/10/15 09:30:18 mdw
36 * Add support for Ethereal protocol analysis.
38 * Revision 1.16 2003/07/13 11:19:49 mdw
39 * Incompatible protocol fix! Include message type code under MAC tag to
40 * prevent cut-and-paste from key-exchange messages to general packet
43 * Revision 1.15 2003/05/16 12:09:03 mdw
44 * Allow binding to a chosen address.
46 * Revision 1.14 2003/04/06 10:36:33 mdw
47 * Rearrange so as not to include Linux headers unless we need to.
49 * Revision 1.13 2003/04/06 10:26:35 mdw
50 * Report peer name on decrypt errors.
52 * Revision 1.12 2003/04/06 10:25:17 mdw
53 * Support Linux TUN/TAP device. Fix some bugs.
55 * Revision 1.11 2002/01/13 14:57:42 mdw
58 * Revision 1.10 2002/01/13 14:54:58 mdw
61 * Revision 1.9 2001/06/22 19:40:36 mdw
62 * Support expiry of other peers' public keys.
64 * Revision 1.8 2001/06/19 22:10:57 mdw
65 * Some more constants for the algorithms. Document the packet format
66 * change for non-malleability. Moved @buf@ definitions to separate header
69 * Revision 1.7 2001/03/03 12:07:08 mdw
70 * Rename word get and put functions now that there's 16-bit support.
72 * Revision 1.6 2001/02/19 19:11:09 mdw
73 * Output buffering on admin connections.
75 * Revision 1.5 2001/02/16 21:41:43 mdw
76 * Major changes. See source files for details.
78 * Revision 1.4 2001/02/05 19:56:37 mdw
79 * Sequence number protection, and BSD tunnels.
81 * Revision 1.3 2001/02/04 01:17:55 mdw
82 * Create a configuration header file to tidy up command lines.
84 * Revision 1.2 2001/02/03 22:40:29 mdw
85 * Put timer information into the entropy pool when packets are received
86 * and on similar events. Reseed the generator on the interval timer.
88 * Revision 1.1 2001/02/03 20:26:37 mdw
100 /*----- Header files ------------------------------------------------------*/
115 #include <sys/types.h>
116 #include <sys/time.h>
119 #include <sys/stat.h>
121 #include <sys/socket.h>
123 #include <netinet/in.h>
124 #include <arpa/inet.h>
130 #include <mLib/alloc.h>
131 #include <mLib/arena.h>
132 #include <mLib/bres.h>
133 #include <mLib/dstr.h>
134 #include <mLib/env.h>
135 #include <mLib/fdflags.h>
136 #include <mLib/fwatch.h>
137 #include <mLib/mdwopt.h>
138 #include <mLib/quis.h>
139 #include <mLib/report.h>
140 #include <mLib/sel.h>
141 #include <mLib/selbuf.h>
142 #include <mLib/sig.h>
143 #include <mLib/str.h>
144 #include <mLib/sub.h>
145 #include <mLib/trace.h>
147 #include <catacomb/buf.h>
149 #include <catacomb/gcipher.h>
150 #include <catacomb/gmac.h>
151 #include <catacomb/grand.h>
152 #include <catacomb/key.h>
153 #include <catacomb/paranoia.h>
155 #include <catacomb/noise.h>
156 #include <catacomb/rand.h>
158 #include <catacomb/mp.h>
159 #include <catacomb/mprand.h>
160 #include <catacomb/dh.h>
161 #include <catacomb/ec.h>
162 #include <catacomb/ec-keys.h>
163 #include <catacomb/group.h>
165 #include "tripe-protocol.h"
170 /*----- Magic numbers -----------------------------------------------------*/
172 /* --- Tunnel types --- */
179 /* --- Trace flags --- */
187 #define T_KEYEXCH 64u
188 #define T_KEYMGMT 128u
194 #define SEC(n) (n##u)
195 #define MIN(n) (n##u * 60u)
196 #define MEG(n) (n##ul * 1024ul * 1024ul)
198 /* --- Other things --- */
200 #define PKBUFSZ 65536
202 /*----- Cipher selections -------------------------------------------------*/
204 #include <catacomb/blowfish.h>
205 #include <catacomb/blowfish-cbc.h>
206 #include <catacomb/blowfish-counter.h>
207 #include <catacomb/rmd160.h>
208 #include <catacomb/rmd160-hmac.h>
210 #define CIPHER (&blowfish_cbc)
211 #define MAC (&rmd160_hmac)
213 #define HASH_CTX rmd160_ctx
214 #define HASH_INIT rmd160_init
215 #define HASH rmd160_hash
216 #define HASH_STRING(c, s) HASH((c), s, sizeof(s))
217 #define HASH_DONE rmd160_done
218 #define HASHSZ RMD160_HASHSZ
220 #define MGF_CTX blowfish_counterctx
221 #define MGF_INIT blowfish_counterinit
222 #define MGF_CRYPT blowfish_counterencrypt
225 #define IVSZ BLOWFISH_BLKSZ
228 /*----- Data structures ---------------------------------------------------*/
230 /* --- Socket addresses --- *
232 * A magic union of supported socket addresses.
237 struct sockaddr_in sin;
240 /* --- A symmetric keyset --- *
242 * A keyset contains a set of symmetric keys for encrypting and decrypting
243 * packets. Keysets are stored in a list, sorted in reverse order of
244 * creation, so that the most recent keyset (the one most likely to be used)
247 * Each keyset has a time limit and a data limit. The keyset is destroyed
248 * when either it has existed for too long, or it has been used to encrypt
249 * too much data. New key exchanges are triggered when keys are close to
253 typedef struct keyset {
254 struct keyset *next; /* Next active keyset in the list */
255 unsigned ref; /* Reference count for keyset */
256 struct peer *p; /* Pointer to peer structure */
257 time_t t_exp; /* Expiry time for this keyset */
258 unsigned long sz_exp; /* Data limit for the keyset */
259 T( unsigned seq; ) /* Sequence number for tracing */
260 unsigned f; /* Various useful flags */
261 gcipher *cin, *cout; /* Keyset ciphers for encryption */
262 gmac *min, *mout; /* Keyset MACs for integrity */
263 uint32 oseq; /* Outbound sequence number */
264 uint32 iseq, iwin; /* Inbound sequence number */
267 #define KS_SEQWINSZ 32 /* Bits in sequence number window */
269 #define KSF_LISTEN 1u /* Don't encrypt packets yet */
270 #define KSF_LINK 2u /* Key is in a linked list */
272 /* --- Key exchange --- *
274 * TrIPE uses the Wrestlers Protocol for its key exchange. The Wrestlers
275 * Protocol has a number of desirable features (e.g., perfect forward
276 * secrecy, and zero-knowledge authentication) which make it attractive for
277 * use in TrIPE. The Wrestlers Protocol was designed by Mark Wooding and
284 typedef struct kxchal {
285 struct keyexch *kx; /* Pointer back to key exchange */
286 ge *c; /* Responder's challenge */
287 ge *r; /* My reply to the challenge */
288 keyset *ks; /* Pointer to temporary keyset */
289 unsigned f; /* Various useful flags */
290 sel_timer t; /* Response timer for challenge */
291 octet hc[HASHSZ]; /* Hash of his challenge */
292 mp *ck; /* The check value */
293 octet hswrq_in[HASHSZ]; /* Inbound switch request message */
294 octet hswok_in[HASHSZ]; /* Inbound switch confirmation */
295 octet hswrq_out[HASHSZ]; /* Outbound switch request message */
296 octet hswok_out[HASHSZ]; /* Outbound switch confirmation */
299 typedef struct keyexch {
300 struct peer *p; /* Pointer back to the peer */
301 keyset **ks; /* Peer's list of keysets */
302 unsigned f; /* Various useful flags */
303 unsigned s; /* Current state in exchange */
304 sel_timer t; /* Timer for next exchange */
305 ge *kpub; /* Peer's public key */
306 time_t texp_kpub; /* Expiry time for public key */
307 mp *alpha; /* My temporary secret */
308 ge *c; /* My challenge */
309 ge *rx; /* The expected response */
310 unsigned nr; /* Number of extant responses */
311 time_t t_valid; /* When this exchange goes bad */
312 octet hc[HASHSZ]; /* Hash of my challenge */
313 kxchal *r[KX_NCHAL]; /* Array of challenges */
316 #define KXF_TIMER 1u /* Waiting for a timer to go off */
317 #define KXF_DEAD 2u /* The key-exchanger isn't up */
318 #define KXF_PUBKEY 4u /* Key exchanger has a public key */
321 KXS_DEAD, /* Uninitialized state (magical) */
322 KXS_CHAL, /* Main answer-challenges state */
323 KXS_COMMIT, /* Committed: send switch request */
324 KXS_SWITCH /* Switched: send confirmation */
327 /* --- Tunnel structure --- *
329 * Used to maintain system-specific information about the tunnel interface.
332 #if TUN_TYPE == TUN_LINUX
333 # include <linux/if.h>
334 # include <linux/if_tun.h>
337 typedef struct tunnel {
338 #if TUN_TYPE == TUN_UNET
339 sel_file f; /* Selector for Usernet device */
340 struct peer *p; /* Pointer to my peer */
341 #elif TUN_TYPE == TUN_LINUX
342 sel_file f; /* Selector for TUN/TAP device */
343 struct peer *p; /* Pointer to my peer */
344 char ifn[IFNAMSIZ]; /* Interface name buffer */
345 #elif TUN_TYPE == TUN_BSD
346 sel_file f; /* Selector for tunnel device */
347 struct peer *p; /* Pointer to my peer */
348 unsigned n; /* Number of my tunnel device */
350 # error "No support for this tunnel type"
354 /* --- Peer statistics --- *
356 * Contains various interesting and not-so-interesting statistics about a
357 * peer. This is updated by various parts of the code. The format of the
358 * structure isn't considered private, and @p_stats@ returns a pointer to the
359 * statistics block for a given peer.
362 typedef struct stats {
363 unsigned long sz_in, sz_out; /* Size of all data in and out */
364 unsigned long sz_kxin, sz_kxout; /* Size of key exchange messages */
365 unsigned long sz_ipin, sz_ipout; /* Size of encapsulated IP packets */
366 time_t t_start, t_last; /* Time peer created, last recv */
367 unsigned long n_reject; /* Number of rejected packets */
368 unsigned long n_in, n_out; /* Number of packets in and out */
369 unsigned long n_kxin, n_kxout; /* Number of key exchange packets */
370 unsigned long n_ipin, n_ipout; /* Number of encrypted packets */
373 /* --- Peer structure --- *
375 * The main structure which glues everything else together.
378 typedef struct peer {
379 struct peer *next, *prev; /* Links to next and previous */
380 char *name; /* Name of this peer */
381 tunnel t; /* Tunnel for local packets */
382 keyset *ks; /* List head for keysets */
383 buf b; /* Buffer for sending packets */
384 addr peer; /* Peer socket address */
385 size_t sasz; /* Socket address size */
386 stats st; /* Statistics */
387 keyexch kx; /* Key exchange protocol block */
390 /* --- Admin structure --- */
392 #define OBUFSZ 16384u
394 typedef struct obuf {
395 struct obuf *next; /* Next buffer in list */
396 char *p_in, *p_out; /* Pointers into the buffer */
397 char buf[OBUFSZ]; /* The actual buffer */
400 typedef struct admin {
401 struct admin *next, *prev; /* Links to next and previous */
402 unsigned f; /* Various useful flags */
404 unsigned seq; /* Sequence number for tracing */
406 char *pname; /* Peer name to create */
407 char *paddr; /* Address string to resolve */
408 obuf *o_head, *o_tail; /* Output buffer list */
409 selbuf b; /* Line buffer for commands */
410 sel_file w; /* Selector for write buffering */
411 bres_client r; /* Background resolver task */
412 sel_timer t; /* Timer for resolver */
413 addr peer; /* Address to set */
414 size_t sasz; /* Size of the address */
417 #define AF_DEAD 1u /* Destroy this admin block */
418 #define AF_LOCK 2u /* Don't destroy it yet */
420 /*----- Global variables --------------------------------------------------*/
422 extern sel_state sel; /* Global I/O event state */
423 extern group *gg; /* The group we work in */
424 extern mp *kpriv; /* Our private key */
425 extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
428 extern const trace_opt tr_opts[]; /* Trace options array */
429 extern unsigned tr_flags; /* Trace options flags */
432 /*----- Other macros ------------------------------------------------------*/
434 #define TIMER noise_timer(RAND_GLOBAL)
436 /*----- Key management ----------------------------------------------------*/
438 /* --- @km_interval@ --- *
442 * Returns: Zero if OK, nonzero to force reloading of keys.
444 * Use: Called on the interval timer to perform various useful jobs.
447 extern int km_interval(void);
449 /* --- @km_init@ --- *
451 * Arguments: @const char *kr_priv@ = private keyring file
452 * @const char *kr_pub@ = public keyring file
453 * @const char *tag@ = tag to load
457 * Use: Initializes, and loads the private key.
460 extern void km_init(const char */*kr_priv*/, const char */*kr_pub*/,
461 const char */*tag*/);
463 /* --- @km_getpubkey@ --- *
465 * Arguments: @const char *tag@ = public key tag to load
466 * @ge *kpub@ = where to put the public key
467 * @time_t *t_exp@ = where to put the expiry time
469 * Returns: Zero if OK, nonzero if it failed.
471 * Use: Fetches a public key from the keyring.
474 extern int km_getpubkey(const char */*tag*/, ge */*kpub*/,
477 /*----- Key exchange ------------------------------------------------------*/
479 /* --- @kx_start@ --- *
481 * Arguments: @keyexch *kx@ = pointer to key exchange context
485 * Use: Stimulates a key exchange. If a key exchage is in progress,
486 * a new challenge is sent (unless the quiet timer forbids
487 * this); if no exchange is in progress, one is commenced.
490 extern void kx_start(keyexch */*kx*/);
492 /* --- @kx_message@ --- *
494 * Arguments: @keyexch *kx@ = pointer to key exchange context
495 * @unsigned msg@ = the message code
496 * @buf *b@ = pointer to buffer containing the packet
500 * Use: Reads a packet containing key exchange messages and handles
504 extern void kx_message(keyexch */*kx*/, unsigned /*msg*/, buf */*b*/);
506 /* --- @kx_free@ --- *
508 * Arguments: @keyexch *kx@ = pointer to key exchange context
512 * Use: Frees everything in a key exchange context.
515 extern void kx_free(keyexch */*kx*/);
517 /* --- @kx_newkeys@ --- *
519 * Arguments: @keyexch *kx@ = pointer to key exchange context
523 * Use: Informs the key exchange module that its keys may have
524 * changed. If fetching the new keys fails, the peer will be
525 * destroyed, we log messages and struggle along with the old
529 extern void kx_newkeys(keyexch */*kx*/);
531 /* --- @kx_init@ --- *
533 * Arguments: @keyexch *kx@ = pointer to key exchange context
534 * @peer *p@ = pointer to peer context
535 * @keyset **ks@ = pointer to keyset list
537 * Returns: Zero if OK, nonzero if it failed.
539 * Use: Initializes a key exchange module. The module currently
540 * contains no keys, and will attempt to initiate a key
544 extern int kx_init(keyexch */*kx*/, peer */*p*/, keyset **/*ks*/);
546 /*----- Keysets and symmetric cryptography --------------------------------*/
548 /* --- @ks_drop@ --- *
550 * Arguments: @keyset *ks@ = pointer to a keyset
554 * Use: Decrements a keyset's reference counter. If the counter hits
555 * zero, the keyset is freed.
558 extern void ks_drop(keyset */*ks*/);
560 /* --- @ks_gen@ --- *
562 * Arguments: @const void *k@ = pointer to key material
563 * @size_t x, y, z@ = offsets into key material (see below)
564 * @peer *p@ = pointer to peer information
566 * Returns: A pointer to the new keyset.
568 * Use: Derives a new keyset from the given key material. The
569 * offsets @x@, @y@ and @z@ separate the key material into three
570 * parts. Between the @k@ and @k + x@ is `my' contribution to
571 * the key material; between @k + x@ and @k + y@ is `your'
572 * contribution; and between @k + y@ and @k + z@ is a shared
573 * value we made together. These are used to construct two
574 * pairs of symmetric keys. Each pair consists of an encryption
575 * key and a message authentication key. One pair is used for
576 * outgoing messages, the other for incoming messages.
578 * The new key is marked so that it won't be selected for output
579 * by @ksl_encrypt@. You can still encrypt data with it by
580 * calling @ks_encrypt@ directly.
583 extern keyset *ks_gen(const void */*k*/,
584 size_t /*x*/, size_t /*y*/, size_t /*z*/,
587 /* --- @ks_tregen@ --- *
589 * Arguments: @keyset *ks@ = pointer to a keyset
591 * Returns: The time at which moves ought to be made to replace this key.
594 extern time_t ks_tregen(keyset */*ks*/);
596 /* --- @ks_activate@ --- *
598 * Arguments: @keyset *ks@ = pointer to a keyset
602 * Use: Activates a keyset, so that it can be used for encrypting
606 extern void ks_activate(keyset */*ks*/);
608 /* --- @ks_encrypt@ --- *
610 * Arguments: @keyset *ks@ = pointer to a keyset
611 * @unsigned ty@ = message type
612 * @buf *b@ = pointer to input buffer
613 * @buf *bb@ = pointer to output buffer
615 * Returns: Zero if OK, nonzero if the key needs replacing. If the
616 * encryption failed, the output buffer is broken and zero is
619 * Use: Encrypts a block of data using the key. Note that the `key
620 * ought to be replaced' notification is only ever given once
621 * for each key. Also note that this call forces a keyset to be
622 * used even if it's marked as not for data output.
625 extern int ks_encrypt(keyset */*ks*/, unsigned /*ty*/,
626 buf */*b*/, buf */*bb*/);
628 /* --- @ks_decrypt@ --- *
630 * Arguments: @keyset *ks@ = pointer to a keyset
631 * @unsigned ty@ = expected type code
632 * @buf *b@ = pointer to an input buffer
633 * @buf *bb@ = pointer to an output buffer
635 * Returns: Zero on success, or nonzero if there was some problem.
637 * Use: Attempts to decrypt a message using a given key. Note that
638 * requesting decryption with a key directly won't clear a
639 * marking that it's not for encryption.
642 extern int ks_decrypt(keyset */*ks*/, unsigned /*ty*/,
643 buf */*b*/, buf */*bb*/);
645 /* --- @ksl_free@ --- *
647 * Arguments: @keyset **ksroot@ = pointer to keyset list head
651 * Use: Frees (releases references to) all of the keys in a keyset.
654 extern void ksl_free(keyset **/*ksroot*/);
656 /* --- @ksl_link@ --- *
658 * Arguments: @keyset **ksroot@ = pointer to keyset list head
659 * @keyset *ks@ = pointer to a keyset
663 * Use: Links a keyset into a list. A keyset can only be on one list
664 * at a time. Bad things happen otherwise.
667 extern void ksl_link(keyset **/*ksroot*/, keyset */*ks*/);
669 /* --- @ksl_prune@ --- *
671 * Arguments: @keyset **ksroot@ = pointer to keyset list head
675 * Use: Prunes the keyset list by removing keys which mustn't be used
679 extern void ksl_prune(keyset **/*ksroot*/);
681 /* --- @ksl_encrypt@ --- *
683 * Arguments: @keyset **ksroot@ = pointer to keyset list head
684 * @unsigned ty@ = message type
685 * @buf *b@ = pointer to input buffer
686 * @buf *bb@ = pointer to output buffer
688 * Returns: Nonzero if a new key is needed.
690 * Use: Encrypts a packet.
693 extern int ksl_encrypt(keyset **/*ksroot*/, unsigned /*ty*/,
694 buf */*b*/, buf */*bb*/);
696 /* --- @ksl_decrypt@ --- *
698 * Arguments: @keyset **ksroot@ = pointer to keyset list head
699 * @unsigned ty@ = expected type code
700 * @buf *b@ = pointer to input buffer
701 * @buf *bb@ = pointer to output buffer
703 * Returns: Nonzero if the packet couldn't be decrypted.
705 * Use: Decrypts a packet.
708 extern int ksl_decrypt(keyset **/*ksroot*/, unsigned /*ty*/,
709 buf */*b*/, buf */*bb*/);
711 /*----- Administration interface ------------------------------------------*/
713 /* --- @a_warn@ --- *
715 * Arguments: @const char *fmt@ = pointer to format string
716 * @...@ = other arguments
720 * Use: Informs all admin connections of a warning.
723 extern void a_warn(const char */*fmt*/, ...);
725 /* --- @a_create@ --- *
727 * Arguments: @int fd_in, fd_out@ = file descriptors to use
731 * Use: Creates a new admin connection.
734 extern void a_create(int /*fd_in*/, int /*fd_out*/);
736 /* --- @a_quit@ --- *
742 * Use: Shuts things down nicely.
745 extern void a_quit(void);
747 /* --- @a_daemon@ --- *
753 * Use: Informs the admin module that it's a daemon.
756 extern void a_daemon(void);
758 /* --- @a_init@ --- *
760 * Arguments: @const char *sock@ = socket name to create
764 * Use: Creates the admin listening socket.
767 extern void a_init(const char */*sock*/);
769 /*----- Peer management ---------------------------------------------------*/
771 /* --- @p_txstart@ --- *
773 * Arguments: @peer *p@ = pointer to peer block
774 * @unsigned msg@ = message type code
776 * Returns: A pointer to a buffer to write to.
778 * Use: Starts sending to a peer. Only one send can happen at a
782 extern buf *p_txstart(peer */*p*/, unsigned /*msg*/);
784 /* --- @p_txend@ --- *
786 * Arguments: @peer *p@ = pointer to peer block
790 * Use: Sends a packet to the peer.
793 extern void p_txend(peer */*p*/);
797 * Arguments: @peer *p@ = pointer to peer block
798 * @buf *b@ = buffer containing incoming packet
802 * Use: Handles a packet which needs to be sent to a peer.
805 extern void p_tun(peer */*p*/, buf */*b*/);
807 /* --- @p_interval@ --- *
813 * Use: Called periodically to do tidying.
816 extern void p_interval(void);
818 /* --- @p_stats@ --- *
820 * Arguments: @peer *p@ = pointer to a peer block
822 * Returns: A pointer to the peer's statistics.
825 extern stats *p_stats(peer */*p*/);
827 /* --- @p_ifname@ --- *
829 * Arguments: @peer *p@ = pointer to a peer block
831 * Returns: A pointer to the peer's interface name.
834 extern const char *p_ifname(peer */*p*/);
836 /* --- @p_addr@ --- *
838 * Arguments: @peer *p@ = pointer to a peer block
840 * Returns: A pointer to the peer's address.
843 extern const addr *p_addr(peer */*p*/);
845 /* --- @p_init@ --- *
847 * Arguments: @struct in_addr addr@ = address to bind to
848 * @unsigned port@ = port number to listen to
852 * Use: Initializes the peer system; creates the socket.
855 extern void p_init(struct in_addr /*addr*/, unsigned /*port*/);
857 /* --- @p_port@ --- *
861 * Returns: Port number used for socket.
864 unsigned p_port(void);
866 /* --- @p_create@ --- *
868 * Arguments: @const char *name@ = name for this peer
869 * @struct sockaddr *sa@ = socket address of peer
870 * @size_t sz@ = size of socket address
872 * Returns: Pointer to the peer block, or null if it failed.
874 * Use: Creates a new named peer block. No peer is actually attached
878 extern peer *p_create(const char */*name*/,
879 struct sockaddr */*sa*/, size_t /*sz*/);
881 /* --- @p_name@ --- *
883 * Arguments: @peer *p@ = pointer to a peer block
885 * Returns: A pointer to the peer's name.
888 extern const char *p_name(peer */*p*/);
890 /* --- @p_find@ --- *
892 * Arguments: @const char *name@ = name to look up
894 * Returns: Pointer to the peer block, or null if not found.
896 * Use: Finds a peer by name.
899 extern peer *p_find(const char */*name*/);
901 /* --- @p_destroy@ --- *
903 * Arguments: @peer *p@ = pointer to a peer
907 * Use: Destroys a peer.
910 extern void p_destroy(peer */*p*/);
912 /* --- @p_first@, @p_next@ --- *
914 * Arguments: @peer *p@ = a peer block
916 * Returns: @peer_first@ returns the first peer in some ordering;
917 * @peer_next@ returns the peer following a given one in the
918 * same ordering. Null is returned for the end of the list.
921 extern peer *p_first(void);
922 extern peer *p_next(peer */*p*/);
924 /*----- Tunnel interface --------------------------------------------------*/
926 /* --- @tun_init@ --- *
932 * Use: Initializes the tunneling system. Maybe this will require
933 * opening file descriptors or something.
936 extern void tun_init(void);
938 /* --- @tun_create@ --- *
940 * Arguments: @tunnel *t@ = pointer to tunnel block
941 * @peer *p@ = pointer to peer block
943 * Returns: Zero if it worked, nonzero on failure.
945 * Use: Initializes a new tunnel.
948 extern int tun_create(tunnel */*t*/, peer */*p*/);
950 /* --- @tun_ifname@ --- *
952 * Arguments: @tunnel *t@ = pointer to tunnel block
954 * Returns: A pointer to the tunnel's interface name.
957 extern const char *tun_ifname(tunnel */*t*/);
959 /* --- @tun_inject@ --- *
961 * Arguments: @tunnel *t@ = pointer to tunnel block
962 * @buf *b@ = buffer to send
966 * Use: Injects a packet into the local network stack.
969 extern void tun_inject(tunnel */*t*/, buf */*b*/);
971 /* --- @tun_destroy@ --- *
973 * Arguments: @tunnel *t@ = pointer to tunnel block
977 * Use: Destroys a tunnel.
980 extern void tun_destroy(tunnel */*t*/);
982 /*----- Other handy utilities ---------------------------------------------*/
986 * Arguments: @mp *m@ = a multiprecision integer
988 * Returns: A pointer to the integer's textual representation.
990 * Use: Converts a multiprecision integer to a string. Corrupts
994 extern const char *mpstr(mp */*m*/);
998 * Arguments: @group *g@ = a group
999 * @ge *x@ = a group element
1001 * Returns: A pointer to the element's textual representation.
1003 * Use: Converts a group element to a string. Corrupts
1007 extern const char *gestr(group */*g*/, ge */*x*/);
1009 /* --- @timestr@ --- *
1011 * Arguments: @time_t t@ = a time to convert
1013 * Returns: A pointer to a textual representation of the time.
1015 * Use: Converts a time to a textual representation. Corrupts
1019 extern const char *timestr(time_t /*t*/);
1021 /*----- That's all, folks -------------------------------------------------*/