Botcraft 1.21.10
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
10struct evp_cipher_ctx_st;
11typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
12#if PROTOCOL_VERSION > 758 /* > 1.18.2 */ && PROTOCOL_VERSION < 761 /* < 1.19.3 */
13struct rsa_st;
14typedef struct rsa_st RSA;
15#endif
16
17namespace Botcraft
18{
20 {
21 public:
24#if PROTOCOL_VERSION < 759 /* < 1.19 */
25 /// @brief Initialize the encryption context for this connection
26 /// @param pub_key Server public key
27 /// @param input_nonce Server input nonce
28 /// @param raw_shared_secret Output shared secret
29 /// @param encrypted_nonce Input nonce encrypted using server public key key
30 /// @param encrypted_shared_secret Shared secret encrypted using server public key
31 void Init(const std::vector<unsigned char>& pub_key, const std::vector<unsigned char>& input_nonce,
32 std::vector<unsigned char>& raw_shared_secret, std::vector<unsigned char>& encrypted_nonce, std::vector<unsigned char>& encrypted_shared_secret);
33#elif PROTOCOL_VERSION < 761 /* < 1.19.3 */
34 /// @brief Initialize the encryption context for this connection
35 /// @param pub_key Server public key
36 /// @param input_nonce Server input nonce
37 /// @param private_key Player private RSA certificate
38 /// @param raw_shared_secret Output shared secret
39 /// @param encrypted_shared_secret Shared secret encrypted using server public key
40 /// @param salt Output random salt used to compute the signature
41 /// @param salted_nonce_signature Output signature of the salted nonce
42 void Init(const std::vector<unsigned char>& pub_key, const std::vector<unsigned char>& input_nonce, RSA* private_key,
43 std::vector<unsigned char>& raw_shared_secret, std::vector<unsigned char>& encrypted_shared_secret,
44 long long int& salt, std::vector<unsigned char>& salted_nonce_signature);
45#else
46 /// @brief Initialize the encryption context for this connection
47 /// @param pub_key Server public key
48 /// @param input_nonce Server input nonce
49 /// @param raw_shared_secret Output shared secret
50 /// @param encrypted_shared_secret Shared secret encrypted using server public key
51 /// @param encrypted_challenge Output encrypted challenge
52 void Init(const std::vector<unsigned char>& pub_key, const std::vector<unsigned char>& input_nonce,
53 std::vector<unsigned char>& raw_shared_secret, std::vector<unsigned char>& encrypted_shared_secret,
54 std::vector<unsigned char>& encrypted_challenge);
55#endif
56 std::vector<unsigned char> Encrypt(const std::vector<unsigned char>& in);
57 std::vector<unsigned char> Decrypt(const std::vector<unsigned char>& in);
58
59 private:
62 unsigned int blocksize;
63 };
64}
65#endif // USE_ENCRYPTION
struct evp_cipher_ctx_st EVP_CIPHER_CTX
struct rsa_st RSA
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)