- fixed poll emulation management
[vde.git] / vde-2 / vde_cryptcab / blowfish.h
blobe72a1e6c5d5fe9d91b1d77eb2e40bf8a3c148047
1 /*
2 * Blowfish headers
3 * Copyright © 2006 Daniele Lacamera
4 * Released under the terms of GNU GPL v.2
5 * http://www.gnu.org/copyleft/gpl.html
7 * This program is released under the GPL with the additional exemption that
8 * compiling, linking, and/or using OpenSSL is allowed.
9 */
11 #ifndef __BLOWFISH_H
12 #define __BLOWFISH_H
15 #include <openssl/blowfish.h>
16 #include <openssl/evp.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include <sys/time.h>
21 #include <sys/stat.h>
22 #include <sys/socket.h>
23 #include <net/if.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
26 #include <fcntl.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <time.h>
33 #include <libvdeplug/libvdeplug.h>
35 #define IP_SIZE 1024
36 #define OP_SIZE 1032
37 #define MAXPKT 2000
38 #define FILENAMESIZE 16
40 #ifdef XOR
41 #undef XOR
42 #endif
43 #define XOR(a,b) a==b?0:1
45 #define before_time(a,b) a.tv_sec==b.tv_sec?a.tv_usec<b.tv_usec:a.tv_sec<b.tv_sec
47 #ifdef MIN
48 #undef MIN
49 #endif
50 #define MIN(a,b) a<b?a:b
52 #define SRC_VDE 0
53 #define SRC_BF 1
54 #define SRC_CTL 2
56 #define PKT_DATA 0x20
57 #define PKT_CTL 0x40
59 #define CMD_LOGIN 0x41
60 #define CMD_CHALLENGE 0x42
61 #define CMD_RESPONSE 0x44
62 #define CMD_AUTH_OK 0x48
63 #define CMD_DENY 0x4A
64 #define CMD_HANDOVER 0x4C
65 #define CMD_IDENTIFY 0x4E
67 #define ST_CLOSED 0
68 #define ST_OPENING 1
69 #define ST_CHALLENGE 2
70 #define ST_AUTH 3
71 #define ST_SERVER 4
72 #define ST_WAIT_AUTH 5
73 #define ST_IDSENT 6
75 #define SESSION_TIMEOUT 120
76 #define time_now(x) gettimeofday(x,NULL)
80 * This struct contains the other endpoint's informations.
82 struct peer
84 struct peer *next; /* Next list element */
85 unsigned long long counter; /* Progressive N number */
86 unsigned char key[16]; /* Blowfish key */
87 unsigned char iv[8]; /* Blowfish vector */
88 char id[FILENAMESIZE]; /* Filename for key on server */
89 char challenge[128]; /* 128B Challenge for 4WHS */
90 struct sockaddr_in in_a; /* Current transport address */
91 struct sockaddr_in handover_a; /* Handover transport address */
92 struct timeval expire; /* Expiration timer */
93 unsigned char state; /* Connection state */
94 VDECONN *plug; /* Vde connection channel */
97 #define ip_address(X) X->in_a.sin_addr.s_addr
98 #define after(a,b) (a.tv_sec == b.tv_sec ) ? (a.tv_usec > b.tv_usec) : (a.tv_sec > b.tv_sec)
102 * Each datagram received from network or from vde_plug
103 * is arranged into a struct like this.
105 struct datagram
107 unsigned char data[MAXPKT];
108 int len;
109 int src;
110 struct peer *orig;
115 struct peer
116 *getpeer(struct sockaddr_in address);
118 void
119 addpeer(struct peer *np);
121 void
122 removepeer(struct peer *np);
124 struct peer
125 *generate_key (struct peer*, char*);
127 void
128 blowfish_init(int);
130 struct datagram
131 *blowfish_select(int timeout);
133 void
134 blowfish_login(struct peer *p);
136 void
137 send_udp(unsigned char *data, size_t len, struct peer *p, unsigned char flags );
139 void
140 send_vde( const char *data, size_t len, struct peer *p);
142 void
143 autocleaner(int signo);
145 void
146 deny_access(struct peer *p);
148 void
149 rcv_login(struct datagram *pkt, struct peer *p, char *);
151 struct peer
152 *getpeerbynewaddr(struct sockaddr_in saddr);
154 void
155 rcv_response(struct datagram *pkt, struct peer *p, void (*callback)(struct peer*));
157 void
158 rcv_challenge(struct datagram *pkt, struct peer *p);
160 struct peer
161 *getpeerbyid(struct datagram *pkt);
163 void
164 vde_plug(struct peer *);
166 #endif