]> git.meshlink.io Git - meshlink/blob - src/sptps.h
Merge branch 'master' into 1.1
[meshlink] / 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 #ifndef __SPTPS_H__
21 #define __SPTPS_H__
22
23 #include "system.h"
24
25 #include "cipher.h"
26 #include "digest.h"
27 #include "ecdh.h"
28 #include "ecdsa.h"
29
30 #define SPTPS_VERSION 0
31
32 // Record types
33 #define SPTPS_HANDSHAKE 128   // Key exchange and authentication
34 #define SPTPS_ALERT 129       // Warning or error messages
35 #define SPTPS_CLOSE 130       // Application closed the connection
36
37 // Key exchange states
38 #define SPTPS_KEX 0           // Waiting for the first Key EXchange record
39 #define SPTPS_SECONDARY_KEX 1 // Ready to receive a secondary Key EXchange record
40 #define SPTPS_SIG 2           // Waiting for a SIGnature record
41 #define SPTPS_ACK 3           // Waiting for an ACKnowledgement record
42
43 typedef bool (*send_data_t)(void *handle, uint8_t type, const char *data, size_t len);
44 typedef bool (*receive_record_t)(void *handle, uint8_t type, const char *data, uint16_t len);
45
46 typedef struct sptps {
47         bool initiator;
48         bool datagram;
49         int state;
50
51         char *inbuf;
52         size_t buflen;
53         uint16_t reclen;
54
55         bool instate;
56         cipher_t incipher;
57         digest_t indigest;
58         uint32_t inseqno;
59         unsigned int replaywin;
60         unsigned int farfuture;
61         char *late;
62
63         bool outstate;
64         cipher_t outcipher;
65         digest_t outdigest;
66         uint32_t outseqno;
67
68         ecdsa_t mykey;
69         ecdsa_t hiskey;
70         ecdh_t ecdh;
71
72         char *mykex;
73         char *hiskex;
74         char *key;
75         char *label;
76         size_t labellen;
77
78         void *handle;
79         send_data_t send_data;
80         receive_record_t receive_record;
81 } sptps_t;
82
83 extern unsigned int sptps_replaywin;
84 extern bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record);
85 extern bool sptps_stop(sptps_t *s);
86 extern bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len);
87 extern bool sptps_receive_data(sptps_t *s, const char *data, size_t len);
88 extern bool sptps_force_kex(sptps_t *s);
89 extern bool sptps_verify_datagram(sptps_t *s, const char *data, size_t len);
90
91 #endif