title: Difference between EVP_PKEY_sign and EVP_DigestSignInit?
body: <p>So far I've seen two different approaches to RSA signing with OpenSSL:<br>
  With <strong>EVP_PKEY_sign</strong></p>
  
  <pre><code> ctx = EVP_PKEY_CTX_new(signing_key, NULL /* no engine */);
   if (!ctx)
       /* Error occurred */
   if (EVP_PKEY_sign_init(ctx) &lt;= 0)
       /* Error */
   if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) &lt;= 0)
       /* Error */
   if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) &lt;= 0)
       /* Error */
  
   /* Determine buffer length */
   if (EVP_PKEY_sign(ctx, NULL, &amp;siglen, md, mdlen) &lt;= 0)
  </code></pre>
  
  <p>With <strong>EVP_DigestSignInit</strong>:</p>
  
  <pre><code>if(1 != EVP_DigestSignInit(mdctx, NULL, EVP_sha256(), NULL, key)) 
            goto err;
  if(1 != EVP_DigestSignUpdate(mdctx, msg, strlen(msg))) 
            goto err;
  if(1 != EVP_DigestSignFinal(mdctx, NULL, slen)) 
            goto err;
  if(!(*sig = OPENSSL_malloc(sizeof(unsigned char) * (*slen)))) 
            goto err;
  if(1 != EVP_DigestSignFinal(mdctx, *sig, slen)) 
            goto err;
  </code></pre>
  
  <p>Are these just two different ways to do the same thing? </p>