Mixe for Privacy and Anonymity in the Internet
CASymCipherCTR.cpp
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 #include "StdAfx.h"
29 #include "CASymCipherCTR.hpp"
30 #include "CAMsg.hpp"
31 //AES
32 
33 
40 {
41  memset(m_iv1,0,16);
42  memset(m_iv2,0,16);
43 
44  EVP_DecryptInit_ex(m_ctxAES1,EVP_aes_128_ctr(), NULL, key, m_iv1);
45  EVP_EncryptInit_ex(m_ctxAES2, EVP_aes_128_ctr(), NULL, key, m_iv2);
46  memcpy(key1, key, 16);
47  memcpy(key2, key, 16);
48 
49  m_bKeySet=true;
50  return E_SUCCESS;
51 }
52 
54 {
55  if(keysize==KEY_SIZE)
56  {
57  return setKey(key);
58  }
59  else if(keysize==2*KEY_SIZE)
60  {
61  memset(m_iv1,0,16);
62  memset(m_iv2,0,16);
63  EVP_DecryptInit_ex(m_ctxAES1,EVP_aes_128_ctr(), NULL, key, m_iv1);
64  EVP_EncryptInit_ex(m_ctxAES2, EVP_aes_128_ctr(), NULL, key+KEY_SIZE, m_iv2);
65  memcpy(key1, key, 16);
66  memcpy(key2, key + KEY_SIZE, 16);
67  m_bKeySet=true;
68  return E_SUCCESS;
69  }
70  return E_UNKNOWN;
71 }
72 
86  {
87  UINT32 i=2000;
88  UINT8 tmpBuff[2000];
89  /*int ret=*/
90  EVP_DecryptUpdate(m_ctxAES1, tmpBuff, (int*)&i, in, len);
91  /*if (ret != 1)
92  {
93  CAMsg::printMsg(LOG_ERR, "Error in CASymCipher::crypt1()\n ");
94  return E_UNKNOWN;
95  }*/
96  memcpy(out, tmpBuff, len);
97  return E_SUCCESS;
98  }
99 
108 {
109  UINT32 i=2000;
110  UINT8 tmpBuff[2000];
111 
112  EVP_EncryptUpdate(m_ctxAES2, tmpBuff, (int*)&i, in, len);
113  memcpy(out, tmpBuff, len);
114  return E_SUCCESS;
115 }
116 
117 
#define KEY_SIZE
Definition: CASymCipher.hpp:31
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
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 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
#define E_UNKNOWN
Definition: errorcodes.hpp:3
UINT16 len
Definition: typedefs.hpp:0