Update SPTPS protocol.
[tinc] / src / sptps.h
1 /*
2     sptps.h -- Simple Peer-to-Peer Security
3     Copyright (C) 2011 Guus Sliepen <guus@tinc-vpn.org>,
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "system.h"
21
22 #include "cipher.h"
23 #include "digest.h"
24 #include "ecdh.h"
25 #include "ecdsa.h"
26
27 #define SPTPS_KEX 0
28 #define SPTPS_SECONDARY_KEX 1 // Waiting for peer's ECDHE pubkey
29 #define SPTPS_SIG 2 // Waiting for peer's ECDHE pubkey
30 #define SPTPS_ACK 3 // Waiting for peer's acknowledgement of pubkey reception
31
32 #define SPTPS_HANDSHAKE 128
33 #define SPTPS_VERSION 128
34
35 typedef bool (*send_data_t)(void *handle, const char *data, size_t len);
36 typedef bool (*receive_record_t)(void *handle, uint8_t type, const char *data, uint16_t len);
37
38 typedef struct sptps {
39         bool initiator;
40         int state;
41
42         char *inbuf;
43         size_t buflen;
44
45         bool instate;
46         cipher_t incipher;
47         digest_t indigest;
48         uint32_t inseqno;
49
50         bool outstate;
51         cipher_t outcipher;
52         digest_t outdigest;
53         uint32_t outseqno;
54
55         ecdsa_t mykey;
56         ecdsa_t hiskey;
57         ecdh_t ecdh;
58
59         char *mykex;
60         char *hiskex;
61         char *key;
62         char *label;
63         size_t labellen;
64
65         void *handle;
66         send_data_t send_data;
67         receive_record_t receive_record;
68 } sptps_t;
69
70 extern bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record);
71 extern bool stop_sptps(sptps_t *s);
72 extern bool send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len);
73 extern bool receive_data(sptps_t *s, const char *data, size_t len);
74 extern bool force_kex(sptps_t *s);