Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
crypto Namespace Reference

The crypto namespace. More...

Classes

class  AES128CFB8Cipher
 AES/CFB8 128bit cipher class. More...
 
class  MinecraftHash
 The Minecraft Hashing class. More...
 
class  ZLibCompressor
 ZLib compressor. More...
 

Enumerations

enum  CipherState { DECRYPT , ENCRYPT }
 Possible cipher states. More...
 

Functions

bool init ()
 Inits Crypto.
 
void cleanup ()
 Cleanups Crypto.
 
std::unique_ptr< std::byte[]> rsaEncrypt (const std::byte *data, size_t len, size_t *outLen)
 Encrypts data using the server's RSA keypair.
 
std::unique_ptr< std::byte[]> rsaDecrypt (const std::byte *data, size_t len, size_t *outLen)
 Decrypts data using the server's RSA keypair.
 
std::unique_ptr< std::byte[]> getPublicRSAKey (int *outLen)
 Get the Public RSA Public Key.
 
std::unique_ptr< std::byte[]> randomSecure (size_t len)
 Generates randoms bytes securely.
 
std::string md5Digest (const std::string &data)
 MD5 digests a string.
 

Variables

constexpr int RSA_KEY_LENGTH = 1024
 The length of the rsa keys.
 

Detailed Description

The crypto namespace.

The namespace containing all of the crypto-related utilities functions.

Enumeration Type Documentation

◆ CipherState

Possible cipher states.

Enum containing the possibilities of what could do a cipher, to not have to create 2 separate classes.

Enumerator
DECRYPT 

Decrypt Cipher state.

Cipher state so that the update method decrypts instead encrypting. Same for finalize.

ENCRYPT 

ENCRYPT Cipher state.

Cipher state so that the update method encrypts instead decrypting. Same for finalize.

Function Documentation

◆ cleanup()

void crypto::cleanup ( )

Cleanups Crypto.

Cleanups the bloat that was created when starting OpenSSL, including the RSA keypair

◆ getPublicRSAKey()

std::unique_ptr< std::byte[]> crypto::getPublicRSAKey ( int * outLen)

Get the Public RSA Public Key.

Formats the public key from the startup keypair into DER format, which is an underlying ASN.1 format defined by x.509

Parameters
outLena pointer to a variable that will hold the length of the key returned
Returns
std::byte * The public key formatted

◆ init()

bool crypto::init ( )

Inits Crypto.

Inits OpenSSL and generates an RSA Keypair to be used in encryption.

Returns
true Init went correctly
false Something went wrong

◆ md5Digest()

std::string crypto::md5Digest ( const std::string & data)

MD5 digests a string.

Returns an MD5 digest of the data given, really used just for MinecraftUUID creation from Player's usernames

Parameters
datathe data to digest
Returns
std::string the md5 string in hex

◆ randomSecure()

std::unique_ptr< std::byte[]> crypto::randomSecure ( size_t len)

Generates randoms bytes securely.

Generates len bytes in a secure way, which just means we let OpenSSL do the heavy lifting.

Parameters
lenthe size of the bytes to generate
Returns
std::unique_ptr<std::byte[]> A pointer to the generated bytes

◆ rsaDecrypt()

std::unique_ptr< std::byte[]> crypto::rsaDecrypt ( const std::byte * data,
size_t len,
size_t * outLen )

Decrypts data using the server's RSA keypair.

Decrypts len of data and returns it as a unique pointer to the decrypted data of length outLen The keypair used is generated at startup in crypto::init(). It uses RSA PKCS1 padding.

Parameters
dataThe data to decrypt
lenThe length of the data to decrypt
outLenA pointer to a variable that will store the encrypted data length
Returns
std::unique_ptr<std::byte[]> the encrypted data

◆ rsaEncrypt()

std::unique_ptr< std::byte[]> crypto::rsaEncrypt ( const std::byte * data,
size_t len,
size_t * outLen )

Encrypts data using the server's RSA keypair.

Encrypts len of data and returns it as a unique pointer to the encrypted data of length outLen The keypair used is generated at startup in crypto::init(). It uses RSA PKCS1 padding.

Parameters
dataThe data to encrypt
lenThe length of the data to encrypt
outLenA pointer to a variable that will store the encrypted data length
Returns
std::unique_ptr<std::byte[]> the encrypted data

Variable Documentation

◆ RSA_KEY_LENGTH

constexpr int crypto::RSA_KEY_LENGTH = 1024
constexpr

The length of the rsa keys.

The length of the RSA keys that the server should generate at the start to be used for encryption scheme.