TrinityCore
Loading...
Searching...
No Matches
ARC4.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include "
ARC4.h
"
19
#include "
Errors.h
"
20
21
Trinity::Crypto::ARC4::ARC4
() : _ctx(EVP_CIPHER_CTX_new())
22
{
23
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
24
_cipher = EVP_CIPHER_fetch(
nullptr
,
"RC4"
,
nullptr
);
25
#else
26
EVP_CIPHER
const
* _cipher = EVP_rc4();
27
#endif
28
29
EVP_CIPHER_CTX_init(
_ctx
);
30
int
result = EVP_EncryptInit_ex(
_ctx
, _cipher,
nullptr
,
nullptr
,
nullptr
);
31
ASSERT
(result == 1);
32
}
33
34
Trinity::Crypto::ARC4::~ARC4
()
35
{
36
EVP_CIPHER_CTX_free(_ctx);
37
38
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
39
EVP_CIPHER_free(_cipher);
40
#endif
41
}
42
43
void
Trinity::Crypto::ARC4::Init
(
uint8
const
* seed,
size_t
len)
44
{
45
int
result1 = EVP_CIPHER_CTX_set_key_length(_ctx, len);
46
ASSERT
(result1 == 1);
47
int
result2 = EVP_EncryptInit_ex(_ctx,
nullptr
,
nullptr
, seed,
nullptr
);
48
ASSERT
(result2 == 1);
49
}
50
51
void
Trinity::Crypto::ARC4::UpdateData
(
uint8
* data,
size_t
len)
52
{
53
int
outlen = 0;
54
int
result1 = EVP_EncryptUpdate(_ctx, data, &outlen, data, len);
55
ASSERT
(result1 == 1);
56
int
result2 = EVP_EncryptFinal_ex(_ctx, data, &outlen);
57
ASSERT
(result2 == 1);
58
}
ARC4.h
uint8
uint8_t uint8
Definition
Define.h:135
Errors.h
ASSERT
#define ASSERT
Definition
Errors.h:68
Trinity::Crypto::ARC4::~ARC4
~ARC4()
Definition
ARC4.cpp:34
Trinity::Crypto::ARC4::ARC4
ARC4()
Definition
ARC4.cpp:21
Trinity::Crypto::ARC4::UpdateData
void UpdateData(uint8 *data, size_t len)
Definition
ARC4.cpp:51
Trinity::Crypto::ARC4::_ctx
EVP_CIPHER_CTX * _ctx
Definition
ARC4.h:44
Trinity::Crypto::ARC4::Init
void Init(uint8 const *seed, size_t len)
Definition
ARC4.cpp:43
common
Cryptography
ARC4.cpp
Generated on Sun May 10 2026 02:30:12 for TrinityCore by
1.9.8