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.
36 /*----- Header files ------------------------------------------------------*/
52 #include <sys/types.h>
58 #include <sys/socket.h>
60 #include <netinet/in.h>
61 #include <arpa/inet.h>
67 #include <mLib/alloc.h>
68 #include <mLib/arena.h>
69 #include <mLib/bres.h>
70 #include <mLib/dstr.h>
72 #include <mLib/fdflags.h>
73 #include <mLib/fwatch.h>
74 #include <mLib/mdwopt.h>
75 #include <mLib/quis.h>
76 #include <mLib/report.h>
78 #include <mLib/selbuf.h>
82 #include <mLib/trace.h>
85 #include <catacomb/buf.h>
87 #include <catacomb/gcipher.h>
88 #include <catacomb/gmac.h>
89 #include <catacomb/grand.h>
90 #include <catacomb/key.h>
91 #include <catacomb/paranoia.h>
93 #include <catacomb/noise.h>
94 #include <catacomb/rand.h>
96 #include <catacomb/mp.h>
97 #include <catacomb/mprand.h>
98 #include <catacomb/dh.h>
99 #include <catacomb/ec.h>
100 #include <catacomb/ec-keys.h>
101 #include <catacomb/group.h>
103 #include "tripe-protocol.h"
108 /*----- Magic numbers -----------------------------------------------------*/
110 /* --- Trace flags --- */
118 #define T_KEYEXCH 64u
119 #define T_KEYMGMT 128u
125 #define SEC(n) (n##u)
126 #define MIN(n) (n##u * 60u)
127 #define MEG(n) (n##ul * 1024ul * 1024ul)
129 /* --- Other things --- */
131 #define PKBUFSZ 65536
133 /*----- Cipher selections -------------------------------------------------*/
135 typedef struct algswitch {
136 const gccipher *c; /* Symmetric encryption scheme */
137 const gccipher *mgf; /* Mask-generation function */
138 const gchash *h; /* Hash function */
139 const gcmac *m; /* Message authentication code */
140 size_t hashsz; /* Hash output size */
141 size_t tagsz; /* Length to truncate MAC tags */
142 size_t cksz, mksz; /* Key lengths for @c@ and @m@ */
145 extern algswitch algs;
147 #define MAXHASHSZ 64 /* Largest possible hash size */
149 #define HASH_STRING(h, s) GH_HASH((h), (s), sizeof(s))
151 /*----- Data structures ---------------------------------------------------*/
153 /* --- Socket addresses --- *
155 * A magic union of supported socket addresses.
160 struct sockaddr_in sin;
163 /* --- A symmetric keyset --- *
165 * A keyset contains a set of symmetric keys for encrypting and decrypting
166 * packets. Keysets are stored in a list, sorted in reverse order of
167 * creation, so that the most recent keyset (the one most likely to be used)
170 * Each keyset has a time limit and a data limit. The keyset is destroyed
171 * when either it has existed for too long, or it has been used to encrypt
172 * too much data. New key exchanges are triggered when keys are close to
176 typedef struct keyset {
177 struct keyset *next; /* Next active keyset in the list */
178 unsigned ref; /* Reference count for keyset */
179 struct peer *p; /* Pointer to peer structure */
180 time_t t_exp; /* Expiry time for this keyset */
181 unsigned long sz_exp; /* Data limit for the keyset */
182 T( unsigned seq; ) /* Sequence number for tracing */
183 unsigned f; /* Various useful flags */
184 gcipher *cin, *cout; /* Keyset ciphers for encryption */
185 size_t tagsz; /* Length to truncate MAC tags */
186 gmac *min, *mout; /* Keyset MACs for integrity */
187 uint32 oseq; /* Outbound sequence number */
188 uint32 iseq, iwin; /* Inbound sequence number */
191 #define KS_SEQWINSZ 32 /* Bits in sequence number window */
193 #define KSF_LISTEN 1u /* Don't encrypt packets yet */
194 #define KSF_LINK 2u /* Key is in a linked list */
196 /* --- Key exchange --- *
198 * TrIPE uses the Wrestlers Protocol for its key exchange. The Wrestlers
199 * Protocol has a number of desirable features (e.g., perfect forward
200 * secrecy, and zero-knowledge authentication) which make it attractive for
201 * use in TrIPE. The Wrestlers Protocol was designed by Mark Wooding and
208 typedef struct kxchal {
209 struct keyexch *kx; /* Pointer back to key exchange */
210 ge *c; /* Responder's challenge */
211 ge *r; /* My reply to the challenge */
212 keyset *ks; /* Pointer to temporary keyset */
213 unsigned f; /* Various useful flags */
214 sel_timer t; /* Response timer for challenge */
215 octet hc[MAXHASHSZ]; /* Hash of his challenge */
216 mp *ck; /* The check value */
217 octet hswrq_in[MAXHASHSZ]; /* Inbound switch request message */
218 octet hswok_in[MAXHASHSZ]; /* Inbound switch confirmation */
219 octet hswrq_out[MAXHASHSZ]; /* Outbound switch request message */
220 octet hswok_out[MAXHASHSZ]; /* Outbound switch confirmation */
223 typedef struct keyexch {
224 struct peer *p; /* Pointer back to the peer */
225 keyset **ks; /* Peer's list of keysets */
226 unsigned f; /* Various useful flags */
227 unsigned s; /* Current state in exchange */
228 sel_timer t; /* Timer for next exchange */
229 ge *kpub; /* Peer's public key */
230 time_t texp_kpub; /* Expiry time for public key */
231 mp *alpha; /* My temporary secret */
232 ge *c; /* My challenge */
233 ge *rx; /* The expected response */
234 unsigned nr; /* Number of extant responses */
235 time_t t_valid; /* When this exchange goes bad */
236 octet hc[MAXHASHSZ]; /* Hash of my challenge */
237 kxchal *r[KX_NCHAL]; /* Array of challenges */
240 #define KXF_TIMER 1u /* Waiting for a timer to go off */
241 #define KXF_DEAD 2u /* The key-exchanger isn't up */
242 #define KXF_PUBKEY 4u /* Key exchanger has a public key */
245 KXS_DEAD, /* Uninitialized state (magical) */
246 KXS_CHAL, /* Main answer-challenges state */
247 KXS_COMMIT, /* Committed: send switch request */
248 KXS_SWITCH /* Switched: send confirmation */
251 /* --- Tunnel structure --- *
253 * Used to maintain system-specific information about the tunnel interface.
256 typedef struct tunnel tunnel;
259 typedef struct tunnel_ops {
260 const char *name; /* Name of this tunnel driver */
261 void (*init)(void); /* Initializes the system */
262 tunnel *(*create)(struct peer */*p*/); /* Initializes a new tunnel */
263 const char *(*ifname)(tunnel */*t*/); /* Returns tunnel's interface name */
264 void (*inject)(tunnel */*t*/, buf */*b*/); /* Sends packet through if */
265 void (*destroy)(tunnel */*t*/); /* Destroys a tunnel */
268 #ifndef TUN_INTERNALS
269 struct tunnel { const tunnel_ops *ops; };
272 /* --- Peer statistics --- *
274 * Contains various interesting and not-so-interesting statistics about a
275 * peer. This is updated by various parts of the code. The format of the
276 * structure isn't considered private, and @p_stats@ returns a pointer to the
277 * statistics block for a given peer.
280 typedef struct stats {
281 unsigned long sz_in, sz_out; /* Size of all data in and out */
282 unsigned long sz_kxin, sz_kxout; /* Size of key exchange messages */
283 unsigned long sz_ipin, sz_ipout; /* Size of encapsulated IP packets */
284 time_t t_start, t_last, t_kx; /* Time peer created, last pk, kx */
285 unsigned long n_reject; /* Number of rejected packets */
286 unsigned long n_in, n_out; /* Number of packets in and out */
287 unsigned long n_kxin, n_kxout; /* Number of key exchange packets */
288 unsigned long n_ipin, n_ipout; /* Number of encrypted packets */
291 /* --- Peer structure --- *
293 * The main structure which glues everything else together.
296 typedef struct peerspec {
297 char *name; /* Peer's name */
298 const tunnel_ops *tops; /* Tunnel operations */
299 unsigned long t_ka; /* Keep alive interval */
300 addr sa; /* Socket address to speak to */
301 size_t sasz; /* Socket address size */
304 typedef struct peer {
305 struct peer *next, *prev; /* Links to next and previous */
306 struct ping *pings; /* Pings we're waiting for */
307 peerspec spec; /* Specifications for this peer */
308 tunnel *t; /* Tunnel for local packets */
309 keyset *ks; /* List head for keysets */
310 buf b; /* Buffer for sending packets */
311 stats st; /* Statistics */
312 keyexch kx; /* Key exchange protocol block */
313 sel_timer tka; /* Timer for keepalives */
316 typedef struct ping {
317 struct ping *next, *prev; /* Links to next and previous */
318 peer *p; /* Peer so we can free it */
319 unsigned msg; /* Kind of response expected */
320 uint32 id; /* Id so we can recognize response */
321 octet magic[32]; /* Some random data */
322 sel_timer t; /* Timeout for ping */
323 void (*func)(int /*rc*/, void */*arg*/); /* Function to call when done */
324 void *arg; /* Argument for callback */
335 /* --- Admin structure --- */
337 #define OBUFSZ 16384u
339 typedef struct obuf {
340 struct obuf *next; /* Next buffer in list */
341 char *p_in, *p_out; /* Pointers into the buffer */
342 char buf[OBUFSZ]; /* The actual buffer */
345 typedef struct admin {
346 struct admin *next, *prev; /* Links to next and previous */
347 unsigned f; /* Various useful flags */
349 unsigned seq; /* Sequence number for tracing */
351 obuf *o_head, *o_tail; /* Output buffer list */
352 selbuf b; /* Line buffer for commands */
353 sel_file w; /* Selector for write buffering */
354 peerspec peer; /* Peer pending creation */
355 char *paddr; /* Hostname to be resolved */
356 bres_client r; /* Background resolver task */
357 sel_timer t; /* Timer for resolver */
358 ping ping; /* Ping pending response */
359 struct timeval pingtime; /* Time last ping was sent */
362 #define AF_DEAD 1u /* Destroy this admin block */
363 #define AF_LOCK 2u /* Don't destroy it yet */
364 #define AF_NOTE 4u /* Catch notifications */
366 #define AF_TRACE 8u /* Catch tracing */
368 #define AF_WARN 16u /* Catch warning messages */
371 # define AF_ALLMSGS (AF_NOTE | AF_TRACE | AF_WARN)
373 # define AF_ALLMSGS (AF_NOTE | AF_WARN)
376 /*----- Global variables --------------------------------------------------*/
378 extern sel_state sel; /* Global I/O event state */
379 extern group *gg; /* The group we work in */
380 extern mp *kpriv; /* Our private key */
381 extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
382 extern const tunnel_ops *tunnels[]; /* Table of tunnels (0-term) */
383 extern const tunnel_ops *tun_default; /* Default tunnel to use */
386 extern const trace_opt tr_opts[]; /* Trace options array */
387 extern unsigned tr_flags; /* Trace options flags */
390 /*----- Other macros ------------------------------------------------------*/
392 #define TIMER noise_timer(RAND_GLOBAL)
394 /*----- Key management ----------------------------------------------------*/
396 /* --- @km_interval@ --- *
400 * Returns: Zero if OK, nonzero to force reloading of keys.
402 * Use: Called on the interval timer to perform various useful jobs.
405 extern int km_interval(void);
407 /* --- @km_init@ --- *
409 * Arguments: @const char *kr_priv@ = private keyring file
410 * @const char *kr_pub@ = public keyring file
411 * @const char *tag@ = tag to load
415 * Use: Initializes, and loads the private key.
418 extern void km_init(const char */*kr_priv*/, const char */*kr_pub*/,
419 const char */*tag*/);
421 /* --- @km_getpubkey@ --- *
423 * Arguments: @const char *tag@ = public key tag to load
424 * @ge *kpub@ = where to put the public key
425 * @time_t *t_exp@ = where to put the expiry time
427 * Returns: Zero if OK, nonzero if it failed.
429 * Use: Fetches a public key from the keyring.
432 extern int km_getpubkey(const char */*tag*/, ge */*kpub*/,
435 /*----- Key exchange ------------------------------------------------------*/
437 /* --- @kx_start@ --- *
439 * Arguments: @keyexch *kx@ = pointer to key exchange context
443 * Use: Stimulates a key exchange. If a key exchage is in progress,
444 * a new challenge is sent (unless the quiet timer forbids
445 * this); if no exchange is in progress, one is commenced.
448 extern void kx_start(keyexch */*kx*/);
450 /* --- @kx_message@ --- *
452 * Arguments: @keyexch *kx@ = pointer to key exchange context
453 * @unsigned msg@ = the message code
454 * @buf *b@ = pointer to buffer containing the packet
458 * Use: Reads a packet containing key exchange messages and handles
462 extern void kx_message(keyexch */*kx*/, unsigned /*msg*/, buf */*b*/);
464 /* --- @kx_free@ --- *
466 * Arguments: @keyexch *kx@ = pointer to key exchange context
470 * Use: Frees everything in a key exchange context.
473 extern void kx_free(keyexch */*kx*/);
475 /* --- @kx_newkeys@ --- *
477 * Arguments: @keyexch *kx@ = pointer to key exchange context
481 * Use: Informs the key exchange module that its keys may have
482 * changed. If fetching the new keys fails, the peer will be
483 * destroyed, we log messages and struggle along with the old
487 extern void kx_newkeys(keyexch */*kx*/);
489 /* --- @kx_init@ --- *
491 * Arguments: @keyexch *kx@ = pointer to key exchange context
492 * @peer *p@ = pointer to peer context
493 * @keyset **ks@ = pointer to keyset list
495 * Returns: Zero if OK, nonzero if it failed.
497 * Use: Initializes a key exchange module. The module currently
498 * contains no keys, and will attempt to initiate a key
502 extern int kx_init(keyexch */*kx*/, peer */*p*/, keyset **/*ks*/);
504 /*----- Keysets and symmetric cryptography --------------------------------*/
506 /* --- @ks_drop@ --- *
508 * Arguments: @keyset *ks@ = pointer to a keyset
512 * Use: Decrements a keyset's reference counter. If the counter hits
513 * zero, the keyset is freed.
516 extern void ks_drop(keyset */*ks*/);
518 /* --- @ks_gen@ --- *
520 * Arguments: @const void *k@ = pointer to key material
521 * @size_t x, y, z@ = offsets into key material (see below)
522 * @peer *p@ = pointer to peer information
524 * Returns: A pointer to the new keyset.
526 * Use: Derives a new keyset from the given key material. The
527 * offsets @x@, @y@ and @z@ separate the key material into three
528 * parts. Between the @k@ and @k + x@ is `my' contribution to
529 * the key material; between @k + x@ and @k + y@ is `your'
530 * contribution; and between @k + y@ and @k + z@ is a shared
531 * value we made together. These are used to construct two
532 * pairs of symmetric keys. Each pair consists of an encryption
533 * key and a message authentication key. One pair is used for
534 * outgoing messages, the other for incoming messages.
536 * The new key is marked so that it won't be selected for output
537 * by @ksl_encrypt@. You can still encrypt data with it by
538 * calling @ks_encrypt@ directly.
541 extern keyset *ks_gen(const void */*k*/,
542 size_t /*x*/, size_t /*y*/, size_t /*z*/,
545 /* --- @ks_tregen@ --- *
547 * Arguments: @keyset *ks@ = pointer to a keyset
549 * Returns: The time at which moves ought to be made to replace this key.
552 extern time_t ks_tregen(keyset */*ks*/);
554 /* --- @ks_activate@ --- *
556 * Arguments: @keyset *ks@ = pointer to a keyset
560 * Use: Activates a keyset, so that it can be used for encrypting
564 extern void ks_activate(keyset */*ks*/);
566 /* --- @ks_encrypt@ --- *
568 * Arguments: @keyset *ks@ = pointer to a keyset
569 * @unsigned ty@ = message type
570 * @buf *b@ = pointer to input buffer
571 * @buf *bb@ = pointer to output buffer
573 * Returns: Zero if OK, nonzero if the key needs replacing. If the
574 * encryption failed, the output buffer is broken and zero is
577 * Use: Encrypts a block of data using the key. Note that the `key
578 * ought to be replaced' notification is only ever given once
579 * for each key. Also note that this call forces a keyset to be
580 * used even if it's marked as not for data output.
583 extern int ks_encrypt(keyset */*ks*/, unsigned /*ty*/,
584 buf */*b*/, buf */*bb*/);
586 /* --- @ks_decrypt@ --- *
588 * Arguments: @keyset *ks@ = pointer to a keyset
589 * @unsigned ty@ = expected type code
590 * @buf *b@ = pointer to an input buffer
591 * @buf *bb@ = pointer to an output buffer
593 * Returns: Zero on success, or nonzero if there was some problem.
595 * Use: Attempts to decrypt a message using a given key. Note that
596 * requesting decryption with a key directly won't clear a
597 * marking that it's not for encryption.
600 extern int ks_decrypt(keyset */*ks*/, unsigned /*ty*/,
601 buf */*b*/, buf */*bb*/);
603 /* --- @ksl_free@ --- *
605 * Arguments: @keyset **ksroot@ = pointer to keyset list head
609 * Use: Frees (releases references to) all of the keys in a keyset.
612 extern void ksl_free(keyset **/*ksroot*/);
614 /* --- @ksl_link@ --- *
616 * Arguments: @keyset **ksroot@ = pointer to keyset list head
617 * @keyset *ks@ = pointer to a keyset
621 * Use: Links a keyset into a list. A keyset can only be on one list
622 * at a time. Bad things happen otherwise.
625 extern void ksl_link(keyset **/*ksroot*/, keyset */*ks*/);
627 /* --- @ksl_prune@ --- *
629 * Arguments: @keyset **ksroot@ = pointer to keyset list head
633 * Use: Prunes the keyset list by removing keys which mustn't be used
637 extern void ksl_prune(keyset **/*ksroot*/);
639 /* --- @ksl_encrypt@ --- *
641 * Arguments: @keyset **ksroot@ = pointer to keyset list head
642 * @unsigned ty@ = message type
643 * @buf *b@ = pointer to input buffer
644 * @buf *bb@ = pointer to output buffer
646 * Returns: Nonzero if a new key is needed.
648 * Use: Encrypts a packet.
651 extern int ksl_encrypt(keyset **/*ksroot*/, unsigned /*ty*/,
652 buf */*b*/, buf */*bb*/);
654 /* --- @ksl_decrypt@ --- *
656 * Arguments: @keyset **ksroot@ = pointer to keyset list head
657 * @unsigned ty@ = expected type code
658 * @buf *b@ = pointer to input buffer
659 * @buf *bb@ = pointer to output buffer
661 * Returns: Nonzero if the packet couldn't be decrypted.
663 * Use: Decrypts a packet.
666 extern int ksl_decrypt(keyset **/*ksroot*/, unsigned /*ty*/,
667 buf */*b*/, buf */*bb*/);
669 /*----- Administration interface ------------------------------------------*/
671 /* --- @a_warn@ --- *
673 * Arguments: @const char *fmt@ = pointer to format string
674 * @...@ = other arguments
678 * Use: Informs all admin connections of a warning.
681 extern void a_warn(const char */*fmt*/, ...);
683 /* --- @a_notify@ --- *
685 * Arguments: @const char *fmt@ = pointer to format string
686 * @...@ = other arguments
690 * Use: Sends a notification to interested admin connections.
693 extern void a_notify(const char */*fmt*/, ...);
695 /* --- @a_create@ --- *
697 * Arguments: @int fd_in, fd_out@ = file descriptors to use
698 * @unsigned f@ = initial flags to set
702 * Use: Creates a new admin connection.
705 extern void a_create(int /*fd_in*/, int /*fd_out*/, unsigned /*f*/);
707 /* --- @a_quit@ --- *
713 * Use: Shuts things down nicely.
716 extern void a_quit(void);
718 /* --- @a_daemon@ --- *
724 * Use: Informs the admin module that it's a daemon.
727 extern void a_daemon(void);
729 /* --- @a_init@ --- *
731 * Arguments: @const char *sock@ = socket name to create
735 * Use: Creates the admin listening socket.
738 extern void a_init(const char */*sock*/);
740 /*----- Peer management ---------------------------------------------------*/
742 /* --- @p_txstart@ --- *
744 * Arguments: @peer *p@ = pointer to peer block
745 * @unsigned msg@ = message type code
747 * Returns: A pointer to a buffer to write to.
749 * Use: Starts sending to a peer. Only one send can happen at a
753 extern buf *p_txstart(peer */*p*/, unsigned /*msg*/);
755 /* --- @p_txend@ --- *
757 * Arguments: @peer *p@ = pointer to peer block
761 * Use: Sends a packet to the peer.
764 extern void p_txend(peer */*p*/);
766 /* --- @p_pingsend@ --- *
768 * Arguments: @peer *p@ = destination peer
769 * @ping *pg@ = structure to fill in
770 * @unsigned type@ = message type
771 * @unsigned long timeout@ = how long to wait before giving up
772 * @void (*func)(int, void *)@ = callback function
773 * @void *arg@ = argument for callback
775 * Returns: Zero if successful, nonzero if it failed.
777 * Use: Sends a ping to a peer. Call @func@ with a nonzero argument
778 * if we get an answer within the timeout, or zero if no answer.
781 extern int p_pingsend(peer */*p*/, ping */*pg*/, unsigned /*type*/,
782 unsigned long /*timeout*/,
783 void (*/*func*/)(int, void *), void */*arg*/);
785 /* --- @p_pingdone@ --- *
787 * Arguments: @ping *p@ = ping structure
788 * @int rc@ = return code to pass on
792 * Use: Disposes of a ping structure, maybe sending a notification.
795 extern void p_pingdone(ping */*p*/, int /*rc*/);
799 * Arguments: @peer *p@ = pointer to peer block
800 * @buf *b@ = buffer containing incoming packet
804 * Use: Handles a packet which needs to be sent to a peer.
807 extern void p_tun(peer */*p*/, buf */*b*/);
809 /* --- @p_interval@ --- *
815 * Use: Called periodically to do tidying.
818 extern void p_interval(void);
820 /* --- @p_stats@ --- *
822 * Arguments: @peer *p@ = pointer to a peer block
824 * Returns: A pointer to the peer's statistics.
827 extern stats *p_stats(peer */*p*/);
829 /* --- @p_ifname@ --- *
831 * Arguments: @peer *p@ = pointer to a peer block
833 * Returns: A pointer to the peer's interface name.
836 extern const char *p_ifname(peer */*p*/);
838 /* --- @p_addr@ --- *
840 * Arguments: @peer *p@ = pointer to a peer block
842 * Returns: A pointer to the peer's address.
845 extern const addr *p_addr(peer */*p*/);
847 /* --- @p_init@ --- *
849 * Arguments: @struct in_addr addr@ = address to bind to
850 * @unsigned port@ = port number to listen to
854 * Use: Initializes the peer system; creates the socket.
857 extern void p_init(struct in_addr /*addr*/, unsigned /*port*/);
859 /* --- @p_port@ --- *
863 * Returns: Port number used for socket.
866 unsigned p_port(void);
868 /* --- @p_create@ --- *
870 * Arguments: @peerspec *spec@ = information about this peer
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(peerspec */*spec*/);
880 /* --- @p_name@ --- *
882 * Arguments: @peer *p@ = pointer to a peer block
884 * Returns: A pointer to the peer's name.
887 extern const char *p_name(peer */*p*/);
889 /* --- @p_find@ --- *
891 * Arguments: @const char *name@ = name to look up
893 * Returns: Pointer to the peer block, or null if not found.
895 * Use: Finds a peer by name.
898 extern peer *p_find(const char */*name*/);
900 /* --- @p_destroy@ --- *
902 * Arguments: @peer *p@ = pointer to a peer
906 * Use: Destroys a peer.
909 extern void p_destroy(peer */*p*/);
911 /* --- @p_first@, @p_next@ --- *
913 * Arguments: @peer *p@ = a peer block
915 * Returns: @peer_first@ returns the first peer in some ordering;
916 * @peer_next@ returns the peer following a given one in the
917 * same ordering. Null is returned for the end of the list.
920 extern peer *p_first(void);
921 extern peer *p_next(peer */*p*/);
923 /*----- Tunnel drivers ----------------------------------------------------*/
926 extern const tunnel_ops tun_linux;
930 extern const tunnel_ops tun_unet;
934 extern const tunnel_ops tun_bsd;
937 extern const tunnel_ops tun_slip;
939 /*----- Other handy utilities ---------------------------------------------*/
943 * Arguments: @mp *m@ = a multiprecision integer
945 * Returns: A pointer to the integer's textual representation.
947 * Use: Converts a multiprecision integer to a string. Corrupts
951 extern const char *mpstr(mp */*m*/);
955 * Arguments: @group *g@ = a group
956 * @ge *x@ = a group element
958 * Returns: A pointer to the element's textual representation.
960 * Use: Converts a group element to a string. Corrupts
964 extern const char *gestr(group */*g*/, ge */*x*/);
966 /* --- @timestr@ --- *
968 * Arguments: @time_t t@ = a time to convert
970 * Returns: A pointer to a textual representation of the time.
972 * Use: Converts a time to a textual representation. Corrupts
976 extern const char *timestr(time_t /*t*/);
978 /* --- @mystrieq@ --- *
980 * Arguments: @const char *x, *y@ = two strings
982 * Returns: True if @x@ and @y are equal, up to case.
985 extern int mystrieq(const char */*x*/, const char */*y*/);
987 /*----- That's all, folks -------------------------------------------------*/