12#ifndef MINESERVER_CRYPTO_H
13#define MINESERVER_CRYPTO_H
18#include <openssl/rsa.h>
19#include <openssl/evp.h>
117 std::string
md5Digest(
const std::string &data);
154 void update(
const std::string &
s);
242 int update(
const std::byte *data,
size_t len, std::byte *
out);
273 int compressionLevel;
AES/CFB8 128bit cipher class.
Definition crypto.h:205
int update(const std::byte *data, size_t len, std::byte *out)
Updates, encrypting or decrypting depending on the state.
Definition crypto.cpp:217
int finalize(std::byte *out)
Finalizes cipher, encrypting / decrypting the rest of the bytes.
Definition crypto.cpp:228
~AES128CFB8Cipher()
Destroy the AES/CFB8 128bit cipher object.
Definition crypto.cpp:212
size_t calculateBufferSize(size_t len)
Calculates minimal buffer size for the cipher.
Definition crypto.cpp:238
AES128CFB8Cipher(CipherState state, const std::byte *key, const std::byte *iv)
Construct a new AES/CFB8 128bit cipher object.
Definition crypto.cpp:201
The Minecraft Hashing class.
Definition crypto.h:129
MinecraftHash()
Construct a new Minecraft Hash object.
Definition crypto.cpp:144
~MinecraftHash()
Destroy the Minecraft Hash object.
Definition crypto.cpp:150
void update(const std::string &s)
Updates the hash.
Definition crypto.cpp:155
std::string finalize()
Finalizes the hash.
Definition crypto.cpp:160
ZLib compressor.
Definition crypto.h:271
ZLibCompressor(int level)
Construct a new Zlib Compressor object.
Definition crypto.cpp:249
~ZLibCompressor()=default
Destroy the Zlib Compressor object.
int uncompress(const std::byte *data, size_t len, std::byte *out, size_t outLen)
Uncompresses data (inflate)
Definition crypto.cpp:295
int compress(const std::byte *data, size_t len, std::byte *out, size_t outLen)
Compresses data (deflate)
Definition crypto.cpp:253
constexpr std::string_view type_name()
Gets the name of the type paramater.
Definition event.h:56
The crypto namespace.
Definition crypto.h:29
std::unique_ptr< std::byte[]> rsaDecrypt(const std::byte *data, size_t len, size_t *outLen)
Decrypts data using the server's RSA keypair.
Definition crypto.cpp:78
std::unique_ptr< std::byte[]> rsaEncrypt(const std::byte *data, size_t len, size_t *outLen)
Encrypts data using the server's RSA keypair.
Definition crypto.cpp:52
bool init()
Inits Crypto.
Definition crypto.cpp:27
std::unique_ptr< std::byte[]> randomSecure(size_t len)
Generates randoms bytes securely.
Definition crypto.cpp:117
CipherState
Possible cipher states.
Definition crypto.h:173
@ DECRYPT
Decrypt Cipher state.
Definition crypto.h:181
@ ENCRYPT
ENCRYPT Cipher state.
Definition crypto.h:189
constexpr int RSA_KEY_LENGTH
The length of the rsa keys.
Definition crypto.h:37
std::string md5Digest(const std::string &data)
MD5 digests a string.
Definition crypto.cpp:126
void cleanup()
Cleanups Crypto.
Definition crypto.cpp:47
std::unique_ptr< std::byte[]> getPublicRSAKey(int *outLen)
Get the Public RSA Public Key.
Definition crypto.cpp:104