Mixe for Privacy and Anonymity in the Internet
CAControlChannelDispatcher.hpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2000, The JAP-Team 
00003 All rights reserved.
00004 Redistribution and use in source and binary forms, with or without modification, 
00005 are permitted provided that the following conditions are met:
00006 
00007   - Redistributions of source code must retain the above copyright notice, 
00008     this list of conditions and the following disclaimer.
00009 
00010   - Redistributions in binary form must reproduce the above copyright notice, 
00011     this list of conditions and the following disclaimer in the documentation and/or 
00012     other materials provided with the distribution.
00013 
00014   - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 
00015     may be used to endorse or promote products derived from this software without specific 
00016     prior written permission. 
00017 
00018   
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 
00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00027 */
00028 
00029 #ifndef _CACONTROLCHANNELDISPATCHER_H_HEADER_
00030 #define _CACONTROLCHANNELDISPATCHER_H_HEADER_
00031 #include "CAQueue.hpp"
00032 class CAAbstractControlChannel;
00033 
00037 class CAControlChannelDispatcher
00038 {
00039   public:
00044     CAControlChannelDispatcher(CAQueue* pSendQueue,UINT8* keyRecv,UINT8* keySent)
00045       {
00046         m_pSendQueue=pSendQueue;
00047         m_pQueueEntry=new tQueueEntry;
00048         m_pMixPacket=&m_pQueueEntry->packet;
00049         m_arControlChannels=new CAAbstractControlChannel*[256];
00050         memset(m_arControlChannels,0,256*sizeof(CAAbstractControlChannel*));
00051         m_pcsSendMsg=new CAMutex();
00052         m_pcsRegisterChannel=new CAMutex();
00053         m_pcsEnc=new CAMutex();
00054         m_pcsDec=new CAMutex();
00055         m_nEncMsgCounter=0;
00056         m_pEncMsgIV=new UINT32[3];
00057         memset(m_pEncMsgIV,0,12);
00058         m_nDecMsgCounter=0;
00059         m_pDecMsgIV=new UINT8[12];
00060         memset(m_pDecMsgIV,0,12);
00061         if(keySent!=NULL)
00062         {
00063           m_pGCMCtxEnc=new gcm_ctx_64k;
00064           m_pGCMCtxDec=new gcm_ctx_64k;
00065           gcm_init_64k(m_pGCMCtxEnc,keySent,128);
00066           gcm_init_64k(m_pGCMCtxDec,keyRecv,128);
00067         }
00068         else
00069         {
00070           m_pGCMCtxEnc=NULL;
00071           m_pGCMCtxDec=NULL;
00072         }
00073       }
00074 
00075     ~CAControlChannelDispatcher()
00076       {
00077         delete m_pcsSendMsg;
00078         m_pcsSendMsg = NULL;
00079         delete m_pcsRegisterChannel;
00080         m_pcsRegisterChannel = NULL;
00081         delete[] m_arControlChannels;
00082         m_arControlChannels = NULL;
00083         delete m_pQueueEntry;
00084         m_pQueueEntry = NULL;
00085         if(m_pGCMCtxEnc!=NULL)
00086           delete m_pGCMCtxEnc;
00087         if(m_pGCMCtxDec!=NULL)
00088           delete m_pGCMCtxDec;
00089         delete []m_pEncMsgIV;
00090         delete m_pcsEnc;
00091         delete []m_pDecMsgIV;
00092         delete m_pcsDec;
00093       }
00094       
00095     void deleteAllControlChannels(void);
00096 
00098     SINT32 registerControlChannel(CAAbstractControlChannel* pControlChannel);
00099     SINT32 removeControlChannel(UINT32 id);
00100 
00101     bool proccessMixPacket(const MIXPACKET* pPacket);
00102     SINT32 sendMessages(UINT32 id,const UINT8* msg,UINT32 msglen);
00103   
00108     SINT32 encryptMessage(const UINT8* in,UINT32 inlen, UINT8* out,UINT32* outlen);
00113     SINT32 decryptMessage(const UINT8* in,UINT32 inlen, UINT8* out,UINT32* outlen);
00115     bool isKeySet()
00116       {
00117         return m_pGCMCtxEnc!=NULL;
00118       }
00119 
00120   private:
00121     CAQueue* m_pSendQueue;
00122     MIXPACKET* m_pMixPacket;
00123     CAAbstractControlChannel** m_arControlChannels;
00124     tQueueEntry* m_pQueueEntry;
00125     CAMutex* m_pcsSendMsg;
00126     CAMutex* m_pcsRegisterChannel;
00127     CAMutex* m_pcsEnc;
00128     CAMutex* m_pcsDec;
00129 
00130     gcm_ctx_64k* m_pGCMCtxEnc;
00131     gcm_ctx_64k* m_pGCMCtxDec;
00132     UINT32 m_nEncMsgCounter;
00133     UINT32* m_pEncMsgIV;
00134     UINT32 m_nDecMsgCounter;
00135     UINT8* m_pDecMsgIV;
00136 };
00137 #endif