Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
58 строк · 1.8 Кб
1
/*
2
* This file is part of the Pandaria 5.4.8 Project. See THANKS 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
}
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.