File indexing completed on 2025-01-05 04:37:19
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "rc4encryptor.h" 0007 #include <util/functions.h> 0008 #include <util/log.h> 0009 0010 using namespace bt; 0011 0012 namespace mse 0013 { 0014 static Uint8 rc4_enc_buffer[bt::MAX_MSGLEN]; 0015 0016 RC4Encryptor::RC4Encryptor(const bt::SHA1Hash &dk, const bt::SHA1Hash &ek) 0017 { 0018 gcry_cipher_open(&enc, GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM, 0); 0019 gcry_cipher_setkey(enc, ek.getData(), 20); 0020 gcry_cipher_open(&dec, GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM, 0); 0021 gcry_cipher_setkey(dec, dk.getData(), 20); 0022 0023 Uint8 tmp[1024]; 0024 gcry_cipher_encrypt(enc, tmp, 1024, tmp, 1024); 0025 gcry_cipher_decrypt(dec, tmp, 1024, tmp, 1024); 0026 } 0027 0028 RC4Encryptor::~RC4Encryptor() 0029 { 0030 gcry_cipher_close(enc); 0031 gcry_cipher_close(dec); 0032 } 0033 0034 void RC4Encryptor::decrypt(Uint8 *data, Uint32 len) 0035 { 0036 gcry_cipher_decrypt(dec, data, len, data, len); 0037 } 0038 0039 const Uint8 *RC4Encryptor::encrypt(const Uint8 *data, Uint32 len) 0040 { 0041 gcry_cipher_encrypt(enc, rc4_enc_buffer, len, data, len); 0042 return rc4_enc_buffer; 0043 } 0044 0045 void RC4Encryptor::encryptReplace(Uint8 *data, Uint32 len) 0046 { 0047 gcry_cipher_encrypt(enc, data, len, data, len); 0048 } 0049 0050 }