added a workaround for strerror_r problem
[anytun.git] / src / authAlgo.h
blob809880df6a1a2b17ba2269062b80829c1047d6de
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 #ifndef USE_SSL_CRYPTO
41 #include <gcrypt.h>
42 #else
43 #include <openssl/hmac.h>
44 #endif
45 #endif
46 #include "keyDerivation.h"
48 class AuthAlgo
50 public:
51 AuthAlgo() : dir_(KD_INBOUND) {};
52 AuthAlgo(kd_dir_t d) : dir_(d) {};
53 virtual ~AuthAlgo() {};
55 /**
56 * generate the mac
57 * @param packet the packet to be authenticated
59 virtual void generate(KeyDerivation& kd, EncryptedPacket& packet) = 0;
61 /**
62 * check the mac
63 * @param packet the packet to be authenticated
65 virtual bool checkTag(KeyDerivation& kd, EncryptedPacket& packet) = 0;
67 protected:
68 kd_dir_t dir_;
71 //****** NullAuthAlgo ******
73 class NullAuthAlgo : public AuthAlgo
75 public:
76 void generate(KeyDerivation& kd, EncryptedPacket& packet);
77 bool checkTag(KeyDerivation& kd, EncryptedPacket& packet);
80 #ifndef NOCRYPT
81 //****** Sha1AuthAlgo ******
82 //* HMAC SHA1 Auth Tag Generator Class
84 class Sha1AuthAlgo : public AuthAlgo
86 public:
87 Sha1AuthAlgo(kd_dir_t d);
88 ~Sha1AuthAlgo();
90 void generate(KeyDerivation& kd, EncryptedPacket& packet);
91 bool checkTag(KeyDerivation& kd, EncryptedPacket& packet);
93 static const u_int32_t DIGEST_LENGTH = 20;
95 private:
96 #ifndef USE_SSL_CRYPTO
97 gcry_md_hd_t handle_;
98 #else
99 HMAC_CTX ctx_;
100 #endif
102 Buffer key_;
104 #endif
106 #endif