When using ECIES to decrypt, cryptopp takes longer to calculate than Bouncy Castle

66 views
Skip to first unread message

苇杭

unread,
Jul 19, 2020, 10:27:43 PM7/19/20
to Crypto++ Users

I tested ecies decrypt api 10000 times, Cryptopp(c++) takes about 10s, Bouncy Castle(java) takes about 3s, eciespy(python) takes about 3s
I tested RSA decrypt api 10000 times, Cryptopp takes about 10s, Bouncy Castle takes about 10s

Does the decrypt api of ecies can be optimized?

Jeffrey Walton

unread,
Jul 20, 2020, 1:00:36 PM7/20/20
to Crypto++ Users List
Please show your code and how you compiled it.

苇杭

unread,
Jul 20, 2020, 10:14:45 PM7/20/20
to Crypto++ Users
g++ -I../cryptopp/cryptopp/output/include -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a

string sPublicKey = "3059301306072A8648CE3D020106082A8648CE3D03010703420004BD8E4960D48F8D0AE1FEEFB69F4E3ED1BAC125F88968C25BCDB19CFEF1A4423EFECDCF348EE59C0EF2AF01DF994951C96A3FBDBF26EC58CC90B003AF7D1522E9";

string sPrivateKey = "3041020100301306072A8648CE3D020106082A8648CE3D030107042730250201010420C9F3A236525B737E0FA48C8375D6379FCF0A26D367EEC5DFBBF330ADE501D0F6";
std::string cipherText;

StringSource pubString(sPublicKey, true, new HexDecoder);

string msgToEncrypt = "tests";
ECIES<ECP>::Encryptor encryptor(pubString);
size_t uiCipherTextSize = encryptor.CiphertextLength(msgToEncrypt.size());
cipherText.resize(uiCipherTextSize);
RandomPool rnds;
encryptor.Encrypt(rnds, (byte*)msgToEncrypt.c_str(), msgToEncrypt.size(), (byte*)cipherText.data());

std::string decryptText;
StringSource priString(sPrivateKey, true, new HexDecoder);
ECIES<ECP>::Decryptor decryptor(priString);

struct timeval tpstart,tpend;
float timeuse = 0;
int count = 10000;
gettimeofday(&tpstart,NULL);
while(count--){
size_t uiDecryptTextSize = decryptor.MaxPlaintextLength(cipherText.size());
decryptText.resize(uiDecryptTextSize);
RandomPool rndss;
decryptor.Decrypt(rndss, (byte*)cipherText.c_str(), cipherText.size(), (byte*)decryptText.data());
}
gettimeofday(&tpend,NULL);
timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;

printf("ecies used:%f ms\n", timeuse/1000);

在 2020年7月21日星期二 UTC+8上午1:00:36,Jeffrey Walton写道:

Jeffrey Walton

unread,
Jul 21, 2020, 12:50:00 AM7/21/20
to Crypto++ Users


On Monday, July 20, 2020 at 10:14:45 PM UTC-4, 苇杭 wrote:
g++ -I../cryptopp/cryptopp/output/include -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a

Use -O2 or -O3.

Jeff

苇杭

unread,
Jul 21, 2020, 9:11:12 AM7/21/20
to Crypto++ Users
g++ -I../cryptopp/cryptopp/output/include -O2 -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a
payload ecies  Used Time:9229.839844 ms

g++ -I../cryptopp/cryptopp/output/include -O3 -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a
payload ecies  Used Time:9365.958984 ms

g++ -I../cryptopp/cryptopp/output/include -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a
payload ecies  Used Time:9894.942383 ms


在 2020年7月21日星期二 UTC+8下午12:50:00,Jeffrey Walton写道:

Jeffrey Walton

unread,
Jul 21, 2020, 9:25:20 AM7/21/20
to Crypto++ Users List
On Tue, Jul 21, 2020 at 9:11 AM 苇杭 <ywhz1...@gmail.com> wrote:
>
> g++ -I../cryptopp/cryptopp/output/include -O2 -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a
> payload ecies Used Time:9229.839844 ms
>
> g++ -I../cryptopp/cryptopp/output/include -O3 -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a
> payload ecies Used Time:9365.958984 ms
>
> g++ -I../cryptopp/cryptopp/output/include -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a
> payload ecies Used Time:9894.942383 ms

How did you build the library?

Jeff

苇杭

unread,
Jul 22, 2020, 2:06:59 AM7/22/20
to Crypto++ Users
make static dynamic
make install PREFIX=output

在 2020年7月21日星期二 UTC+8下午9:25:20,Jeffrey Walton写道:
Reply all
Reply to author
Forward
0 new messages