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
21Trinity::Crypto::ARC4::ARC4() : _ctx(EVP_CIPHER_CTX_new())
22{
23 _cipher = EVP_CIPHER_fetch(nullptr, "RC4", nullptr);
24
25 EVP_CIPHER_CTX_init(_ctx);
26 int result = EVP_EncryptInit_ex(_ctx, _cipher, nullptr, nullptr, nullptr);
27 ASSERT(result == 1);
28}
29
31{
32 EVP_CIPHER_CTX_free(_ctx);
33 EVP_CIPHER_free(_cipher);
34}
35
36void Trinity::Crypto::ARC4::Init(uint8 const* seed, size_t len)
37{
38 int result1 = EVP_CIPHER_CTX_set_key_length(_ctx, len);
39 ASSERT(result1 == 1);
40 int result2 = EVP_EncryptInit_ex(_ctx, nullptr, nullptr, seed, nullptr);
41 ASSERT(result2 == 1);
42}
43
45{
46 int outlen = 0;
47 int result1 = EVP_EncryptUpdate(_ctx, data, &outlen, data, len);
48 ASSERT(result1 == 1);
49 int result2 = EVP_EncryptFinal_ex(_ctx, data, &outlen);
50 ASSERT(result2 == 1);
51}
uint8_t uint8
Definition Define.h:156
#define ASSERT
Definition Errors.h:80
void UpdateData(uint8 *data, size_t len)
Definition ARC4.cpp:44
EVP_CIPHER * _cipher
Definition ARC4.h:41
EVP_CIPHER_CTX * _ctx
Definition ARC4.h:42
void Init(uint8 const *seed, size_t len)
Definition ARC4.cpp:36