Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcclient / protocol.h
1 /*
2
3   protocol.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2004 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef PROTOCOL_H
21 #define PROTOCOL_H
22
23 /* SILC client protocol types */
24 #define SILC_PROTOCOL_CLIENT_NONE               0
25 #define SILC_PROTOCOL_CLIENT_CONNECTION_AUTH    1
26 #define SILC_PROTOCOL_CLIENT_KEY_EXCHANGE       2
27 #define SILC_PROTOCOL_CLIENT_REKEY              3
28 /* #define SILC_PROTOCOL_CLIENT_MAX             255 */
29
30 /* Internal context for key exchange protocol */
31 typedef struct {
32   void *client;
33   SilcSocketConnection sock;
34   SilcRng rng;
35   int responder;
36
37   void *dest_id;                    /* Destination ID from packet */
38   SilcIdType dest_id_type;          /* Destination ID type */
39
40   SilcTask timeout_task;
41   SilcPacketContext *packet;
42
43   SilcSKESendPacketCb send_packet;  /* SKE's packet sending callback */
44   SilcSKEVerifyCb verify;           /* SKE's key verify callback */
45   SilcSKE ske;                      /* The SKE object */
46   SilcSKEKeyMaterial *keymat;       /* The negotiated key material */
47   void *context;                    /* Internal context */
48 } SilcClientKEInternalContext;
49
50 /* Internal context for connection authentication protocol */
51 typedef struct {
52   void *client;
53   SilcSocketConnection sock;
54   SilcClientConnectionStatus status;
55
56   /* SKE object from Key Exchange protocol. */
57   SilcSKE ske;
58
59   /* Auth method that must be used. This is resolved before this
60      connection authentication protocol is started. */
61   SilcProtocolAuthMeth auth_meth;
62
63   /* Destinations ID from KE protocol context */
64   void *dest_id;
65   SilcIdType dest_id_type;
66
67   /* Authentication data if we alreay know it. This is filled before
68      starting the protocol if we know the authentication data. Otherwise
69      these are and remain NULL. */
70   unsigned char *auth_data;
71   SilcUInt32 auth_data_len;
72
73   SilcTask timeout_task;
74 } SilcClientConnAuthInternalContext;
75
76 /* Internal context for the rekey protocol */
77 typedef struct {
78   void *client;
79   void *context;
80   SilcSocketConnection sock;
81   bool responder;                   /* TRUE if we are receiving party */
82   bool pfs;                         /* TRUE if PFS is to be used */
83   SilcSKE ske;                      /* Defined if PFS is used */
84   SilcPacketContext *packet;
85 } SilcClientRekeyInternalContext;
86
87 /* Prototypes */
88 void silc_client_protocols_register(void);
89 void silc_client_protocols_unregister(void);
90 void silc_client_protocol_ke_send_packet(SilcSKE ske,
91                                          SilcBuffer packet,
92                                          SilcPacketType type,
93                                          void *context);
94 void silc_client_protocol_ke_verify_key(SilcSKE ske,
95                                         unsigned char *pk_data,
96                                         SilcUInt32 pk_len,
97                                         SilcSKEPKType pk_type,
98                                         void *context,
99                                         SilcSKEVerifyCbCompletion completion,
100                                         void *completion_context);
101 void silc_client_protocol_ke_set_keys(SilcSKE ske,
102                                       SilcSocketConnection sock,
103                                       SilcSKEKeyMaterial *keymat,
104                                       SilcCipher cipher,
105                                       SilcPKCS pkcs,
106                                       SilcHash hash,
107                                       SilcHmac hmac,
108                                       SilcSKEDiffieHellmanGroup group,
109                                       bool is_responder);
110
111 #endif