Mixe for Privacy and Anonymity in the Internet
CASymCipherGCM.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 "
CASymCipherGCM.hpp
"
30
#include "
CAMsg.hpp
"
31
//AES GCM
32
33
/*
34
void CASymCipherGCM::setGCMKeys(UINT8* keyRecv, UINT8* keySend)
35
{
36
37
#ifndef USE_OPENSSL_GCM
38
m_pGCMCtxEnc = new gcm_ctx_64k;
39
m_pGCMCtxDec = new gcm_ctx_64k;
40
#else
41
//Note the have to provide *some* key (OpenSSL API enforced --> so the use the variables we have anyway..)
42
// The Key will be overriden by a call to setKeyGCM in any case!
43
AES_set_encrypt_key(m_iv1,128,m_keyAES1);
44
m_pGCMCtxEnc = CRYPTO_gcm128_new(m_keyAES1,(block128_f)AES_encrypt);
45
m_pGCMCtxDec = CRYPTO_gcm128_new(m_keyAES1,(block128_f)AES_encrypt);
46
#endif
47
48
49
50
#ifndef USE_OPENSSL_GCM
51
if(m_pGCMCtxDec!=NULL)
52
delete m_pGCMCtxDec;
53
if(m_pGCMCtxEnc!=NULL)
54
delete m_pGCMCtxEnc;
55
56
m_pGCMCtxEnc = new gcm_ctx_64k;
57
m_pGCMCtxDec = new gcm_ctx_64k;
58
gcm_init_64k(m_pGCMCtxEnc, keySend, 128);
59
gcm_init_64k(m_pGCMCtxDec, keyRecv, 128);
60
#else
61
AES_set_encrypt_key(keyRecv,128,m_keyAES1);
62
AES_set_encrypt_key(keySend,128,m_keyAES2);
63
CRYPTO_gcm128_release(m_pGCMCtxEnc);
64
CRYPTO_gcm128_release(m_pGCMCtxDec);
65
m_pGCMCtxEnc=CRYPTO_gcm128_new(m_keyAES2,(block128_f)AES_encrypt);
66
m_pGCMCtxDec=CRYPTO_gcm128_new(m_keyAES1,(block128_f)AES_encrypt);
67
#endif
68
//reset IV
69
m_nEncMsgCounter = 0;
70
memset(m_pEncMsgIV, 0, 12);
71
m_nDecMsgCounter = 0;
72
memset(m_pDecMsgIV, 0, 12);
73
}
74
*/
75
/*
76
SINT32 CASymCipherGCM::encryptMessage(const UINT8* const in, UINT32 inlen, UINT8* out)
77
{
78
#ifdef NO_ENCRYPTION
79
memmove(out, in, inlen);
80
return E_SUCCESS;
81
#endif
82
83
//m_pcsEnc->lock();
84
m_pEncMsgIV[2] = htonl(m_nEncMsgCounter);
85
m_nEncMsgCounter++;
86
#ifndef USE_OPENSSL_GCM
87
gcm_encrypt_64k(m_pGCMCtxEnc, m_pEncMsgIV, in, inlen, out, (UINT32*)(out + inlen));
88
#else
89
CRYPTO_gcm128_setiv(m_pGCMCtxEnc,(UINT8*)m_pEncMsgIV,12);
90
CRYPTO_gcm128_encrypt(m_pGCMCtxEnc,in,out,inlen);
91
CRYPTO_gcm128_tag(m_pGCMCtxEnc,out+inlen,16);
92
#endif
93
//m_pcsEnc->unlock();
94
return E_SUCCESS;
95
}
96
*/
97
/*
98
SINT32 CASymCipherGCM::decryptMessage(const UINT8* in, UINT32 inlen, UINT8* out, bool integrityCheck)
99
{
100
#ifdef NO_ENCRYPTION
101
memmove(out, in, inlen);
102
return E_SUCCESS;
103
#endif
104
105
SINT32 ret = E_UNKNOWN;
106
//m_pcsDec->lock();
107
m_pDecMsgIV[2] = htonl(m_nDecMsgCounter);
108
if (integrityCheck)
109
{
110
m_nDecMsgCounter++;
111
#ifndef USE_OPENSSL_GCM
112
ret = ::gcm_decrypt_64k(m_pGCMCtxDec, m_pDecMsgIV, in, inlen - 16, in + inlen - 16, out);
113
#else
114
CRYPTO_gcm128_setiv(m_pGCMCtxDec,(UINT8*)m_pDecMsgIV,12);
115
CRYPTO_gcm128_decrypt(m_pGCMCtxDec,in,out,inlen-16);
116
ret=CRYPTO_gcm128_finish(m_pGCMCtxDec,in + inlen - 16,16);
117
#endif
118
}
119
else
120
{
121
#ifndef USE_OPENSSL_GCM
122
ret = ::gcm_decrypt_64k(m_pGCMCtxDec, m_pDecMsgIV, in, inlen, out);
123
#else
124
CRYPTO_gcm128_setiv(m_pGCMCtxDec,(UINT8*)m_pDecMsgIV,12);
125
ret=CRYPTO_gcm128_decrypt(m_pGCMCtxDec,in,out,inlen);
126
#endif
127
}
128
//m_pcsDec->unlock();
129
#ifndef USE_OPENSSL_GCM
130
if(ret==0)
131
#else
132
if(ret!=0)
133
#endif
134
return E_UNKNOWN;
135
return E_SUCCESS;
136
}
137
*/
CAMsg.hpp
CASymCipherGCM.hpp
StdAfx.h
Generated on Sat Jul 22 2023 00:20:12 for Mixe for Privacy and Anonymity in the Internet by
1.9.1