Botcraft 1.21.4
Loading...
Searching...
No Matches
AESEncrypter.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ENCRYPTION
4
5#include <vector>
6#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
7#include <string>
8#endif
9
10typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
11
12namespace Botcraft
13{
15 {
16 public:
19#if PROTOCOL_VERSION < 759 /* < 1.19 */
20 /// @brief Initialize the encryption context for this connection
21 /// @param pub_key Server public key
22 /// @param input_nonce Server input nonce
23 /// @param raw_shared_secret Output shared secret
24 /// @param encrypted_nonce Input nonce encrypted using server public key key
25 /// @param encrypted_shared_secret Shared secret encrypted using server public key
26 void Init(const std::vector<unsigned char>& pub_key, const std::vector<unsigned char>& input_nonce,
27 std::vector<unsigned char>& raw_shared_secret, std::vector<unsigned char>& encrypted_nonce, std::vector<unsigned char>& encrypted_shared_secret);
28#elif PROTOCOL_VERSION < 761 /* < 1.19.3 */
29 /// @brief Initialize the encryption context for this connection
30 /// @param pub_key Server public key
31 /// @param input_nonce Server input nonce
32 /// @param private_key Player private RSA certificate
33 /// @param raw_shared_secret Output shared secret
34 /// @param encrypted_shared_secret Shared secret encrypted using server public key
35 /// @param salt Output random salt used to compute the signature
36 /// @param salted_nonce_signature Output signature of the salted nonce
37 void Init(const std::vector<unsigned char>& pub_key, const std::vector<unsigned char>& input_nonce, const std::string& private_key,
38 std::vector<unsigned char>& raw_shared_secret, std::vector<unsigned char>& encrypted_shared_secret,
39 long long int& salt, std::vector<unsigned char>& salted_nonce_signature);
40#else
41 /// @brief Initialize the encryption context for this connection
42 /// @param pub_key Server public key
43 /// @param input_nonce Server input nonce
44 /// @param raw_shared_secret Output shared secret
45 /// @param encrypted_shared_secret Shared secret encrypted using server public key
46 /// @param encrypted_challenge Output encrypted challenge
47 void Init(const std::vector<unsigned char>& pub_key, const std::vector<unsigned char>& input_nonce,
48 std::vector<unsigned char>& raw_shared_secret, std::vector<unsigned char>& encrypted_shared_secret,
49 std::vector<unsigned char>& encrypted_challenge);
50#endif
51 std::vector<unsigned char> Encrypt(const std::vector<unsigned char>& in);
52 std::vector<unsigned char> Decrypt(const std::vector<unsigned char>& in);
53
54 private:
57 unsigned int blocksize;
58 };
59}
60#endif // USE_ENCRYPTION
struct evp_cipher_ctx_st EVP_CIPHER_CTX
void Init(const std::vector< unsigned char > &pub_key, const std::vector< unsigned char > &input_nonce, std::vector< unsigned char > &raw_shared_secret, std::vector< unsigned char > &encrypted_shared_secret, std::vector< unsigned char > &encrypted_challenge)
Initialize the encryption context for this connection.
EVP_CIPHER_CTX * decryption_context
std::vector< unsigned char > Encrypt(const std::vector< unsigned char > &in)
EVP_CIPHER_CTX * encryption_context
std::vector< unsigned char > Decrypt(const std::vector< unsigned char > &in)