Mixe for Privacy and Anonymity in the Internet
CASymCipher.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 __CASYMCIPHER__
29 #define __CASYMCIPHER__
30 
31 #define KEY_SIZE 16
32 
33 #include "CALockAble.hpp"
34 #include "CAMutex.hpp"
39 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
40  :public CALockAble
41 #endif
42  {
43  public:
45  {
46  m_bKeySet=false;
47 #ifdef INTEL_IPP_CRYPTO
48  int size=0;
49  ippsRijndael128GetSize(&size);
50  m_keyAES1=(IppsRijndael128Spec*)new UINT8[size];
51 #else
52  m_keyAES1=new AES_KEY;
53 #endif
54 
55  m_iv1=new UINT8[16];
56 
57 
58 
59  m_pcsEnc = new CAMutex();
60  m_pcsDec = new CAMutex();
61  }
62 
64  {
65 #ifndef ONLY_LOCAL_PROXY
67 #endif
68 #ifdef INTEL_IPP_CRYPTO
69  delete[] (UINT8*)m_keyAES1;
70 #else
71  delete m_keyAES1;
72 #endif
73  m_keyAES1 = NULL;
74  delete[] m_iv1;
75  m_iv1 = NULL;
76 
77 
78 
79 
80  delete m_pcsEnc;
81  m_pcsEnc = NULL;
82  delete m_pcsDec;
83  m_pcsDec = NULL;
84  }
85  bool isKeyValid()
86  {
87  return m_bKeySet;
88  }
89 
91  SINT32 setKey(const UINT8* key);
92 
95  //SINT32 setKeys(const UINT8* key,UINT32 keysize);
96 
97  SINT32 setKey(const UINT8* key,bool bEncrypt);
98 
103  SINT32 setIV(const UINT8* p_iv)
104  {
105  memcpy(m_iv1,p_iv,16);
106  return E_SUCCESS;
107  }
108 
109 
110  SINT32 decryptCBCwithPKCS7(const UINT8* in,UINT8* out,UINT32* len);
111  SINT32 encryptCBCwithPKCS7(const UINT8* in,UINT32 inlen,UINT8* out,UINT32* len);
112 
113 
114  private:
117 
118  protected:
119 
120 #ifdef INTEL_IPP_CRYPTO
121  IppsRijndael128Spec* m_keyAES1;
122 #else
123  AES_KEY* m_keyAES1;
124 #endif
125 
126 
127 
129  bool m_bKeySet;
130  };
131 
132 #endif
#define INCLUDE_MIDDLE_MIX
Definition: StdAfx.h:276
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
From this class other classes could be derived, which need some kind from "locking" in memory.
Definition: CALockAble.hpp:41
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 CBC mode.
Definition: CASymCipher.hpp:42
UINT8 * m_iv1
bool isKeyValid()
Definition: CASymCipher.hpp:85
CAMutex * m_pcsDec
AES_KEY * m_keyAES1
SINT32 encryptCBCwithPKCS7(const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *len)
En-/Decryptes in to out using IV1 and key1.
CAMutex * m_pcsEnc
SINT32 setIV(const UINT8 *p_iv)
Sets iv to p_iv.
SINT32 setKey(const UINT8 *key)
Sets the key for encryption.
Definition: CASymCipher.cpp:52
SINT32 decryptCBCwithPKCS7(const UINT8 *in, UINT8 *out, UINT32 *len)
En-/Decryptes in to out using iv1 and key1.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
UINT16 len
Definition: typedefs.hpp:0