1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** crypt header file **
10 \*****************************************************************************/
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 */
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 */
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 */
38 CM_ST_SWAIT, /* wait for share key establishment */
39 CM_ST_SACTIVE, /* shared key established */
43 static const char *cm_st_name[] = { \
58 int cm_st_num = sizeof(cm_st_name) / sizeof(char *);
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 */
105 #define CM_MSG_NAMES \
106 static const char *cm_msg_name[] = { \
140 "CI_DISCONNECT_IND", \
143 int cm_msg_num = sizeof(cm_msg_name) / sizeof(char *);
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
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
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);
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);