Mixe for Privacy and Anonymity in the Internet
CASymCipherOFB.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 __CASYMCIPHEROFB__
29 #define __CASYMCIPHEROFB__
30 
31 #define KEY_SIZE 16
32 
33 #include "CALockAble.hpp"
34 #include "CAMutex.hpp"
35 #include "CASymChannelCipher.hpp"
44 
45  {
46  public:
48  {
49  m_bKeySet=false;
50 #ifdef INTEL_IPP_CRYPTO
51  int size=0;
52  ippsRijndael128GetSize(&size);
53  m_keyAES1=(IppsRijndael128Spec*)new UINT8[size];
54  m_keyAES2=(IppsRijndael128Spec*)new UINT8[size];
55 #else
56  m_keyAES1=new AES_KEY;
57  m_keyAES2=new AES_KEY;
58 #endif
59 
60  m_iv1=new UINT8[16];
61  m_iv2=new UINT8[16];
62 
63  m_pcsEnc = new CAMutex();
64  m_pcsDec = new CAMutex();
65  }
66 
68  {
69 #ifndef ONLY_LOCAL_PROXY
71 #endif
72 #ifdef INTEL_IPP_CRYPTO
73  delete[] (UINT8*)m_keyAES1;
74  delete[] (UINT8*)m_keyAES2;
75 #else
76  delete m_keyAES1;
77  delete m_keyAES2;
78 #endif
79  m_keyAES1 = NULL;
80  m_keyAES2 = NULL;
81  delete[] m_iv1;
82  m_iv1 = NULL;
83  delete[] m_iv2;
84  m_iv2 = NULL;
85 
86  delete m_pcsEnc;
87  m_pcsEnc = NULL;
88  delete m_pcsDec;
89  m_pcsDec = NULL;
90  }
91  bool isKeyValid()
92  {
93  return m_bKeySet;
94  }
95 
97  SINT32 setKey(const UINT8* key);
98 
101  SINT32 setKeys(const UINT8* key,UINT32 keysize);
102 
103  SINT32 setKey(const UINT8* key,bool bEncrypt);
104 
109  SINT32 setIVs(const UINT8* p_iv)
110  {
111  memcpy(m_iv1,p_iv,16);
112  memcpy(m_iv2,p_iv,16);
113  return E_SUCCESS;
114  }
115 
120  SINT32 setIV2(const UINT8* p_iv)
121  {
122  memcpy(m_iv2,p_iv,16);
123  return E_SUCCESS;
124  }
125 
126  SINT32 crypt1(const UINT8* in,UINT8* out,UINT32 len);
127  SINT32 crypt2(const UINT8* in,UINT8* out,UINT32 len);
128 
129  static SINT32 testSpeed();
130 
131  private:
136 
137  protected:
138 
139 #ifdef INTEL_IPP_CRYPTO
140  IppsRijndael128Spec* m_keyAES1;
141  IppsRijndael128Spec* m_keyAES2;
142 #else
143  AES_KEY* m_keyAES1;
144  AES_KEY* m_keyAES2;
145 #endif
146 
149  bool m_bKeySet;
150  };
151 
152 #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 OFB mode.
SINT32 setIVs(const UINT8 *p_iv)
Sets iv1 and iv2 to p_iv.
static SINT32 testSpeed()
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 setKey(const UINT8 *key)
Sets the keys for crypt1() and crypt2() to the same key.
SINT32 setIV2(const UINT8 *p_iv)
Sets iv2 to p_iv.
SINT32 crypt1(const UINT8 *in, UINT8 *out, UINT32 len)
Encryptes/Decrpytes in to out using iv1 and key1.
SINT32 crypt2(const UINT8 *in, UINT8 *out, UINT32 len)
Decryptes in to out using iv2 and key2.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
UINT16 len
Definition: typedefs.hpp:0