Overview
Conditional Directives
Building and Requirements
Enumerations
Type Definitions
Functions
gxRandom Class
Example
10/14/2026 Changes
Overview
The gxSSL class is an OpenSSL wrapper used to add SSL/TLS encryption to client and server socket applications. A gxSSL object holds the OpenSSL context object, the SSL object and the BIO objects used for socket I/O, and provides functions to load certificates and keys, perform the handshake, send and receive data, verify peer certificates and generate RSA keys, self-signed certificates and Diffie-Hellman parameters.
gxSSL works with any connected socket, such as a gxSocket object. The socket is opened and connected or accepted as usual and then passed to OpenSSLSocket(). Some of the class functions were derived from "SSL and TLS: Designing and Building Secure Systems" by Eric Rescorla (Addison Wesley, 2001) and from the OpenSSL documentation and example programs.
The include file also defines the gxRandom class, a pseudo random number table generator used internally by gxSSL. See gxRandom Class.
Conditional Directives
__USE_GX_SSL_EXTENSIONS__ - Conditional directive required to build the gxSSL class. Without it only the gxRandom class is compiled.
__WIN32__ - Conditional directive required for all WIN32 platforms
__UNIX__ - Conditional directive required for all UNIX variants.
__LINUX__ - Conditional directive required for all Linux platforms.
Building and Requirements
gxSSL builds with OpenSSL 1.0.2, 1.1.x and 3.x. OpenSSL 3 is recommended. The code selects the OpenSSL interfaces from OPENSSL_VERSION_NUMBER, so no other settings are needed.
Linux library build:
export USE_OPEN_SSL=YES make -f makefile_ssl
Applications are compiled with -D__USE_GX_SSL_EXTENSIONS__ and linked with -lssl -lcrypto. For Windows builds see the Windows Builds section of the readme.
Enumerations
enum gxSSLMethod { gxSSL_SSLv23, // Supported protocols are SSLv2, SSLv3, TLSv1, TLSv1.1 and TLSv1.2 gxSSL_SSLv2, // Only understand SSLv2 gxSSL_SSLv3, // Only understand SSLv3 gxSSL_TLSv1, // Only understand TLSv1 gxSSL_TLS, // Supported protocols SSLv3, TLSv1, TLSv1.1 and TLSv1.2 gxSSL_TLSv1_1, // Only understand TLSv1.1 gxSSL_TLSv1_2, // Only understand TLSv1.2 gxSSL_DTLS, gxSSL_DTLSv1, gxSSL_DTLSv1_2 };
Newer OpenSSL versions no longer support SSLv2 and SSLv3. With OpenSSL 1.1.0 and later gxSSL_SSLv2 and gxSSL_SSLv3 select the version flexible method. Use gxSSL_TLS for new applications; it negotiates the highest TLS version supported by both sides.
enum gxSSLCertType { gxSSL_PEM, // Privacy Enhancement Mechanisms gxSSL_ASN1 // Abstract Syntax Notation One };
enum gxSSLError { // Open SSL exception codes gxSSL_NO_ERROR = 0, // No errors reported gxSSL_INVALID_ERROR_CODE, // Invalid socket error code // SSL error codes gxSSL_ACCEPT_ERROR, // Error accepting remote socket gxSSL_AES_ERROR, // AES crypto error gxSSL_AESGEN_ERROR, // Error generating AES key gxSSL_AESKEY_ERROR, // Error processing AES key gxSSL_ASN1_ERROR, // ASN.1 error gxSSL_ASN1_CERT_ERROR, // Error processing ASN.1 cert gxSSL_ASN1_REQ_ERROR, // Error processing ASN.1 cert req gxSSL_BIO_ERROR, // BIO I/O error gxSSL_BIND_ERROR, // Could not bind socket gxSSL_BLOWFISH_ERROR, // Blowfish crypto error gxSSL_BLOWFISHGEN_ERROR, // Error generating blowfish key gxSSL_BLOWFISHKEY_ERROR, // Error processing blowfish key gxSSL_BUFOVER_ERROR, // Buffer overflow gxSSL_CALIST_ERROR, // Error processing CA list gxSSL_CERT_ERROR, // Error processing certificate gxSSL_CERT_VER_ERROR, // Cert doesn't verify gxSSL_CLOSE_ERROR, // TLS/SSL connection has been closed gxSSL_CONNECT_ERROR, // Could not connect socket gxSSL_CTX_INIT_ERROR, // Context object not initialized gxSSL_DES_ERROR, // DES crypto error gxSSL_DHPARMS_ERROR, // Error processing DH parameters gxSSL_DHPARMS_GEN_ERROR, // Error generating DH parameters gxSSL_DISCONNECTED_ERROR, // Socket has been disconnected gxSSL_DSA_ERROR, // DSA crypto error gxSSL_DSAGEN_ERROR, // Error generating DSA key gxSSL_DSAKEY_ERROR, // Error processing DSA key gxSSL_FBIO_INIT_ERROR, // File BIO not initialized gxSSL_FILELENGTH_ERROR, // File length does not match expected value gxSSL_FILEMODTIME_ERROR, // File modification time dates do not match gxSSL_FILESYSTEM_ERROR, // A file system error occurred gxSSL_HOSTNAME_ERROR, // Could not resolve hostname gxSSL_INIT_ERROR, // Initialization error gxSSL_KRB_ERROR, // Kerberos crypto error gxSSL_LIB_ERROR, // Library error gxSSL_LISTEN_ERROR, // Listen error gxSSL_KEY_ERROR, // Error processing private key gxSSL_MAC_ERROR, // MAC crypto error gxSSL_MD5_ERROR, // MD5 hash error gxSSL_MBIO_INIT_ERROR, // Memory BIO not initialized gxSSL_NULL_PTR_ERROR, // Accessing a null pointer gxSSL_PASSWD_ERROR, // Error processing password gxSSL_PEERCN_ERROR, // CN doesn't match hostname gxSSL_PEERCERT_ERROR, // Error processing peer cert gxSSL_PRNG_ERROR, // Pseudo random number error gxSSL_PROTOCOL_ERROR, // Error setting requested protocol gxSSL_PUBKEY_ERROR, // Error processing public key gxSSL_READ_ERROR, // Read operation did not complete gxSSL_RECEIVE_ERROR, // Receive error gxSSL_REQUEST_TIMEOUT, // Request timed out gxSSL_RSA_ERROR, // RSA crypto error gxSSL_RSAGEN_ERROR, // Error generating RSA key gxSSL_RSAKEY_ERROR, // Error processing RSA key gxSSL_SBIO_INIT_ERROR, // Socket BIO not initialized gxSSL_SHA_ERROR, // SHA crypto error gxSSL_SHUTDOWN_ERROR, // Shutdown failed gxSSL_SSL_INIT_ERROR, // SSL object not initialized gxSSL_TRANSMIT_ERROR, // Transmit error gxSSL_WRITE_ERROR, // Write operation did not complete gxSSL_X509_ERROR, // X509 error gxSSL_X509_CERT_ERROR, // Error processing X509 cert gxSSL_X509_GEN_ERROR, // Error generating X509 cert gxSSL_X509_LOOKUP_ERROR, // X509 lookup error gxSSL_X509_REQ_ERROR, // Error processing X509 cert req gxSSL_X509_REQGEN_ERROR, // Error generating X509 cert req // Additional SSL and crypto error codes // Exception codes for database block errors gxSSL_BLOCKACK_ERROR, // Database block acknowledgment error gxSSL_BLOCKHEADER_ERROR, // Bad database block header gxSSL_BLOCKSIZE_ERROR, // Bad database block size gxSSL_BLOCKSYNC_ERROR, // Database block synchronization error // Exception code used to allow application to set error string gxSSL_APPDEF_ERROR // Application defined error };
Type Definitions
KeyGenCallbackFunc - typedef void ((*KeyGenCallbackFunc)(int,int,void *)); Callback function type called during RSA key generation by MakeRSAPrivateKey(). The first two arguments report the generation stage and count, and the third is the cb_arg value passed to MakeRSAPrivateKey().
gxCertIssuerInfo - Structure used by MakeCertReq() to set the certificate subject and issuer, serial number, expiration and extensions.
struct gxCertIssuerInfo { gxCertIssuerInfo() { ResetCert(); } ~gxCertIssuerInfo() { } gxCertIssuerInfo(gxCertIssuerInfo &ob) { CopyCert(ob); } void operator=(gxCertIssuerInfo &ob) { if(&ob != this) CopyCert(ob); } void ResetCert(); void CopyCert(gxCertIssuerInfo &ob); // Certificate issuer fields gxString C; // Country Name = C gxString ST; // State or Province Name = ST gxString L; // Locality Name = L gxString O; // Organization Name = O gxString OU; // Organizational Unit Name = OU gxString CN; // Common Name = CN int sn; // Cert serial number int days; // Days to expire // Optional values and or settings gxString passwd; // Optional challenge password gxString company_name; // Optional company name gxString email_address; // Optional Email address // Standard extensions gxString basic_constraints; gxString key_usage; gxString subject_key_identifier; // Netscape specific extensions gxString netscape_cert_type; gxString netscape_comment; };
Functions
gxSSL::AcceptSSLSocket()
gxSSL::CAList()
gxSSL::CertFile()
gxSSL::CertType()
gxSSL::CloseSSLSocket()
gxSSL::ConnectSSLSocket()
gxSSL::DestroyCTX()
gxSSL::DestroySSL()
gxSSL::FileBIO()
gxSSL::GetCTX()
gxSSL::GetSSL()
gxSSL::GetSSLError()
gxSSL::GlobalSSLError()
gxSSL::HasError()
gxSSL::HasLibInit()
gxSSL::HasVerifyCert()
gxSSL::InitCTX()
gxSSL::InitCTX()
gxSSL::InitCTX()
gxSSL::InitPRNG()
gxSSL::InitPRNG()
gxSSL::InitSSLibrary()
gxSSL::IsClient()
gxSSL::IsServer()
gxSSL::KeyFile()
gxSSL::LoadDHParms()
gxSSL::MakeCertReq()
gxSSL::MakeClient()
gxSSL::MakeDHParms()
gxSSL::MakeRSAEphKey()
gxSSL::MakeRSAPrivateKey()
gxSSL::MakeServer()
gxSSL::MemoryBIO()
gxSSL::NoVerifyCert()
gxSSL::OpenSSLSocket()
gxSSL::Passwd()
gxSSL::RandomFile()
gxSSL::RawReadSSLSocket()
gxSSL::RawWriteSSLSocket()
gxSSL::RecvSSLSocket()
gxSSL::RecvSSLSocket()
gxSSL::RecvSSLSocket()
gxSSL::Release()
gxSSL::ReleaseCTX()
gxSSL::ReleaseFBIO()
gxSSL::ReleaseMBIO()
gxSSL::ReleaseSBIO()
gxSSL::ReleaseSSL()
gxSSL::ReleaseSSLLibrary()
gxSSL::RequireVerifyCert()
gxSSL::ResetAppError()
gxSSL::ResetSSLError()
gxSSL::SendSSLSocket()
gxSSL::SetAppError()
gxSSL::SetCAList()
gxSSL::SetCertFile()
gxSSL::SetCertType()
gxSSL::SetCTX()
gxSSL::SetFileBIO()
gxSSL::SetKeyFile()
gxSSL::SetMemoryBIO()
gxSSL::SetPasswd()
gxSSL::SetRandomFile()
gxSSL::SetSocketBIO()
gxSSL::SetSSL()
gxSSL::SetSSLError()
gxSSL::SetSSLProto()
gxSSL::SocketBIO()
gxSSL::SSLErrorMessage()
gxSSL::SSLExceptionMessage()
gxSSL::SSLProto()
gxSSL::VerifyCert()
gxSSL::gxSSL()
gxSSL::~gxSSL()
gxSSL::gxSSL()
int gxSSL::AcceptSSLSocket()Public member function used by a server to accept an SSL/TLS connection from a client after OpenSSLSocket() has been called with the accepted socket. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
const char *gxSSL::CAList()Public member function that returns the name of the certificate authority list file.
const char *gxSSL::CertFile()Public member function that returns the name of the certificate file.
gxSSLCertType gxSSL::CertType()Public member function that returns the certificate and key file format, gxSSL_PEM or gxSSL_ASN1.
int gxSSL::CloseSSLSocket(int destroy_ssl = 1)Public member function used to shut down the SSL/TLS connection. If the first shutdown call does not complete, the write side of the socket is shut down and the shutdown is retried. If destroy_ssl is true the SSL object is destroyed after the shutdown. The underlying socket is not closed. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
int gxSSL::ConnectSSLSocket()Public member function used by a client to start the SSL/TLS handshake with a server after OpenSSLSocket() has been called with a connected socket. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
void gxSSL::DestroyCTX()Public member function used to free the SSL context object.
void gxSSL::DestroySSL()Public member function used to free the SSL object. The socket BIO is freed with the SSL object.
BIO *gxSSL::FileBIO()Public member function that returns a pointer to the file BIO.
SSL_CTX *gxSSL::GetCTX()Public member function that returns a pointer to the SSL context object.
SSL *gxSSL::GetSSL()Public member function that returns a pointer to the SSL object.
gxSSLError gxSSL::GetSSLError()Public member function that returns the last reported SSL error code.
static void gxSSL::GlobalSSLError(gxString &err_str)Public static member function that passes back the OpenSSL library error string for the last error in the err_str variable.
int gxSSL::HasError()Public member function that returns true if an SSL error has been reported.
int gxSSL::HasLibInit()Public member function that returns true if the OpenSSL library has been initialized.
int gxSSL::HasVerifyCert()Public member function that returns true if certificate verification is required.
SSL_CTX *gxSSL::InitCTX()Public member function used to create the SSL context object. The protocol is set by SetSSLProto() and by MakeClient() or MakeServer(). The certificate file, private key file, key passphrase and CA list are loaded when they have been set. Returns a pointer to the context object or a null value if an error occurs.
SSL_CTX *gxSSL::InitCTX(const char *cert_fname, const char *key_fname)Public member function used to create the SSL context object using the specified certificate and private key files. Returns a pointer to the context object or a null value if an error occurs.
SSL_CTX *gxSSL::InitCTX(const char *cert_fname, const char *key_fname, const char *key_passphrase)Public member function used to create the SSL context object using the specified certificate file and a passphrase protected private key file. Returns a pointer to the context object or a null value if an error occurs.
int gxSSL::InitPRNG(const char *r_file, int check_prng_init = 1)Public member function used to seed the OpenSSL pseudo random number generator from the r_file random data file. If check_prng_init is true the generator is only seeded if it has not already been seeded. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
int gxSSL::InitPRNG(int check_prng_init = 1)Public member function used to seed the OpenSSL pseudo random number generator. If check_prng_init is true the generator is only seeded if it has not already been seeded. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
static int gxSSL::InitSSLibrary()Public static member function used to initialize the OpenSSL library and load its error strings. Called by InitCTX(). Returns true after initialization or if the library was previously initialized.
int gxSSL::IsClient()Public member function that returns true if this object is configured for client connections.
int gxSSL::IsServer()Public member function that returns true if this object is configured for server connections.
const char *gxSSL::KeyFile()Public member function that returns the name of the private key file.
int gxSSL::LoadDHParms(const char *fname)Public member function used to load Diffie-Hellman parameters from the fname PEM file into the SSL context object for DHE cipher suites. The context must be created with InitCTX() first. With OpenSSL 3 the parameters are read with PEM_read_bio_Parameters() and set with SSL_CTX_set0_tmp_dh_pkey(). OpenSSL 3 rejects parameters smaller than 2048 bits at its default security level. Returns 0 if successful or a non-zero gxSSLError code if an error occurs. NOTE: 10/14/2026: Errors setting the parameters are now reported. Earlier versions missed the OpenSSL 1.x failure value of 0.
int gxSSL::MakeCertReq(const char *key_fname, gxCertIssuerInfo &ci, const char *req_fname)Public member function used to write a self-signed X509 certificate for the private key in key_fname to the req_fname file. The ci variable sets the subject and issuer fields, serial number, days to expire and certificate extensions. See gxCertIssuerInfo. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
int gxSSL::MakeClient()Public member function used to configure this object for client connections. Call before InitCTX().
int gxSSL::MakeDHParms(const char *dh_fname, unsigned char *dh1024_p = 0, int dh1024_p_len = 0, unsigned char *dh1024_g = 0, int dh1024_g_len = 0)Public member function used to write Diffie-Hellman parameters to the dh_fname file in PEM format. The prime and generator are passed as big-endian byte arrays in dh1024_p and dh1024_g. If they are not specified the RFC 7919 ffdhe2048 group (2048-bit prime, generator 2) is written. The parameter names are kept for compatibility; primes of any length can be passed. Returns 0 if successful or a non-zero gxSSLError code if an error occurs. NOTE: 10/14/2026: The default group was a 1024-bit prime, which OpenSSL 3 rejects ("dh key too small") and which is too weak to use.
int gxSSL::MakeRSAEphKey(int key_len = 512)Public member function used to set a temporary RSA key for export cipher suites. With OpenSSL 1.1.0 and later temporary RSA keys are not supported and this function does nothing and returns 0.
int gxSSL::MakeRSAPrivateKey(const char *key_fname, int key_len = 512, KeyGenCallbackFunc cb_func = 0, void *cb_arg = 0)Public member function used to generate an RSA private key of key_len bits and write it to the key_fname file in PEM format. The optional cb_func callback is called with cb_arg during key generation to report progress. The pseudo random number generator is seeded before the key is generated. Use a key_len of 2048 or more; the 512-bit default is kept for compatibility only. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
int gxSSL::MakeServer()Public member function used to configure this object for server connections. Call before InitCTX().
BIO *gxSSL::MemoryBIO()Public member function that returns a pointer to the memory BIO.
int gxSSL::NoVerifyCert()Public member function used to turn off certificate verification.
int gxSSL::OpenSSLSocket(gxsSocket_t s)Public member function used to attach an SSL object to the open socket s. The context object is created with InitCTX() if it does not exist. Call ConnectSSLSocket() for a client or AcceptSSLSocket() for a server after this function. Returns 0 if successful or a non-zero gxSSLError code if an error occurs.
const char *gxSSL::Passwd()Public member function that returns the private key passphrase.
const char *gxSSL::RandomFile()Public member function that returns the name of the random data file used to seed the random number generator.
int gxSSL::RawReadSSLSocket(void *buf, int bytes)Public member function used to read up to the specified number of bytes into buf. A raw read may return before all the bytes have been read. Returns the number of bytes read or -1 if an error occurs.
int gxSSL::RawWriteSSLSocket(const void *buf, int bytes)Public member function used to write the specified number of bytes from buf. A raw write may return before all the bytes have been written. Returns the number of bytes written or -1 if an error occurs.
int gxSSL::RecvSSLSocket(void *buf, int bytes)Public member function used to read the specified number of bytes into buf and not return until all the bytes have been read. Returns the number of bytes read or -1 if an error occurs.
int gxSSL::RecvSSLSocket(void *buf, int bytes, int seconds, int useconds)Public member function used to read the specified number of bytes into buf and not return until all the bytes have been read or the timeout value has been exceeded. Returns the number of bytes read or -1 if an error occurs.
int gxSSL::RecvSSLSocket(void *buf, int bytes, int useTimeout, int seconds, int useconds)Public member function used to read the specified number of bytes into buf. If useTimeout is true the read stops when the timeout value is exceeded. Returns the number of bytes read or -1 if an error occurs and no bytes were read.
void gxSSL::Release()Public member function used to clear the context, SSL and BIO pointers without freeing them. Used when the objects are owned by another gxSSL object or thread. NOTE: 10/14/2026: Added. The misspelled Relase() function is kept for existing code and now calls Release(). Relase() used to copy the memory BIO pointer into the socket and file BIO pointers instead of clearing them.
void gxSSL::ReleaseCTX()Public member function used to clear the context pointer without freeing the context object.
void gxSSL::ReleaseFBIO()Public member function used to clear the file BIO pointer without freeing it.
void gxSSL::ReleaseMBIO()Public member function used to clear the memory BIO pointer without freeing it.
void gxSSL::ReleaseSBIO()Public member function used to clear the socket BIO pointer without freeing it.
void gxSSL::ReleaseSSL()Public member function used to clear the SSL pointer without freeing the SSL object.
static int gxSSL::ReleaseSSLLibrary()Public static member function used to mark the OpenSSL library as released. Returns true.
int gxSSL::RequireVerifyCert()Public member function used to require certificate verification.
void gxSSL::ResetAppError()Public member function used to clear the application error string.
gxSSLError gxSSL::ResetSSLError()Public member function used to reset the last reported SSL error to gxSSL_NO_ERROR. ResetError() is the same function.
int gxSSL::SendSSLSocket(const void *buf, int bytes)Public member function used to write the specified number of bytes from buf and not return until all the bytes have been written. Returns the number of bytes written or -1 if an error occurs.
int gxSSL::SetAppError(const char *s)Public member function used to set an application defined error string and the gxSSL_APPDEF_ERROR error code.
void gxSSL::SetCAList(const char *s)Public member function used to set the certificate authority list file used to verify peer certificates. Set before InitCTX().
void gxSSL::SetCertFile(const char *s)Public member function used to set the certificate file. Set before InitCTX().
void gxSSL::SetCertType(gxSSLCertType t)Public member function used to set the certificate and key file format, gxSSL_PEM (default) or gxSSL_ASN1.
void gxSSL::SetCTX(SSL_CTX *p)Public member function used to set the context object pointer, for example to share one context between threads.
void gxSSL::SetFileBIO(BIO *p)Public member function used to set the file BIO pointer.
void gxSSL::SetKeyFile(const char *s)Public member function used to set the private key file. Set before InitCTX().
void gxSSL::SetMemoryBIO(BIO *p)Public member function used to set the memory BIO pointer.
void gxSSL::SetPasswd(const char *s)Public member function used to set the private key passphrase. Set before InitCTX().
void gxSSL::SetRandomFile(const char *s)Public member function used to set the random data file used to seed the random number generator.
void gxSSL::SetSocketBIO(BIO *p)Public member function used to set the socket BIO pointer.
void gxSSL::SetSSL(SSL *p)Public member function used to set the SSL object pointer.
gxSSLError gxSSL::SetSSLError(gxSSLError err)Public member function used to set the SSL error code.
void gxSSL::SetSSLProto(gxSSLMethod m)Public member function used to set the SSL/TLS protocol. Set before InitCTX(). See gxSSLMethod.
BIO *gxSSL::SocketBIO()Public member function that returns a pointer to the socket BIO.
const char *gxSSL::SSLErrorMessage()Public member function that returns a null terminated string describing the last SSL error. Same as SSLExceptionMessage().
const char *gxSSL::SSLExceptionMessage()Public member function that returns a null terminated string that can be used to log or print the last SSL exception.
gxSSLMethod gxSSL::SSLProto()Public member function that returns the SSL/TLS protocol setting.
int gxSSL::VerifyCert(const char *hostname, long *X509_return_code = 0)Public member function used to verify the certificate presented by the peer. The certificate must pass OpenSSL verification and its common name must match hostname (not case sensitive). If X509_return_code is not null the OpenSSL verify result is passed back in it. Returns 0 if successful, gxSSL_PEERCERT_ERROR if no certificate was presented, gxSSL_CERT_VER_ERROR if verification failed or gxSSL_PEERCN_ERROR if the common name does not match.
gxSSL::gxSSL()Default class constructor.
virtual gxSSL::~gxSSL()Class destructor. Shuts down an open SSL connection and frees the SSL and context objects.
gxSSL::gxSSL(SSL_CTX *p)Class constructor used to create an object that shares the existing context object p.
gxRandom Class
The gxRandom class generates tables of pseudo random numbers and seeds. It is used internally by gxSSL and does not require OpenSSL. It is not a cryptographic random number generator; use InitPRNG() and the OpenSSL generator for keys and other secrets.
gxRandom::PRNGTable()
gxRandom::PRNGTable()
gxRandom::RandomNumber()
gxRandom::Seed()
gxRandom::Seed()
gxRandom::SeedTable()
gxRandom::gxRandom()
gxRandom::~gxRandom()
unsigned *gxRandom::PRNGTable(unsigned table_size, unsigned long r_seed = 0)Public member function used to allocate and fill a table of table_size pseudo random numbers. The r_seed value seeds the generator. The calling function must free the table with delete[].
unsigned *gxRandom::PRNGTable(unsigned *table1, unsigned table_size, unsigned long r_seed = 0)Public member function used to refill the previously allocated table1 of table_size entries with pseudo random numbers.
unsigned gxRandom::RandomNumber(unsigned long r_seed = 0)Public member function that returns a pseudo random number.
unsigned gxRandom::Seed(int reuse = 1)Public member function that returns the next seed from the seed table. If reuse is true the table is reused when all the seeds have been returned.
unsigned gxRandom::Seed(unsigned &a, unsigned &b, unsigned &c, unsigned &d)Public member function that returns a seed from the entropy function and passes back its four byte values in a, b, c and d.
void gxRandom::SeedTable(unsigned max_seeds = 256, unsigned long r_seed = 0)Public member function used to build a new seed table with max_seeds entries.
gxRandom::gxRandom(unsigned max_seeds = 256)Class constructor used to create a seed table with max_seeds entries.
gxRandom::~gxRandom()Class destructor responsible for freeing the seed table.
Example
See the examples_socket/ssl_server, https_client and ssl_verify_cert example programs for complete programs.
// Server side: accept a client and start TLS
gxSSL openssl;
openssl.MakeServer();
openssl.SetSSLProto(gxSSL_TLS);
openssl.SetCertFile("server_cert.pem");
openssl.SetKeyFile("server_private_key.pem");
if(!openssl.InitCTX()) {
cerr << openssl.SSLExceptionMessage() << "\n";
return 1;
}
openssl.LoadDHParms("dhparms.pem"); // Optional, enables DHE cipher suites
// remote_socket was accepted by a gxSocket server
if(openssl.OpenSSLSocket(remote_socket) != 0 ||
openssl.AcceptSSLSocket() != 0) {
cerr << openssl.SSLExceptionMessage() << "\n";
return 1;
}
char buf[255];
int bytes = openssl.RawReadSSLSocket(buf, sizeof(buf));
openssl.SendSSLSocket(buf, bytes); // Echo the data back
openssl.CloseSSLSocket();
// One time setup: make a key, a self-signed certificate and DH parameters
gxSSL keygen;
gxCertIssuerInfo ci;
ci.C = "US"; ci.ST = "MD"; ci.O = "Example"; ci.CN = "localhost";
ci.sn = 1; ci.days = 365;
keygen.MakeRSAPrivateKey("server_private_key.pem", 2048);
keygen.MakeCertReq("server_private_key.pem", ci, "server_cert.pem");
keygen.MakeDHParms("dhparms.pem"); // RFC 7919 ffdhe2048 group
10/14/2026 Changes
The gxSSL code was reviewed and fixed by Claude Code, Anthropic's AI coding assistant (https://claude.ai/code), for DataReel 5.10. Summary of the gxSSL changes:
- OpenSSL 3 interfaces for Diffie-Hellman parameters (OSSL_PARAM_BLD, EVP_PKEY_fromdata(), PEM_write_bio_Parameters(), PEM_read_bio_Parameters(), SSL_CTX_set0_tmp_dh_pkey()) and RSA keys (EVP_PKEY_CTX_new_from_name()). The OpenSSL 1.1 and older code paths are kept.
- MakeDHParms() writes the RFC 7919 ffdhe2048 group by default instead of a 1024-bit prime.
- LoadDHParms() reports errors setting the parameters and checks for a null context object.
- MakeRSAPrivateKey() seeds the random number generator first, generates the key before opening the key file and frees everything on every path.
- MakeRSAEphKey() does nothing with OpenSSL 1.1.0 and later.
- MakeCertReq(): fixed an undefined order of evaluation in the X509_new() call.
- Release() added; Relase() now clears all of the BIO pointers.
- The gxRandom tables are freed with delete[].
- The ssl_server example has a new 2048-bit key, certificate and DH parameter file.
See Code Review and Fixes for the full list of library changes.