cypher.h

Go to the documentation of this file.
00001 /*
00002  *  anytun
00003  *
00004  *  The secure anycast tunneling protocol (satp) defines a protocol used
00005  *  for communication between any combination of unicast and anycast
00006  *  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
00007  *  mode and allows tunneling of every ETHER TYPE protocol (e.g.
00008  *  ethernet, ip, arp ...). satp directly includes cryptography and
00009  *  message authentication based on the methodes used by SRTP.  It is
00010  *  intended to deliver a generic, scaleable and secure solution for
00011  *  tunneling and relaying of packets of any protocol.
00012  *
00013  *
00014  *  Copyright (C) 2007 anytun.org <satp@wirdorange.org>
00015  *
00016  *  This program is free software; you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License version 2
00018  *  as published by the Free Software Foundation.
00019  *
00020  *  This program is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  You should have received a copy of the GNU General Public License
00026  *  along with this program (see the file COPYING included with this
00027  *  distribution); if not, write to the Free Software Foundation, Inc.,
00028  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029  */
00030 
00031 #ifndef _CYPHER_H_
00032 #define _CYPHER_H_
00033 
00034 
00035 
00036 #include "datatypes.h"
00037 #include "buffer.h"
00038 
00039 extern "C" {
00040 #include <gcrypt.h>
00041 }
00042 
00043 
00044 #include <string>
00045 
00046 class Cypher
00047 {
00048 public:
00049   Cypher() {};
00050   virtual ~Cypher() {};
00051  
00052   void setKey(Buffer key) {};
00053   void setSalt(Buffer salt) {};
00054   void cypher(Buffer& buf, seq_nr_t seq_nr, sender_id_t sender_id);
00055   
00056 protected:
00057   void exor(Buffer& buf, const Buffer& bit_stream);
00058   virtual Buffer getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t sender_id) = 0;
00059 };
00060 
00061 class NullCypher : public Cypher
00062 {
00063 protected:
00064   Buffer getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t sender_id);
00065 };
00066 
00067 class AesIcmCypher : public Cypher
00068 {
00069 public:
00070   AesIcmCypher();
00071   ~AesIcmCypher();
00072   void setKey(Buffer key);
00073   void setSalt(Buffer salt);
00074 
00075   static const std::string MIN_GCRYPT_VERSION;
00076   static const u_int32_t GCRYPT_SEC_MEM;
00077 
00078 protected:
00079   Buffer getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t sender_id);
00080   gcry_cipher_hd_t cipher_;
00081   Buffer salt_;
00082 
00083 private:
00084   static bool gcrypt_initialized_;
00085 };
00086 
00087 const std::string AesIcmCypher::MIN_GCRYPT_VERSION = "1.2.3";
00088 bool AesIcmCypher::gcrypt_initialized_ = false;
00089 const u_int32_t AesIcmCypher::GCRYPT_SEC_MEM = 16384; // 16k secure memory
00090 
00091 #endif

Generated on Sun Oct 7 23:43:49 2007 for anytun by  doxygen 1.5.1