rewrote network addressess to base on boost::asio
[anytun.git] / src / authAlgo.h
blob308567300e1b539e1c5731b837b71a9ff5f5d028
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-2008 Othmar Gsenger, Erwin Nindl,
15 * Christian Pointner <satp@wirdorange.org>
17 * This file is part of Anytun.
19 * Anytun is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 3 as
21 * published by the Free Software Foundation.
23 * Anytun is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
32 #ifndef _AUTHALGO_H_
33 #define _AUTHALGO_H_
35 #include "datatypes.h"
36 #include "buffer.h"
37 #include "encryptedPacket.h"
39 #ifndef NOCRYPT
40 #include <gcrypt.h>
41 #endif
43 class AuthAlgo
45 public:
46 AuthAlgo() {};
47 virtual ~AuthAlgo() {};
49 /**
50 * set the key for the auth algo
51 * @param key key for hmac calculation
53 virtual void setKey(Buffer& key) = 0;
55 /**
56 * generate the mac
57 * @param packet the packet to be authenticated
59 virtual void generate(EncryptedPacket& packet) = 0;
61 /**
62 * check the mac
63 * @param packet the packet to be authenticated
65 virtual bool checkTag(EncryptedPacket& packet) = 0;
67 /**
68 * get the maximum size of the auth algo
70 virtual u_int32_t getMaxLength() = 0;
73 //****** NullAuthAlgo ******
75 class NullAuthAlgo : public AuthAlgo
77 public:
78 void setKey(Buffer& key) {};
79 void generate(EncryptedPacket& packet);
80 bool checkTag(EncryptedPacket& packet);
81 u_int32_t getMaxLength();
83 static const u_int32_t MAX_LENGTH_ = 0;
86 #ifndef NOCRYPT
87 //****** Sha1AuthAlgo ******
88 //* HMAC SHA1 Auth Tag Generator Class
90 class Sha1AuthAlgo : public AuthAlgo
92 public:
93 Sha1AuthAlgo();
94 ~Sha1AuthAlgo();
96 void setKey(Buffer& key);
97 void generate(EncryptedPacket& packet);
98 bool checkTag(EncryptedPacket& packet);
99 u_int32_t getMaxLength();
101 static const u_int32_t MAX_LENGTH_ = 20;
103 private:
104 gcry_md_hd_t ctx_;
106 #endif
108 #endif