<div dir="auto"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">در تاریخ چهارشنبه ۲۹ ژانویهٔ ۲۰۲۰،‏ ۰:۰۵ Viktor Dukhovni <<a href="mailto:openssl-users@dukhovni.org">openssl-users@dukhovni.org</a>> نوشت:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Jan 28, 2020 at 06:24:06PM +0000, Dan Heinz wrote:<br>
<br>
> >RSA is not intended for bulk data decryption, its intended uses are<br>
> >key transport and signing.  Bulk data decryption is done via AES or<br>
> >similar.<br>
<br>
It sounds like you're directly encrypting data with RSA.  That's a<br>
mistake.  RSA is for decrypting a symmetric algorithm key, that then<br>
decrypts the data.<br>
<br>
> >Are you sure that's seconds and not milliseconds?  These are absurdly<br>
> >long times, almost certainly dominated by factors other than the<br>
> >encryption algorithms.  On my 2015 laptop (MacOS) I get:<br>
> <br>
> Yes, it is seconds.  <br>
<br>
Sorry, 0.6 seconds for a single 1024-bit RSA_private_decrypt() (128<br>
bytes of data) is not plausible, but you say you have just over 8KB of<br>
data, which would take ~65 calls to RSA_private_decrypt() to decrypt<br>
piecewise.  It sure looks like you're measuring something other than<br>
what you claim to be measuring, or not describing it accurately.<br>
<br>
    OpenSSL 1.1.1c-dev  xx XXX xxxx<br>
    options:bn(64,64) rc4(16x,int) des(int) aes(partial) idea(int) blowfish(ptr)<br>
    compiler: cc -fPIC -arch x86_64 -g -O0 -Wall -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -D_REENTRANT<br>
                      sign    verify    sign/s verify/s<br>
    rsa 1024 bits 0.000135s 0.000013s   7414.8  78566.9<br>
<br>
On my laptop RSA_private_decrypt (aka sign) takes 135 microseconds.  You<br>
claim 600 milliseconds for perhaps ~60 calls, which might be 10ms each,<br>
but that still is about two orders of magnitude too slow.<br>
<br>
So, sorry whatever you're measuring, it is not the performance of<br>
RSA_private_decrypt().<br>
<br>
> While I'm ok with the execution speed with OpenSSL 1.0.2, I'd like to<br>
> figure out why the times doubled with OpenSSL 1.1.1.  <br>
<br>
Neither is a reasonable performance level, but also it is not reasonable<br>
to use RSA for bulk data encryption.<br>
<br>
> I'm logging times before and after the calls to RSA_private_decrypt.<br>
<br>
How many calls?  What else is happening to feed the data into the<br>
decryption algorithm, and reassemble the output?<br>
<br>
> With OpenSSL 1.0.2 it takes on average about 4-8 milliseconds for each<br>
> RSA_private_decrypt call.  With OpenSSL 1.1.1d, it takes 10-15<br>
> milliseconds for each RSA_private_decrypt call.<br>
<br>
Now we see that you're in fact chunking data for multiple calls to<br>
"decrypt" via RSA.  That's a fatal design flaw. This is not a valid<br>
operating mode for RSA.  You MUST NOT do this.<br>
<br>
> >> I'm wondering if perhaps my build configuration is incorrect or <br>
> >> missing something for the 1.1.1d build.  Here are the configuration <br>
> >> parameters for the 64-bit build:<br>
<br>
You have a deeper problem, your use of RSA is broken.<br>
<br>
> The data being decrypted is local on the client machine and is just an XML file. <br>
> RSA key is 1024 bits.  <br>
> I'm using OAEP padding.<br>
<br>
This is a mistake, for asymmetric encryption you should be using CMS.<br>
<br>
> Thank you for the information.  I removed it from the configuration<br>
> parameters.  I didn't really notice a difference in execution time<br>
> though.  I also removed the no-asm parameter, setup nasm, and rebuilt<br>
> with no noticeable changes.  <br>
<br>
Likely the time is dominated by something other than the RSA operations,<br>
but since those are mistake anyway, it hardly matters.<br>
<br>
> > I logged things granular enough to see the speed difference was in <br>
> > RSA_private_decrypt, but I'm not sure why it is so much slower with <br>
> > 1.1.1d.  Any help or ideas would be appreciated!<br>
<br>
STOP.  Fix your design to use CMS.  Report any performance differences<br>
in CMS between 1.0.2 and 1.1.1 when built correctly with asm support.<br>
<br>
> >At 600ms for 8KB, it is not plausible that the time is spend doing<br>
> >cryptography.  That's barely fast enough to feed a 1980's modem.<br>
> <br>
> I would expect the execution times to be more in line with what I saw<br>
> with Linux for both 1.0.2 and 1.1.1.  But even so, I do not understand<br>
> why just upgrading to 1.1.1 causes the RSA_private_decrypt calls to<br>
> double in execution time from what they were with 1.0.2?<br>
<br>
I would expect execution times that are 2 to 3 orders of magnitude<br>
faster, especially if you were using sound cryptographic primitives.<br>
<br>
-- <br>
    Viktor.<br>
</blockquote></div>