finallly working, payload type needs further checks
[anytun.git] / encryptedPacket.h
blob83b831e2fa5acfce4db9353fc91ced153bef3095
1 /*
2 * anytun
4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING included with this
27 * distribution); if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef _ENCRYPTED_PACKET_H_
32 #define _ENCRYPTED_PACKET_H_
34 #include "datatypes.h"
35 #include "buffer.h"
36 #include "authTag.h"
37 class Cypher;
38 class EncryptedPacket : public Buffer
40 public:
42 /**
43 * Packet constructor
44 * @param max_payload_length maximum length of encrypted payload
46 EncryptedPacket(u_int32_t max_payload_length);
48 /**
49 * Packet destructor
51 ~EncryptedPacket();
53 /**
54 * Get the sequence number
55 * @return seqence number
57 seq_nr_t getSeqNr() const;
59 /**
60 * Set the seqence number
61 * @param seq_nr sequence number
63 void setSeqNr(seq_nr_t seq_nr);
65 /**
66 * Get the sender id
67 * @return sender id
69 sender_id_t getSenderId() const;
71 /**
72 * Set the sender id
73 * @param sender_id sender id
75 void setSenderId(sender_id_t sender_id);
77 /**
78 * Get the mulitplex id
79 * @return multiplex id
81 mux_t getMux() const;
83 /**
84 * Set the multiplex id
85 * @param mux multiplex id
87 void setMux(mux_t mux);
89 /**
90 * Set the header of a packet
91 * @param seq_nr sequence number
92 * @param sender_id sender id
93 * @param mux multiplex id
95 void setHeader(seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux);
97 /**
98 * Get the maximum payload size
99 * @return maximum payload size
101 u_int32_t getMaxLength() const;
104 * Set the real length of the payload
105 * @param length the real length of the payload, has to be smaller than the maximum payload size!
107 void setLength(u_int32_t length);
109 bool hasAuthTag() const;
110 void withAuthTag(bool b);
111 AuthTag getAuthTag() const;
112 void setAuthTag(AuthTag& tag);
114 void setPayloadLength(u_int8_t payload_length);
117 // bool hasHeader() const;
118 // Packet& withHeader(bool b);
119 // Packet& addHeader(seq_nr_t seq_nr, sender_id_t sender_id);
120 // Packet& withAuthTag(bool b);
121 // AuthTag getAuthTag() const;
122 // Packet& addAuthTag(AuthTag auth_tag);
124 private:
125 EncryptedPacket();
126 EncryptedPacket(const EncryptedPacket &src);
127 struct HeaderStruct
129 seq_nr_t seq_nr;
130 sender_id_t sender_id;
131 mux_t mux;
132 }__attribute__((__packed__));
134 struct HeaderStruct* header_;
135 AuthTag* auth_tag_;
136 u_int32_t max_length_;
138 static const u_int32_t AUTHTAG_SIZE = 10; // 10byte
139 protected:
140 friend class Cypher;
141 u_int8_t * payload_;
142 u_int32_t payload_length_;
145 #endif