<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle21
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head><body lang="EN-IN" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Hi Daniel,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">                Thanks we will try it out.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">One more doubt regarding  DH_generate_key, as per earlier suggestion we tried following changes to replicate the generate key, but we observe that the out put key is not matching with the one that
 is obtained by DH_generate_key() of older version. Note that the inputs are same in both scenario.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><u><span style="mso-fareast-language:EN-US">Inputs to both EVP version & DH_generate_key are same as below</span></u><span style="mso-fareast-language:EN-US">…<o:p></o:p></span></p>
<p class="MsoNormal"><u><span style="mso-fareast-language:EN-US">BIGNUM P input</span></u><span style="mso-fareast-language:EN-US">:  FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A4<o:p></o:p></span></p>
<p class="MsoNormal"><u><span style="mso-fareast-language:EN-US">BIGNUM G input</span></u><span style="mso-fareast-language:EN-US">: 2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">(Code suggested to replace DH_generate_key ) …………….<o:p></o:p></span></p>
<p class="MsoNormal">EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_from_name(NULL, "DH", NULL);<br>
OSSL_PARAM_BLD *tmpl = NULL;<br>
OSSL_PARAM *params = NULL;<br>
EVP_PKEY *param_key = NULL;<br>
<br>
if (pctx == NULL || !EVP_PKEY_key_fromdata_init(pctx))<br>
goto err;<br>
<br>
if ((tmpl = OSSL_PARAM_BLD_new()) == NULL<br>
|| !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, p)<br>
|| !OSSL_PARAM_BLD_push_uint(tmpl, OSSL_PKEY_PARAM_FFC_G, 2))<br>
goto err;<br>
<br>
params = OSSL_PARAM_BLD_to_param(tmpl);<br>
if (params == NULL || !EVP_PKEY_fromdata(pctx, &param_key, params))<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">EVP_PKEY *key = NULL;<br>
EVP_PKEY_CTX *gctx = EVP_PKEY_CTX_new_from_pkey(NULL, param_key, NULL);<br>
EVP_PKEY_keygen_init(gctx);<br>
EVP_PKEY_gen(gctx, &key);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="background:yellow;mso-highlight:yellow">Post this we obtained DH from the key and printed dh->p, dh->g, dh->priv, dh->pub using below API</span>
<o:p></o:p></p>
<p class="MsoNormal">dh = EVP_PKEY_get0_DH(pkey);<br>
DH_get0_key(dh, &dh_pubkey,&dh_privkey);<br>
<span style="mso-fareast-language:EN-US">DH_get0_pqg(dh, &dhp, &dhq, &dhg);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">BN_print_fp(dhfp, dh_pubkey);.. etc<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Note : post fetching DH from pkey, the input params (P,G) are matching properly. But pub/priv keys are not matching with the DH_generate_key output.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Please suggest.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Sunil<o:p></o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Sands, Daniel <dnsands@sandia.gov>
<br>
<b>Sent:</b> 16 December 2020 05:00<br>
<b>To:</b> Narayana, Sunil Kumar <sanarayana@rbbn.com>; openssl-users@openssl.org<br>
<b>Subject:</b> RE: [EXTERNAL] RE: DH_compute_key () - replacement in 3.0<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US">
<hr size="2" width="100%" align="center">
</span></div>
<p class="MsoNormal"><span lang="EN-US">NOTICE: This email was received from an EXTERNAL sender<o:p></o:p></span></p>
<div class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US">
<hr size="2" width="100%" align="center">
</span></div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt">We do have generated the key using EVP_PKEY_gen as suggested in earlier emails, but since this was a non-ephemeral and we wanted to store the key in "raw" octet bytes, so we did extracted the whole DH priv/pub
 key pair out from the key generated via  EVP_PKEY_gen  ( using as suggested… EVP_PKEY_get_raw_public_key (pkey, pub, &len)  )<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">Now, at a later stage in application we have to compute the Secret key using the stored key’s (in above step).<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">As of now,  these keys are in uchar format, but are converted to BIGNUM and given to DH_compute_key as below.<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">   BIGNUM      *<span style="background:yellow;mso-highlight:yellow">bn_publicKey</span>;<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">    <span style="background:aqua;mso-highlight:aqua">dh->priv_key</span> = BN_bin2bn(privateKey, octet_len, NULL);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">    <span style="background:yellow;mso-highlight:yellow">bn_publicKey</span> = BN_bin2bn(publicKey, octet_len, NULL);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">    rv = DH_compute_key(sharedSecret, bn_publicKey, dh);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">So in order to keep the existing frame work in place and just replace the DH_compute_key, we should be using the  dh->priv_key/ bn_publicKey  to compute shared secret key.<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">So we require to convert the BIGNUM key types to EVP_KEY types to use in EVP_PKEY_derive_init, EVP_PKEY_derive_set_peer, and EVP_PKEY_derive to get shared secret<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">Please suggest…<br>
<br>
<br>
<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">Is it possible to change the format of your raw blob?  If so, you can use i2d_PrivateKey or friends to output the entire private key to your raw data blob, and use d2i_PrivateKey et al to read it back into a working EVP_PKEY in a single
 call.<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">Otherwise, one shortcut you can do to avoid all the params work is to create a static array since you should already know how many params you need.  But you need the public key, the private key, the generator (g), and the prime modulus
 (p).  The following (untested) code ought to work.<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">OSSL_PARAM params[5];<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">params[0] = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_P, <prime modulus>, <prime modulus bytes size>);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">params[1] = OSSL_PARAM_construct_uint(OSSL_PKEY_PARAM_FFC_G, <generator>);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">params[2] = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_PUB_KEY, <public key>, <public key bytes size>);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">params[3] = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_PRIV_KEY, <private key>, <private key bytes size>);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">params[4] = OSSL_PARAM_construct_end();<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">my_key_ctx = EVP_PKEY_CTX_new_from_name(NULL, “DH”, NULL);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">EVP_PKEY_derive_init(my_key_ctx);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">EVP_PKEY_CTX_set_params(my_key_ctx, params);<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal">…<span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"> <span lang="EN-US"><o:p></o:p></span></p>
</div>


<br><br><span style="font-family:Arial; Font-size:8.0pt"> <hr> Notice: This e-mail together with any attachments may contain information of Ribbon Communications Inc. that is confidential and/or proprietary for the sole use of the intended recipient.  Any review, disclosure, reliance or distribution by others or forwarding without express permission is strictly prohibited.  If you are not the intended recipient, please notify the sender immediately and then delete all copies, including any attachments.<hr> </span></body></html>