Merge branch 'master' of ssh://jolly@www.misdn.org/var/git/lcr
[lcr.git] / crypt.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** crypt header file                                                         **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12
13 enum { /* enpoint's user states */
14         CRYPT_OFF,              /* no encryption */
15         CRYPT_KWAIT,            /* wait for key-exchange mehtod */
16         CRYPT_SWAIT,            /* wait for shared secret method */
17         CRYPT_ON,               /* crypting */
18         CRYPT_RELEASE,          /* wait for deactivation */
19 };
20
21 #define CM_TO_IDENT     10      /* timeout for identifying remote peer */
22 #define CM_TO_PUBKEY    60      /* timeout for public key generation */
23 #define CM_TO_CSKEY     5       /* timeout for crypting session key */
24
25 enum { /* crypt manager states */
26         CM_ST_NULL,             /* no encryption used */
27         CM_ST_IDENT,            /* find the remote pary */
28         CM_ST_KEYGEN,           /* generating public/private key */
29         CM_ST_KEYWAIT,          /* waiting for public key */
30         CM_ST_CSKEY,            /* generate crypted session key */
31         CM_ST_CSWAIT,           /* wait for CSKey */
32         CM_ST_SESSION,          /* wait for session key decryption */
33         CM_ST_WAIT_DELAY,       /* wait sone time until the cskey is transferred */
34         CM_ST_WAIT_CRYPT,       /* wait for encryption from session engine */
35         CM_ST_ACTIVE,           /* done with encryption */
36         CM_ST_RELEASE,          /* wait until key engine has finished, after abort */
37
38         CM_ST_SWAIT,            /* wait for share key establishment */
39         CM_ST_SACTIVE,          /* shared key established */
40 };
41
42 #define CM_ST_NAMES \
43 static const char *cm_st_name[] = { \
44         "NULL", \
45         "IDENT", \
46         "KEYGEN", \
47         "KEYWAIT", \
48         "CSKEY", \
49         "CSWAIT", \
50         "SESSION", \
51         "WAIT_DELAY", \
52         "WAIT_CRYPT", \
53         "ACTIVE", \
54         "RELEASE", \
55         "SWAIT", \
56         "SACTIVE", \
57 }; \
58 int cm_st_num = sizeof(cm_st_name) / sizeof(char *);
59
60 enum { /* messages */
61         /* messages to/from peer */
62         CP_IDENT,               /* send random number, cpu power */
63         CP_SLAVE,               /* tell remote to be slave */
64         CP_MASTER,              /* tell remote to be master */
65         CP_LOOPED,              /* tell remote (us) that the call is looped */
66         CP_PUBKEY,              /* send public key */
67         CP_CSKEY,               /* send encrypted session key */
68         CP_ABORT,               /* send abort message */
69         /* messages to/from "key engine" */
70         CK_GENRSA_REQ,          /* generate rsa key */
71         CK_GENRSA_CONF,         /* rsa key result */
72         CK_CPTRSA_REQ,          /* crypt session key */
73         CK_CPTRSA_CONF,         /* session key result */
74         CK_DECRSA_REQ,          /* decode session key */
75         CK_DECRSA_CONF,         /* session key result */
76         CK_ERROR_IND,           /* error of engine */
77         /* messages to/from "crypt engine" */
78         CC_ACTBF_REQ,           /* activate blowfish */
79         CC_ACTBF_CONF,          /* blowfish activated */
80         CC_ERROR_IND,           /* failed to activate session encryption */
81         CC_DACT_REQ,            /* deactivate session encryption */
82         /* messages to/from user interface */
83         CU_ACTK_REQ,            /* request encryption with key exchange */
84         CU_ACTK_CONF,           /* encryption now active */
85         CU_ACTS_REQ,            /* request shared key encryption */
86         CU_ACTS_CONF,           /* encryption now active */
87         CU_ERROR_IND,           /* encryption failed */
88         CU_INFO_REQ,            /* info reques */
89         CU_INFO_CONF,           /* info to the user*/
90         CU_INFO_IND,            /* info to the user*/
91         CU_DACT_REQ,            /* deactivate encryption */
92         CU_DACT_CONF,           /* encryption now inactive */
93         CU_DACT_IND,            /* encryption now inactive */
94         /* messages to/from message transponder */
95         CR_LISTEN_REQ,          /* start listening to messages */
96         CR_UNLISTEN_REQ,        /* stop listening to messages */
97         CR_MESSAGE_REQ,         /* send message */
98         CR_MESSAGE_IND,         /* receive message */
99         /* messages from ISDN */
100         CI_DISCONNECT_IND,      /* call is disconnected */
101         /* message timeout */
102         CT_TIMEOUT,             /* current state timed out */
103 };
104
105 #define CM_MSG_NAMES \
106 static const char *cm_msg_name[] = { \
107         "CP_IDENT", \
108         "CP_SLAVE", \
109         "CP_MASTER", \
110         "CP_LOOPED", \
111         "CP_PUBKEY", \
112         "CP_CSKEY", \
113         "CP_ABORT", \
114         "CK_GENRSA_REQ", \
115         "CK_GENRSA_CONF", \
116         "CK_CPTRSA_REQ", \
117         "CK_CPTRSA_CONF", \
118         "CK_DECRSA_REQ", \
119         "CK_DECRSA_CONF", \
120         "CK_ERROR_IND", \
121         "CC_ACTBF_REQ", \
122         "CC_ACTBF_CONF", \
123         "CC_ERROR_IND", \
124         "CC_DACT_REQ", \
125         "CU_ACTK_REQ", \
126         "CU_ACTK_CONF", \
127         "CU_ACTS_REQ", \
128         "CU_ACTS_CONF", \
129         "CU_ERROR_IND", \
130         "CU_INFO_REQ", \
131         "CU_INFO_CONF", \
132         "CU_INFO_IND", \
133         "CU_DACT_REQ", \
134         "CU_DACT_CONF", \
135         "CU_DACT_IND", \
136         "CR_LISTEN_REQ", \
137         "CR_UNLISTEN_REQ", \
138         "CR_MESSAGE_REQ", \
139         "CR_MESSAGE_IND", \
140         "CI_DISCONNECT_IND", \
141         "CT_TIMEOUT", \
142 }; \
143 int cm_msg_num = sizeof(cm_msg_name) / sizeof(char *);
144
145 /* peer2peer messages */
146 #define CMSG_IDENT              0x01
147 #define CMSG_MASTER             0x11
148 #define CMSG_SLAVE              0x12
149 #define CMSG_LOOPED             0x13
150 #define CMSG_PUBKEY             0x21
151 #define CMSG_CSKEY              0x22
152 #define CMSG_ABORT              0x81
153
154 /* peer2peer info elements */
155 #define CM_INFO_MESSAGE         0x01
156 #define CM_INFO_RANDOM          0x10
157 #define CM_INFO_BOGOMIPS        0x11
158 #define CM_INFO_PUBKEY          0x12
159 #define CM_INFO_PUBEXPONENT     0x13
160 #define CM_INFO_CSKEY           0x14
161
162
163 #define CM_ADDINF(a, b, c) \
164         cryptman_addinf(buf, sizeof(buf), a, b, c);
165 #define CM_SIZEOFINF(a) \
166         cryptman_sizeofinf(param, a);
167 #define CM_GETINF(a, b) \
168         cryptman_getinf(param, a, b);
169
170 void crc_init(void);
171 unsigned int crc32(unsigned char *data, int len);
172 int cryptman_encode_bch(unsigned char *data, int len, unsigned char *buf, int buf_len);
173 int crypt_handler(struct lcr_timer *timer, void *instance, int index);