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>
84 #include <catacomb/buf.h>
86 #include <catacomb/gcipher.h>
87 #include <catacomb/gmac.h>
88 #include <catacomb/grand.h>
89 #include <catacomb/key.h>
90 #include <catacomb/paranoia.h>
92 #include <catacomb/noise.h>
93 #include <catacomb/rand.h>
95 #include <catacomb/mp.h>
96 #include <catacomb/mprand.h>
97 #include <catacomb/dh.h>
98 #include <catacomb/ec.h>
99 #include <catacomb/ec-keys.h>
100 #include <catacomb/group.h>
102 #include "tripe-protocol.h"
107 /*----- Magic numbers -----------------------------------------------------*/
109 /* --- Tunnel types --- */
117 /* --- Trace flags --- */
125 #define T_KEYEXCH 64u
126 #define T_KEYMGMT 128u
132 #define SEC(n) (n##u)
133 #define MIN(n) (n##u * 60u)
134 #define MEG(n) (n##ul * 1024ul * 1024ul)
136 /* --- Other things --- */
138 #define PKBUFSZ 65536
140 /*----- Cipher selections -------------------------------------------------*/
142 typedef struct algswitch {
143 const gccipher *c; /* Symmetric encryption scheme */
144 const gccipher *mgf; /* Mask-generation function */
145 const gchash *h; /* Hash function */
146 const gcmac *m; /* Message authentication code */
147 size_t hashsz; /* Hash output size */
148 size_t tagsz; /* Length to truncate MAC tags */
149 size_t cksz, mksz; /* Key lengths for @c@ and @m@ */
152 extern algswitch algs;
154 #define MAXHASHSZ 64 /* Largest possible hash size */
156 #define HASH_STRING(h, s) GH_HASH((h), (s), sizeof(s))
158 /*----- Data structures ---------------------------------------------------*/
160 /* --- Socket addresses --- *
162 * A magic union of supported socket addresses.
167 struct sockaddr_in sin;
170 /* --- A symmetric keyset --- *
172 * A keyset contains a set of symmetric keys for encrypting and decrypting
173 * packets. Keysets are stored in a list, sorted in reverse order of
174 * creation, so that the most recent keyset (the one most likely to be used)
177 * Each keyset has a time limit and a data limit. The keyset is destroyed
178 * when either it has existed for too long, or it has been used to encrypt
179 * too much data. New key exchanges are triggered when keys are close to
183 typedef struct keyset {
184 struct keyset *next; /* Next active keyset in the list */
185 unsigned ref; /* Reference count for keyset */
186 struct peer *p; /* Pointer to peer structure */
187 time_t t_exp; /* Expiry time for this keyset */
188 unsigned long sz_exp; /* Data limit for the keyset */
189 T( unsigned seq; ) /* Sequence number for tracing */
190 unsigned f; /* Various useful flags */
191 gcipher *cin, *cout; /* Keyset ciphers for encryption */
192 size_t tagsz; /* Length to truncate MAC tags */
193 gmac *min, *mout; /* Keyset MACs for integrity */
194 uint32 oseq; /* Outbound sequence number */
195 uint32 iseq, iwin; /* Inbound sequence number */
198 #define KS_SEQWINSZ 32 /* Bits in sequence number window */
200 #define KSF_LISTEN 1u /* Don't encrypt packets yet */
201 #define KSF_LINK 2u /* Key is in a linked list */
203 /* --- Key exchange --- *
205 * TrIPE uses the Wrestlers Protocol for its key exchange. The Wrestlers
206 * Protocol has a number of desirable features (e.g., perfect forward
207 * secrecy, and zero-knowledge authentication) which make it attractive for
208 * use in TrIPE. The Wrestlers Protocol was designed by Mark Wooding and
215 typedef struct kxchal {
216 struct keyexch *kx; /* Pointer back to key exchange */
217 ge *c; /* Responder's challenge */
218 ge *r; /* My reply to the challenge */
219 keyset *ks; /* Pointer to temporary keyset */
220 unsigned f; /* Various useful flags */
221 sel_timer t; /* Response timer for challenge */
222 octet hc[MAXHASHSZ]; /* Hash of his challenge */
223 mp *ck; /* The check value */
224 octet hswrq_in[MAXHASHSZ]; /* Inbound switch request message */
225 octet hswok_in[MAXHASHSZ]; /* Inbound switch confirmation */
226 octet hswrq_out[MAXHASHSZ]; /* Outbound switch request message */
227 octet hswok_out[MAXHASHSZ]; /* Outbound switch confirmation */
230 typedef struct keyexch {
231 struct peer *p; /* Pointer back to the peer */
232 keyset **ks; /* Peer's list of keysets */
233 unsigned f; /* Various useful flags */
234 unsigned s; /* Current state in exchange */
235 sel_timer t; /* Timer for next exchange */
236 ge *kpub; /* Peer's public key */
237 time_t texp_kpub; /* Expiry time for public key */
238 mp *alpha; /* My temporary secret */
239 ge *c; /* My challenge */
240 ge *rx; /* The expected response */
241 unsigned nr; /* Number of extant responses */
242 time_t t_valid; /* When this exchange goes bad */
243 octet hc[MAXHASHSZ]; /* Hash of my challenge */
244 kxchal *r[KX_NCHAL]; /* Array of challenges */
247 #define KXF_TIMER 1u /* Waiting for a timer to go off */
248 #define KXF_DEAD 2u /* The key-exchanger isn't up */
249 #define KXF_PUBKEY 4u /* Key exchanger has a public key */
252 KXS_DEAD, /* Uninitialized state (magical) */
253 KXS_CHAL, /* Main answer-challenges state */
254 KXS_COMMIT, /* Committed: send switch request */
255 KXS_SWITCH /* Switched: send confirmation */
258 /* --- Tunnel structure --- *
260 * Used to maintain system-specific information about the tunnel interface.
263 #if TUN_TYPE == TUN_LINUX
264 # include <linux/if.h>
265 # include <linux/if_tun.h>
268 #if TUN_TYPE == TUN_SLIP
269 typedef struct slipif {
270 struct slipif *next; /* Next one in the list */
271 int ifd, ofd; /* File descriptors to talk on */
272 char *name; /* Interface name */
273 unsigned f; /* Various flags */
274 # define SLIPIFF_INUSE 1u /* Interface is in use */
278 typedef struct tunnel {
279 #if TUN_TYPE == TUN_UNET
280 sel_file f; /* Selector for Usernet device */
281 struct peer *p; /* Pointer to my peer */
282 #elif TUN_TYPE == TUN_LINUX
283 sel_file f; /* Selector for TUN/TAP device */
284 struct peer *p; /* Pointer to my peer */
285 char ifn[IFNAMSIZ]; /* Interface name buffer */
286 #elif TUN_TYPE == TUN_BSD
287 sel_file f; /* Selector for tunnel device */
288 struct peer *p; /* Pointer to my peer */
289 unsigned n; /* Number of my tunnel device */
290 #elif TUN_TYPE == TUN_SLIP
291 slipif *sl; /* My interface record */
292 sel_file f; /* Selector for SLIP tty */
293 struct peer *p; /* Pointer to my peer */
294 unsigned st; /* Current parser state */
295 # define SLIPST_ESC 1u /* Last saw an escape character */
296 # define SLIPST_BAD 2u /* This packet is malformed */
297 # define SLIPST_EOF 4u /* File descriptor reported EOF */
298 size_t n; /* Number of bytes used in buffer */
299 octet buf[PKBUFSZ]; /* Buffer for incoming data */
301 # error "No support for this tunnel type"
305 /* --- Peer statistics --- *
307 * Contains various interesting and not-so-interesting statistics about a
308 * peer. This is updated by various parts of the code. The format of the
309 * structure isn't considered private, and @p_stats@ returns a pointer to the
310 * statistics block for a given peer.
313 typedef struct stats {
314 unsigned long sz_in, sz_out; /* Size of all data in and out */
315 unsigned long sz_kxin, sz_kxout; /* Size of key exchange messages */
316 unsigned long sz_ipin, sz_ipout; /* Size of encapsulated IP packets */
317 time_t t_start, t_last, t_kx; /* Time peer created, last pk, kx */
318 unsigned long n_reject; /* Number of rejected packets */
319 unsigned long n_in, n_out; /* Number of packets in and out */
320 unsigned long n_kxin, n_kxout; /* Number of key exchange packets */
321 unsigned long n_ipin, n_ipout; /* Number of encrypted packets */
324 /* --- Peer structure --- *
326 * The main structure which glues everything else together.
329 typedef struct peer {
330 struct peer *next, *prev; /* Links to next and previous */
331 char *name; /* Name of this peer */
332 tunnel t; /* Tunnel for local packets */
333 keyset *ks; /* List head for keysets */
334 buf b; /* Buffer for sending packets */
335 addr peer; /* Peer socket address */
336 size_t sasz; /* Socket address size */
337 stats st; /* Statistics */
338 keyexch kx; /* Key exchange protocol block */
341 /* --- Admin structure --- */
343 #define OBUFSZ 16384u
345 typedef struct obuf {
346 struct obuf *next; /* Next buffer in list */
347 char *p_in, *p_out; /* Pointers into the buffer */
348 char buf[OBUFSZ]; /* The actual buffer */
351 typedef struct admin {
352 struct admin *next, *prev; /* Links to next and previous */
353 unsigned f; /* Various useful flags */
355 unsigned seq; /* Sequence number for tracing */
357 char *pname; /* Peer name to create */
358 char *paddr; /* Address string to resolve */
359 obuf *o_head, *o_tail; /* Output buffer list */
360 selbuf b; /* Line buffer for commands */
361 sel_file w; /* Selector for write buffering */
362 bres_client r; /* Background resolver task */
363 sel_timer t; /* Timer for resolver */
364 addr peer; /* Address to set */
365 size_t sasz; /* Size of the address */
368 #define AF_DEAD 1u /* Destroy this admin block */
369 #define AF_LOCK 2u /* Don't destroy it yet */
370 #define AF_NOTE 4u /* Catch notifications */
372 #define AF_TRACE 8u /* Catch tracing */
374 #define AF_WARN 16u /* Catch warning messages */
377 # define AF_ALLMSGS (AF_NOTE | AF_TRACE | AF_WARN)
379 # define AF_ALLMSGS (AF_NOTE | AF_WARN)
382 /*----- Global variables --------------------------------------------------*/
384 extern sel_state sel; /* Global I/O event state */
385 extern group *gg; /* The group we work in */
386 extern mp *kpriv; /* Our private key */
387 extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
390 extern const trace_opt tr_opts[]; /* Trace options array */
391 extern unsigned tr_flags; /* Trace options flags */
394 /*----- Other macros ------------------------------------------------------*/
396 #define TIMER noise_timer(RAND_GLOBAL)
398 /*----- Key management ----------------------------------------------------*/
400 /* --- @km_interval@ --- *
404 * Returns: Zero if OK, nonzero to force reloading of keys.
406 * Use: Called on the interval timer to perform various useful jobs.
409 extern int km_interval(void);
411 /* --- @km_init@ --- *
413 * Arguments: @const char *kr_priv@ = private keyring file
414 * @const char *kr_pub@ = public keyring file
415 * @const char *tag@ = tag to load
419 * Use: Initializes, and loads the private key.
422 extern void km_init(const char */*kr_priv*/, const char */*kr_pub*/,
423 const char */*tag*/);
425 /* --- @km_getpubkey@ --- *
427 * Arguments: @const char *tag@ = public key tag to load
428 * @ge *kpub@ = where to put the public key
429 * @time_t *t_exp@ = where to put the expiry time
431 * Returns: Zero if OK, nonzero if it failed.
433 * Use: Fetches a public key from the keyring.
436 extern int km_getpubkey(const char */*tag*/, ge */*kpub*/,
439 /*----- Key exchange ------------------------------------------------------*/
441 /* --- @kx_start@ --- *
443 * Arguments: @keyexch *kx@ = pointer to key exchange context
447 * Use: Stimulates a key exchange. If a key exchage is in progress,
448 * a new challenge is sent (unless the quiet timer forbids
449 * this); if no exchange is in progress, one is commenced.
452 extern void kx_start(keyexch */*kx*/);
454 /* --- @kx_message@ --- *
456 * Arguments: @keyexch *kx@ = pointer to key exchange context
457 * @unsigned msg@ = the message code
458 * @buf *b@ = pointer to buffer containing the packet
462 * Use: Reads a packet containing key exchange messages and handles
466 extern void kx_message(keyexch */*kx*/, unsigned /*msg*/, buf */*b*/);
468 /* --- @kx_free@ --- *
470 * Arguments: @keyexch *kx@ = pointer to key exchange context
474 * Use: Frees everything in a key exchange context.
477 extern void kx_free(keyexch */*kx*/);
479 /* --- @kx_newkeys@ --- *
481 * Arguments: @keyexch *kx@ = pointer to key exchange context
485 * Use: Informs the key exchange module that its keys may have
486 * changed. If fetching the new keys fails, the peer will be
487 * destroyed, we log messages and struggle along with the old
491 extern void kx_newkeys(keyexch */*kx*/);
493 /* --- @kx_init@ --- *
495 * Arguments: @keyexch *kx@ = pointer to key exchange context
496 * @peer *p@ = pointer to peer context
497 * @keyset **ks@ = pointer to keyset list
499 * Returns: Zero if OK, nonzero if it failed.
501 * Use: Initializes a key exchange module. The module currently
502 * contains no keys, and will attempt to initiate a key
506 extern int kx_init(keyexch */*kx*/, peer */*p*/, keyset **/*ks*/);
508 /*----- Keysets and symmetric cryptography --------------------------------*/
510 /* --- @ks_drop@ --- *
512 * Arguments: @keyset *ks@ = pointer to a keyset
516 * Use: Decrements a keyset's reference counter. If the counter hits
517 * zero, the keyset is freed.
520 extern void ks_drop(keyset */*ks*/);
522 /* --- @ks_gen@ --- *
524 * Arguments: @const void *k@ = pointer to key material
525 * @size_t x, y, z@ = offsets into key material (see below)
526 * @peer *p@ = pointer to peer information
528 * Returns: A pointer to the new keyset.
530 * Use: Derives a new keyset from the given key material. The
531 * offsets @x@, @y@ and @z@ separate the key material into three
532 * parts. Between the @k@ and @k + x@ is `my' contribution to
533 * the key material; between @k + x@ and @k + y@ is `your'
534 * contribution; and between @k + y@ and @k + z@ is a shared
535 * value we made together. These are used to construct two
536 * pairs of symmetric keys. Each pair consists of an encryption
537 * key and a message authentication key. One pair is used for
538 * outgoing messages, the other for incoming messages.
540 * The new key is marked so that it won't be selected for output
541 * by @ksl_encrypt@. You can still encrypt data with it by
542 * calling @ks_encrypt@ directly.
545 extern keyset *ks_gen(const void */*k*/,
546 size_t /*x*/, size_t /*y*/, size_t /*z*/,
549 /* --- @ks_tregen@ --- *
551 * Arguments: @keyset *ks@ = pointer to a keyset
553 * Returns: The time at which moves ought to be made to replace this key.
556 extern time_t ks_tregen(keyset */*ks*/);
558 /* --- @ks_activate@ --- *
560 * Arguments: @keyset *ks@ = pointer to a keyset
564 * Use: Activates a keyset, so that it can be used for encrypting
568 extern void ks_activate(keyset */*ks*/);
570 /* --- @ks_encrypt@ --- *
572 * Arguments: @keyset *ks@ = pointer to a keyset
573 * @unsigned ty@ = message type
574 * @buf *b@ = pointer to input buffer
575 * @buf *bb@ = pointer to output buffer
577 * Returns: Zero if OK, nonzero if the key needs replacing. If the
578 * encryption failed, the output buffer is broken and zero is
581 * Use: Encrypts a block of data using the key. Note that the `key
582 * ought to be replaced' notification is only ever given once
583 * for each key. Also note that this call forces a keyset to be
584 * used even if it's marked as not for data output.
587 extern int ks_encrypt(keyset */*ks*/, unsigned /*ty*/,
588 buf */*b*/, buf */*bb*/);
590 /* --- @ks_decrypt@ --- *
592 * Arguments: @keyset *ks@ = pointer to a keyset
593 * @unsigned ty@ = expected type code
594 * @buf *b@ = pointer to an input buffer
595 * @buf *bb@ = pointer to an output buffer
597 * Returns: Zero on success, or nonzero if there was some problem.
599 * Use: Attempts to decrypt a message using a given key. Note that
600 * requesting decryption with a key directly won't clear a
601 * marking that it's not for encryption.
604 extern int ks_decrypt(keyset */*ks*/, unsigned /*ty*/,
605 buf */*b*/, buf */*bb*/);
607 /* --- @ksl_free@ --- *
609 * Arguments: @keyset **ksroot@ = pointer to keyset list head
613 * Use: Frees (releases references to) all of the keys in a keyset.
616 extern void ksl_free(keyset **/*ksroot*/);
618 /* --- @ksl_link@ --- *
620 * Arguments: @keyset **ksroot@ = pointer to keyset list head
621 * @keyset *ks@ = pointer to a keyset
625 * Use: Links a keyset into a list. A keyset can only be on one list
626 * at a time. Bad things happen otherwise.
629 extern void ksl_link(keyset **/*ksroot*/, keyset */*ks*/);
631 /* --- @ksl_prune@ --- *
633 * Arguments: @keyset **ksroot@ = pointer to keyset list head
637 * Use: Prunes the keyset list by removing keys which mustn't be used
641 extern void ksl_prune(keyset **/*ksroot*/);
643 /* --- @ksl_encrypt@ --- *
645 * Arguments: @keyset **ksroot@ = pointer to keyset list head
646 * @unsigned ty@ = message type
647 * @buf *b@ = pointer to input buffer
648 * @buf *bb@ = pointer to output buffer
650 * Returns: Nonzero if a new key is needed.
652 * Use: Encrypts a packet.
655 extern int ksl_encrypt(keyset **/*ksroot*/, unsigned /*ty*/,
656 buf */*b*/, buf */*bb*/);
658 /* --- @ksl_decrypt@ --- *
660 * Arguments: @keyset **ksroot@ = pointer to keyset list head
661 * @unsigned ty@ = expected type code
662 * @buf *b@ = pointer to input buffer
663 * @buf *bb@ = pointer to output buffer
665 * Returns: Nonzero if the packet couldn't be decrypted.
667 * Use: Decrypts a packet.
670 extern int ksl_decrypt(keyset **/*ksroot*/, unsigned /*ty*/,
671 buf */*b*/, buf */*bb*/);
673 /*----- Administration interface ------------------------------------------*/
675 /* --- @a_warn@ --- *
677 * Arguments: @const char *fmt@ = pointer to format string
678 * @...@ = other arguments
682 * Use: Informs all admin connections of a warning.
685 extern void a_warn(const char */*fmt*/, ...);
687 /* --- @a_notify@ --- *
689 * Arguments: @const char *fmt@ = pointer to format string
690 * @...@ = other arguments
694 * Use: Sends a notification to interested admin connections.
697 extern void a_notify(const char */*fmt*/, ...);
699 /* --- @a_create@ --- *
701 * Arguments: @int fd_in, fd_out@ = file descriptors to use
702 * @unsigned f@ = initial flags to set
706 * Use: Creates a new admin connection.
709 extern void a_create(int /*fd_in*/, int /*fd_out*/, unsigned /*f*/);
711 /* --- @a_quit@ --- *
717 * Use: Shuts things down nicely.
720 extern void a_quit(void);
722 /* --- @a_daemon@ --- *
728 * Use: Informs the admin module that it's a daemon.
731 extern void a_daemon(void);
733 /* --- @a_init@ --- *
735 * Arguments: @const char *sock@ = socket name to create
739 * Use: Creates the admin listening socket.
742 extern void a_init(const char */*sock*/);
744 /*----- Peer management ---------------------------------------------------*/
746 /* --- @p_txstart@ --- *
748 * Arguments: @peer *p@ = pointer to peer block
749 * @unsigned msg@ = message type code
751 * Returns: A pointer to a buffer to write to.
753 * Use: Starts sending to a peer. Only one send can happen at a
757 extern buf *p_txstart(peer */*p*/, unsigned /*msg*/);
759 /* --- @p_txend@ --- *
761 * Arguments: @peer *p@ = pointer to peer block
765 * Use: Sends a packet to the peer.
768 extern void p_txend(peer */*p*/);
772 * Arguments: @peer *p@ = pointer to peer block
773 * @buf *b@ = buffer containing incoming packet
777 * Use: Handles a packet which needs to be sent to a peer.
780 extern void p_tun(peer */*p*/, buf */*b*/);
782 /* --- @p_interval@ --- *
788 * Use: Called periodically to do tidying.
791 extern void p_interval(void);
793 /* --- @p_stats@ --- *
795 * Arguments: @peer *p@ = pointer to a peer block
797 * Returns: A pointer to the peer's statistics.
800 extern stats *p_stats(peer */*p*/);
802 /* --- @p_ifname@ --- *
804 * Arguments: @peer *p@ = pointer to a peer block
806 * Returns: A pointer to the peer's interface name.
809 extern const char *p_ifname(peer */*p*/);
811 /* --- @p_addr@ --- *
813 * Arguments: @peer *p@ = pointer to a peer block
815 * Returns: A pointer to the peer's address.
818 extern const addr *p_addr(peer */*p*/);
820 /* --- @p_init@ --- *
822 * Arguments: @struct in_addr addr@ = address to bind to
823 * @unsigned port@ = port number to listen to
827 * Use: Initializes the peer system; creates the socket.
830 extern void p_init(struct in_addr /*addr*/, unsigned /*port*/);
832 /* --- @p_port@ --- *
836 * Returns: Port number used for socket.
839 unsigned p_port(void);
841 /* --- @p_create@ --- *
843 * Arguments: @const char *name@ = name for this peer
844 * @struct sockaddr *sa@ = socket address of peer
845 * @size_t sz@ = size of socket address
847 * Returns: Pointer to the peer block, or null if it failed.
849 * Use: Creates a new named peer block. No peer is actually attached
853 extern peer *p_create(const char */*name*/,
854 struct sockaddr */*sa*/, size_t /*sz*/);
856 /* --- @p_name@ --- *
858 * Arguments: @peer *p@ = pointer to a peer block
860 * Returns: A pointer to the peer's name.
863 extern const char *p_name(peer */*p*/);
865 /* --- @p_find@ --- *
867 * Arguments: @const char *name@ = name to look up
869 * Returns: Pointer to the peer block, or null if not found.
871 * Use: Finds a peer by name.
874 extern peer *p_find(const char */*name*/);
876 /* --- @p_destroy@ --- *
878 * Arguments: @peer *p@ = pointer to a peer
882 * Use: Destroys a peer.
885 extern void p_destroy(peer */*p*/);
887 /* --- @p_first@, @p_next@ --- *
889 * Arguments: @peer *p@ = a peer block
891 * Returns: @peer_first@ returns the first peer in some ordering;
892 * @peer_next@ returns the peer following a given one in the
893 * same ordering. Null is returned for the end of the list.
896 extern peer *p_first(void);
897 extern peer *p_next(peer */*p*/);
899 /*----- Tunnel interface --------------------------------------------------*/
901 /* --- @tun_init@ --- *
907 * Use: Initializes the tunneling system. Maybe this will require
908 * opening file descriptors or something.
911 extern void tun_init(void);
913 /* --- @tun_create@ --- *
915 * Arguments: @tunnel *t@ = pointer to tunnel block
916 * @peer *p@ = pointer to peer block
918 * Returns: Zero if it worked, nonzero on failure.
920 * Use: Initializes a new tunnel.
923 extern int tun_create(tunnel */*t*/, peer */*p*/);
925 /* --- @tun_ifname@ --- *
927 * Arguments: @tunnel *t@ = pointer to tunnel block
929 * Returns: A pointer to the tunnel's interface name.
932 extern const char *tun_ifname(tunnel */*t*/);
934 /* --- @tun_inject@ --- *
936 * Arguments: @tunnel *t@ = pointer to tunnel block
937 * @buf *b@ = buffer to send
941 * Use: Injects a packet into the local network stack.
944 extern void tun_inject(tunnel */*t*/, buf */*b*/);
946 /* --- @tun_destroy@ --- *
948 * Arguments: @tunnel *t@ = pointer to tunnel block
952 * Use: Destroys a tunnel.
955 extern void tun_destroy(tunnel */*t*/);
957 /*----- Other handy utilities ---------------------------------------------*/
961 * Arguments: @mp *m@ = a multiprecision integer
963 * Returns: A pointer to the integer's textual representation.
965 * Use: Converts a multiprecision integer to a string. Corrupts
969 extern const char *mpstr(mp */*m*/);
973 * Arguments: @group *g@ = a group
974 * @ge *x@ = a group element
976 * Returns: A pointer to the element's textual representation.
978 * Use: Converts a group element to a string. Corrupts
982 extern const char *gestr(group */*g*/, ge */*x*/);
984 /* --- @timestr@ --- *
986 * Arguments: @time_t t@ = a time to convert
988 * Returns: A pointer to a textual representation of the time.
990 * Use: Converts a time to a textual representation. Corrupts
994 extern const char *timestr(time_t /*t*/);
996 /*----- That's all, folks -------------------------------------------------*/