<div dir="ltr">Hi Matt,<div><br></div><div>Thank you for the inputs.</div><div>Yes, we had encountered the padding issue initially. But we added support for RSA_NO_PADDING in our hardware. That's why we are able to successfully decrypt the premaster secret in the hardware.</div><div>Hence the issue does not seem to be related to padding. We have confirmed this by comparing the premaster secret on both client and server and they are the same.</div><div><br></div><div>We suspect in this case, verification of "encrypted handshake message" failure is happening. </div><div>We understand constant_time_xx APIs get used for CBC padding validation. Will this have  any dependency on the compiler optimization or asm flags? Will this issue be seen if hardware takes more time for the operation?</div><div><br></div><div>Here is the snippet of the wireshark where our device acting as server closes the connection with decryption failure.</div><div>If you need any further info, please let us know. </div><div><div><img src="cid:ii_kgw5v8a90" alt="image.png" width="474" height="177"><br></div></div><div>Thanks</div><div>Mahendra</div><div><br></div><div>Please suggest.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 30, 2020 at 3:32 PM Matt Caswell <<a href="mailto:matt@openssl.org">matt@openssl.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 30/10/2020 09:18, Mahendra SP wrote:<br>
> Hi All.<br>
> <br>
> We have upgraded openssl version to 1.1.1b<br>
> <br>
> With this, we are seeing decryption error during SSL handshake for the<br>
> below explained scenario. Our device acts as an SSL server.<br>
> <br>
> We have external hardware to offload RSA private key operations using<br>
> the engine.<br>
> Decryption of pre-master secret is done using hardware and is<br>
> successful. We compared the pre-master secret on both server and client<br>
> and they match.<br>
> However, we see that SSL handshake fails with "decrypt error (51)" with<br>
> an alert number 21. Verifying the encrypted finish message on the server<br>
> side fails.<br>
> <br>
> This issue does not happen with software performing RSA private key<br>
> operations.<br>
> <br>
> Can someone help with the reason for decryption failure? Below is the<br>
> compiler and processor details. It is 64 bit.<br>
> arm-linux-gnueabihf-gcc  -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard<br>
<br>
Potentially this is related to the use of PSS padding in libssl which is<br>
mandated in TLSv1.3. The TLSv1.3 spec also requires its use even in TLSv1.2.<br>
<br>
The PSS padding is implemented within the EVP layer. Ultimately EVP<br>
calls the function RSA_private_encrypt() with padding set to RSA_NO_PADDING.<br>
<br>
Assuming your engine is implemented via a custom RSA_METHOD does it<br>
support RSA_private_encrypt(() with RSA_NO_PADDING? If not this is<br>
likely to be the problem.<br>
<br>
More discussion of this is here:<br>
<br>
<a href="https://github.com/openssl/openssl/issues/7968" rel="noreferrer" target="_blank">https://github.com/openssl/openssl/issues/7968</a><br>
<br>
Also related is the recent discussion on this list about the CAPI engine<br>
and this issue:<br>
<br>
<a href="https://github.com/openssl/openssl/issues/8872" rel="noreferrer" target="_blank">https://github.com/openssl/openssl/issues/8872</a><br>
<br>
Matt<br>
</blockquote></div>