<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p><font size="2"><span style="font-size:10pt;"></p>
<div dir="ltr" ,="" style="text-align: left;">> The rsa_mod_exp function is only called for private key operations. You can't<br>
</div>
> tell if it is a private encrypt or a private decrypt though but that<br>
> shouldn't matter because the operation performed at that level is the same for<br>
</span></font><font size="2"><span style="font-size:10pt;">> both.</span></font><br>
<p></p>
<p>Ah, I see. So to clarify (pls correct me if I'm wrong):</p>
<ul style="margin-bottom: 0px; margin-top: 0px;">
<li>rsa_mod_exp() is the modular exponentiation function that openSSL will attempt to use for all private key operations (if
<span>RSA_FLAG_EXT_PKEY</span> is set, or the private parameters of that method are non-null), before defaulting to bn_mod_exp().
<br>
</li><li>And bn_mod_exp() is the modular exponentiation function used by all <span>public key
</span>operations</li></ul>
<p><br>
</p>
<p>So in my case, I should set RSA_FLAG_EX_PKEY in my engine's RSA_METHOD struct, and then implement my own versions of rsa_mod_exp (for the private key encryption/decryption), and bn_mod_exp (for the public key encryption/decryption).
<br>
</p>
<p><br>
</p>
<p>Brett<br>
</p>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> openssl-dev <openssl-dev-bounces@openssl.org> on behalf of Dr. Stephen Henson <steve@openssl.org><br>
<b>Sent:</b> Sunday, August 27, 2017 6:45 PM<br>
<b>To:</b> openssl-dev@openssl.org<br>
<b>Subject:</b> Re: [openssl-dev] confusion with rsa_meth_st in a custom RSA engine</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On Sun, Aug 27, 2017, Brett R. Nicholas wrote:<br>
<br>
> <br>
> This makes sense to me, and it seems that is the desired behavior. However,<br>
> if I *only* reimplement the rsa_mod_exp() function, and leave the<br>
> encrypt/decrypt functions to the default openSSL implementations, how can my<br>
> engine know which of the four of those functions called its rsa_mod_exp<br>
> function()? To put it another way: my accelerator will need to know whether<br>
> it is meant to perform public key or private key operations, since the<br>
> inputs will be written to different memory addresses. From within<br>
> rsa_mod_exp(), the only way I can think of determining whether the function<br>
> has been called by private_encrypt/decrypt() or public_encrypt/decrypt would<br>
> be to check if the  p and q fields of the RSA *rsa struct passed into the<br>
> function are NULL? But I can't tell from the source code if this will be<br>
> guaranteed just by having  RSA_FLAG_EXT_PKEY set in the "flags" field of my<br>
> engine's RSA_METHOD.<br>
> <br>
<br>
The rsa_mod_exp function is only called for private key operations. You can't<br>
tell if it is a private encrypt or a private decrypt though but that<br>
shouldn't matter because the operation performed at that level is the same for<br>
both.<br>
<br>
Steve.<br>
--<br>
Dr Stephen N. Henson. OpenSSL project core developer.<br>
Commercial tech support now available see: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.openssl.org&data=02%7C01%7Cbrett.r.nicholas.th%40dartmouth.edu%7C5374bb23132c4377080c08d4edb671de%7C995b093648d640e5a31ebf689ec9446f%7C0%7C0%7C636394815232517002&sdata=AdSj9Ys%2FG%2FQ1VJIIaD5kZhAwbki5mcF0AL8b2UBxic4%3D&reserved=0" id="LPlnk846310" previewremoved="true">
https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.openssl.org&data=02%7C01%7Cbrett.r.nicholas.th%40dartmouth.edu%7C5374bb23132c4377080c08d4edb671de%7C995b093648d640e5a31ebf689ec9446f%7C0%7C0%7C636394815232517002&sdata=AdSj9Ys%2FG%2FQ1VJIIaD5kZhAwbki5mcF0AL8b2UBxic4%3D&reserved=0</a><br>
-- <br>
openssl-dev mailing list<br>
To unsubscribe: <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmta.openssl.org%2Fmailman%2Flistinfo%2Fopenssl-dev&data=02%7C01%7Cbrett.r.nicholas.th%40dartmouth.edu%7C5374bb23132c4377080c08d4edb671de%7C995b093648d640e5a31ebf689ec9446f%7C0%7C0%7C636394815232517002&sdata=zzQB9AlLiORZC2btJ6zi1MZQxVzoB8pgWHTtAC8LHtM%3D&reserved=0" id="LPlnk438905" previewremoved="true">
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmta.openssl.org%2Fmailman%2Flistinfo%2Fopenssl-dev&data=02%7C01%7Cbrett.r.nicholas.th%40dartmouth.edu%7C5374bb23132c4377080c08d4edb671de%7C995b093648d640e5a31ebf689ec9446f%7C0%7C0%7C636394815232517002&sdata=zzQB9AlLiORZC2btJ6zi1MZQxVzoB8pgWHTtAC8LHtM%3D&reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>