Mixe for Privacy and Anonymity in the Internet
CASymCipherCTR.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef __CASYMCIPHERCTR__
29 #define __CASYMCIPHERCTR__
30 
31 
32 #include "CALockAble.hpp"
33 #include "CAMutex.hpp"
34 #include "CASymChannelCipher.hpp"
42 //#define AES_NI
44 
45  {
46  public:
48  {
49  m_bKeySet=false;
50  m_ctxAES1=EVP_CIPHER_CTX_new();
51  m_ctxAES2=EVP_CIPHER_CTX_new();
52 
53  m_iv1=new UINT8[16];
54  m_iv2=new UINT8[16];
55 
56  m_pcsEnc = new CAMutex();
57  m_pcsDec = new CAMutex();
58  }
59 
61  {
62 #ifndef ONLY_LOCAL_PROXY
64 #endif
65  delete[] m_iv1;
66  m_iv1 = NULL;
67  delete[] m_iv2;
68  m_iv2 = NULL;
69 
70  delete m_pcsEnc;
71  m_pcsEnc = NULL;
72  delete m_pcsDec;
73  m_pcsDec = NULL;
74  }
75  bool isKeyValid()
76  {
77  return m_bKeySet;
78  }
79 
81  SINT32 setKey(const UINT8* key);
82 
85  SINT32 setKeys(const UINT8* key,UINT32 keysize);
86 
91  SINT32 setIVs(const UINT8* p_iv)
92  {
93  memcpy(m_iv1,p_iv,16);
94  memcpy(m_iv2,p_iv,16);
95  EVP_DecryptInit_ex(m_ctxAES1, EVP_aes_128_ctr(), NULL, key1, m_iv1);
96  EVP_EncryptInit_ex(m_ctxAES2, EVP_aes_128_ctr(), NULL, key2, m_iv2);
97  return E_SUCCESS;
98  }
99 
104  SINT32 setIV2(const UINT8* p_iv)
105  {
106  memcpy(m_iv2,p_iv,16);
107  EVP_EncryptInit_ex(m_ctxAES2, EVP_aes_128_ctr(), NULL, key2, m_iv2);
108  return E_SUCCESS;
109  }
110 
111  SINT32 crypt1(const UINT8* in,UINT8* out,UINT32 len);
112  SINT32 crypt2(const UINT8* in,UINT8* out,UINT32 len);
113 
114  private:
117 
118  protected:
119 
120 
121  EVP_CIPHER_CTX *m_ctxAES1;
122  EVP_CIPHER_CTX *m_ctxAES2;
123  UINT8 key1[16];
124  UINT8 key2[16];
125 
126 
129  bool m_bKeySet;
130  };
131 
132 #endif
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 waitForDestroy()
If called checks if the reference counter equals zero.
Definition: CALockAble.hpp:82
This class could be used for encryption/decryption of data (streams) with AES using 128bit CTR mode.
SINT32 setIVs(const UINT8 *p_iv)
Sets iv1 and iv2 to p_iv.
SINT32 crypt2(const UINT8 *in, UINT8 *out, UINT32 len)
Decryptes in to out using iv2 and key2.
SINT32 setKeys(const UINT8 *key, UINT32 keysize)
Sets the keys for crypt1() and crypt2() either to the same key (if keysize==KEY_SIZE) or to different...
SINT32 crypt1(const UINT8 *in, UINT8 *out, UINT32 len)
Encryptes/Decrpytes in to out using iv1 and key1.
EVP_CIPHER_CTX * m_ctxAES2
SINT32 setIV2(const UINT8 *p_iv)
Sets iv2 to p_iv.
SINT32 setKey(const UINT8 *key)
Sets the keys for crypt1() and crypt2() to the same key.
EVP_CIPHER_CTX * m_ctxAES1
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
UINT16 len
Definition: typedefs.hpp:0