[DEBUG] Error string : error:00000005:lib(0):func(0):DH lib
The error happened during the Diffie-Hellman Key Exchange, e.g. where the peers tried to generate the keys for the connection. There might be several reasons for this, like invalid DH parameters given on the server side. With the your current code it is hard to see where the error actually is, but I guess is somewhere in setting up your ctx, so maybe should show the relevant parts of the code.