title: OpenSSL handshake logic in code
body: <p>The code for SSL_do_handshake can be found at <a href="https://github.com/openssl/openssl" rel="nofollow">OpenSSL</a>/ssl/ssl_lib.c.
  The SSL_do_handshake function will wait for a TLS handshake to take place.
  I am not able to understand the logic for the implementation. If my understanding is correct, the <a href="http://www.ibm.com/support/knowledgecenter/SSFKSJ_7.1.0/com.ibm.mq.doc/sy10660_.htm" rel="nofollow">TLS handshake</a> consists of a few steps before a symmetric key is generated. Where can I find the various steps in code (sending client hello, etc) for the implementation of the SSL_do_handshake() function. Are these steps in different parts of the OpenSSL library. If so, how are they tracked/called in the do_handshake function ?</p>
  
  <p>Broader context:
  Software like apache/nginx uses OpenSSL in their code. I would like to replace the SSL_do_handshake() function used in the apache/nginx code with a modified handshake. For this I need to understand the logic for the implementation in OpenSSL. Note, that I am looking to replace the API call with my modified API call. I do not want to make changes to openssl and then recompile and use the modified OpenSSL library. The modified_handshake API should be able to replace the symmetric key generated at the end of the handshake with a user generated key.</p>