Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-11-04 Thread Arik Agazarian
We Need wallet address of 7 months for clean transactions, traceable on
Blockchain,
Ratio 45%/45%/10%
Sender/Reciever/Mandate
Telegram sender: @Arik_loader


On Thu, Nov 2, 2023, 7:25 PM Catherine Issabel 
wrote:

>
> $500 million dollars available only for good and trusted receiver or
> mandate
> Kindly contact the sender for more information:+1 (336) 345-9681
> On Friday, May 12, 2023 at 7:09:38 PM UTC+1 Jeffrey Walton wrote:
>
>> On Fri, May 12, 2023 at 1:09 PM Dwight Kulkarni 
>> wrote:
>> >
>> > Update: It seems to be an issue with CFB mode. If I switch to ECB: 12
>> ms to process the workload.
>> >
>> > in encrypt aes
>> > Encrypted 1at: 05/12/2023 17:06:54.838
>> > Encrypted 2at: 05/12/2023 17:06:54.838
>> > Encrypted 3at: 05/12/2023 17:06:54.838
>> > returning cipher
>> > Encrypted 4at: 05/12/2023 17:06:54.850
>>
>> Yeah, CFB mode is a hard mode in software. The software is effectively
>> providing a linear feedback shift register, and it does a lot of
>> [non-accelerated] bit twiddling. That's why it needs 4+ cycles to
>> process a byte.
>>
>> I think you would have better results with GCM mode. First, GCM mode
>> is an authenticated encryption mode, so you get authenticity
>> assurances over the ciphertext. Second, you get hardware acceleration
>> with both the bulk cipher encryption (AES), and the mac over the
>> ciphertext (GMAC).
>>
>> Also see https://www.cryptopp.com/wiki/Authenticated_Encryption .
>>
>> Jeff
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Crypto++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cryptopp-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/cryptopp-users/3bd37ee9-859d-41f2-841a-9b5cf32e14dcn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CAOLESwm4LQH9Ru%3Dc6Q21-k3hz2QTf4Bt9ajBiE09hiHVx6Ob_A%40mail.gmail.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-11-02 Thread Catherine Issabel

$500 million dollars available only for good and trusted receiver or 
mandate 
Kindly contact the sender for more information:+1 (336) 345-9681
On Friday, May 12, 2023 at 7:09:38 PM UTC+1 Jeffrey Walton wrote:

> On Fri, May 12, 2023 at 1:09 PM Dwight Kulkarni  
> wrote:
> >
> > Update: It seems to be an issue with CFB mode. If I switch to ECB: 12 ms 
> to process the workload.
> >
> > in encrypt aes
> > Encrypted 1at: 05/12/2023 17:06:54.838
> > Encrypted 2at: 05/12/2023 17:06:54.838
> > Encrypted 3at: 05/12/2023 17:06:54.838
> > returning cipher
> > Encrypted 4at: 05/12/2023 17:06:54.850
>
> Yeah, CFB mode is a hard mode in software. The software is effectively
> providing a linear feedback shift register, and it does a lot of
> [non-accelerated] bit twiddling. That's why it needs 4+ cycles to
> process a byte.
>
> I think you would have better results with GCM mode. First, GCM mode
> is an authenticated encryption mode, so you get authenticity
> assurances over the ciphertext. Second, you get hardware acceleration
> with both the bulk cipher encryption (AES), and the mac over the
> ciphertext (GMAC).
>
> Also see https://www.cryptopp.com/wiki/Authenticated_Encryption .
>
> Jeff
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/3bd37ee9-859d-41f2-841a-9b5cf32e14dcn%40googlegroups.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Jeffrey Walton
On Fri, May 12, 2023 at 1:09 PM Dwight Kulkarni  wrote:
>
> Update: It seems to be an issue with CFB mode. If I switch to ECB: 12 ms to 
> process the workload.
>
>  in encrypt aes
>  Encrypted 1at: 05/12/2023 17:06:54.838
>  Encrypted 2at: 05/12/2023 17:06:54.838
>  Encrypted 3at: 05/12/2023 17:06:54.838
>  returning cipher
>  Encrypted 4at: 05/12/2023 17:06:54.850

Yeah, CFB mode is a hard mode in software. The software is effectively
providing a linear feedback shift register, and it does a lot of
[non-accelerated] bit twiddling. That's why it needs 4+ cycles to
process a byte.

I think you would have better results with GCM mode. First, GCM mode
is an authenticated encryption mode, so you get authenticity
assurances over the ciphertext. Second, you get hardware acceleration
with both the bulk cipher encryption (AES), and the mac over the
ciphertext (GMAC).

Also see https://www.cryptopp.com/wiki/Authenticated_Encryption .

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8n5na5bkfkM6fUJ2cRfwpEBvxFquPMidsm4_GPVsaidAg%40mail.gmail.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
*Update: It seems to be an issue with CFB mode. If I switch to ECB: 12 ms 
to process the workload.*

 in encrypt aes 
 Encrypted 1at: 05/12/2023 17:06:54.838
 Encrypted 2at: 05/12/2023 17:06:54.838
 Encrypted 3at: 05/12/2023 17:06:54.838
 returning cipher 
 Encrypted 4at: 05/12/2023 17:06:54.850

std::string encrypt_aes(std::string message, SecByteBlock key, SecByteBlock 
iv) {
try {
cout <<" in encrypt aes " <::Encryption e;
std::string cipher;
cipher.reserve(message.size()+16); 
e.SetKey(key, key.size(), params);
cout << " Encrypted 3at: " << get_curr_datetime_str() << endl;

/*
const size_t buf_sz = 32;
byte buffer[buf_sz];
StringSink ssk(cipher);
ArraySource ars((const byte*)message.data(), message.size(), true, new 
StreamTransformationFilter(e, new ArraySink(buffer,buf_sz)));
while(true){
size_t bread = ars.Get(buffer, buf_sz);
if(bread==0){
break;
}
ssk.Put(buffer,bread);
}
ssk.MessageEnd();
*/
StringSource ss(message, true, new StreamTransformationFilter(e, new 
StringSink(cipher)));
cout << " returning cipher " << endl;
cout << " Encrypted 4at: " << get_curr_datetime_str() << endl;
return cipher;
}
catch (CryptoPP::Exception e) {
std::cerr << e.what() << std::endl;
return "";
}
}

On Friday, May 12, 2023 at 11:46:08 AM UTC-4 Dwight Kulkarni wrote:

> Hi Jeff,
>
> The time is taken up all on the one line:
>
>
> StringSource ss(message, true, new StreamTransformationFilter(e, new 
> StringSink(cipher)));
>
>
> *Do you know what might be the difference versus the .exe test ?
> AES/CFB (128-bit key)ARMv83444.991.1352044*
>
>
>
> Encrypted 1at: 05/12/2023 15:40:55.588
>  Encrypted 2at: 05/12/2023 15:40:55.588
>  Encrypted 3at: 05/12/2023 15:40:55.588
> returning cipher 
>  Encrypted 4at: 05/12/2023 15:40:56.599
>  Encrypted at: 05/12/2023 15:40:56.600
>
>
> std::string encrypt_aes(std::string message, SecByteBlock key, 
> SecByteBlock iv) {
> try {
> cout <<" in encrypt aes " < cout << " Encrypted 1at: " << get_curr_datetime_str() << endl;
> AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 1
> /*8-bits*/)
> (Name::IV(), ConstByteArrayParameter(iv));
> cout << " Encrypted 2at: " << get_curr_datetime_str() << endl;
> CFB_Mode::Encryption e;
> std::string cipher;
> cipher.reserve(message.size()+16); 
> e.SetKey(key, key.size(), params);
> cout << " Encrypted 3at: " << get_curr_datetime_str() << endl;
> StringSource ss(message, true, new StreamTransformationFilter(e, new 
> StringSink(cipher)));
> cout << " returning cipher " << endl;
> cout << " Encrypted 4at: " << get_curr_datetime_str() << endl;
> return cipher;
> }
> catch (CryptoPP::Exception e) {
> std::cerr << e.what() << std::endl;
> return "";
> }
> }
> On Friday, May 12, 2023 at 11:17:32 AM UTC-4 Jeffrey Walton wrote:
>
>> On Fri, May 12, 2023 at 10:48 AM Dwight Kulkarni  
>> wrote: 
>> > 
>> > The new library is much faster, but I am still not getting that speed 
>> in the code. 1 second to encrypt 5 mb versus 3 seconds before. 
>> > 
>> > I added the .reserve(...) code also. 
>>
>> Well, you should profile your code to find the bottlenecks. 
>>
>> Jeff 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/d68e5954-8844-47ae-ab5d-843dd12f8938n%40googlegroups.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
BTW,

Are there any flags I should be setting when compiling the .a library into 
my .exe to set the ARM acceleration ?

This is the makefile output:


*aarch64-poky-linux-g++  -mcpu=cortex-a53 -march=armv8-a+crc+crypto 
-fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat 
-Wformat-security -Werror=format-security 
--sysroot=/opt/fsl-imx-xwayland/5.10-hardknott/sysroots/cortexa53-crypto-poky-linux
 
-o cryptest.exe -O2 -pipe -g -feliminate-unused-debug-types 
-DCRYPTOPP_ARM_ACLE_AVAILABLE=0 -DCRYPTOPP_DISABLE_ASM -fPIC -pthread -pipe 
adhoc.o test.o bench1.o bench2.o bench3.o datatest.o dlltest.o fipsalgt.o 
validat0.o validat1.o validat2.o validat3.o validat4.o validat5.o 
validat6.o validat7.o validat8.o validat9.o validat10.o regtest1.o 
regtest2.o regtest3.o regtest4.o ./libcryptopp.a -Wl,-O1 
-Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now *

should I be setting for example:

 
* -mcpu=cortex-a53 -march=armv8-a+crc+crypto*

I use the following for compiling the files:

"-g",
"-c",
"-pthread",

//Add this ???
"-mcpu=cortex-a53",
"-march=armv8-a+crc+crypto" 
//


Right now I use the following for building the executable:

"-g",
"-pthread",

//Add this ???
"-mcpu=cortex-a53",
"-march=armv8-a+crc+crypto" 
//

"-L${workspaceFolder}/external-libs/lib/",
"-l:libcryptopp.a"

On Friday, May 12, 2023 at 11:46:08 AM UTC-4 Dwight Kulkarni wrote:

> Hi Jeff,
>
> The time is taken up all on the one line:
>
>
> StringSource ss(message, true, new StreamTransformationFilter(e, new 
> StringSink(cipher)));
>
>
> *Do you know what might be the difference versus the .exe test ?
> AES/CFB (128-bit key)ARMv83444.991.1352044*
>
>
>
> Encrypted 1at: 05/12/2023 15:40:55.588
>  Encrypted 2at: 05/12/2023 15:40:55.588
>  Encrypted 3at: 05/12/2023 15:40:55.588
> returning cipher 
>  Encrypted 4at: 05/12/2023 15:40:56.599
>  Encrypted at: 05/12/2023 15:40:56.600
>
>
> std::string encrypt_aes(std::string message, SecByteBlock key, 
> SecByteBlock iv) {
> try {
> cout <<" in encrypt aes " < cout << " Encrypted 1at: " << get_curr_datetime_str() << endl;
> AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 1
> /*8-bits*/)
> (Name::IV(), ConstByteArrayParameter(iv));
> cout << " Encrypted 2at: " << get_curr_datetime_str() << endl;
> CFB_Mode::Encryption e;
> std::string cipher;
> cipher.reserve(message.size()+16); 
> e.SetKey(key, key.size(), params);
> cout << " Encrypted 3at: " << get_curr_datetime_str() << endl;
> StringSource ss(message, true, new StreamTransformationFilter(e, new 
> StringSink(cipher)));
> cout << " returning cipher " << endl;
> cout << " Encrypted 4at: " << get_curr_datetime_str() << endl;
> return cipher;
> }
> catch (CryptoPP::Exception e) {
> std::cerr << e.what() << std::endl;
> return "";
> }
> }
> On Friday, May 12, 2023 at 11:17:32 AM UTC-4 Jeffrey Walton wrote:
>
>> On Fri, May 12, 2023 at 10:48 AM Dwight Kulkarni  
>> wrote: 
>> > 
>> > The new library is much faster, but I am still not getting that speed 
>> in the code. 1 second to encrypt 5 mb versus 3 seconds before. 
>> > 
>> > I added the .reserve(...) code also. 
>>
>> Well, you should profile your code to find the bottlenecks. 
>>
>> Jeff 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/f83b8164-8d60-4bd3-aa68-ba350cbda0e3n%40googlegroups.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
Hi Jeff,

The time is taken up all on the one line:


StringSource ss(message, true, new StreamTransformationFilter(e, new 
StringSink(cipher)));


*Do you know what might be the difference versus the .exe test ?
AES/CFB (128-bit key)ARMv83444.991.1352044*



Encrypted 1at: 05/12/2023 15:40:55.588
 Encrypted 2at: 05/12/2023 15:40:55.588
 Encrypted 3at: 05/12/2023 15:40:55.588
returning cipher 
 Encrypted 4at: 05/12/2023 15:40:56.599
 Encrypted at: 05/12/2023 15:40:56.600


std::string encrypt_aes(std::string message, SecByteBlock key, SecByteBlock 
iv) {
try {
cout <<" in encrypt aes " <::Encryption e;
std::string cipher;
cipher.reserve(message.size()+16); 
e.SetKey(key, key.size(), params);
cout << " Encrypted 3at: " << get_curr_datetime_str() << endl;
StringSource ss(message, true, new StreamTransformationFilter(e, new 
StringSink(cipher)));
cout << " returning cipher " << endl;
cout << " Encrypted 4at: " << get_curr_datetime_str() << endl;
return cipher;
}
catch (CryptoPP::Exception e) {
std::cerr << e.what() << std::endl;
return "";
}
}
On Friday, May 12, 2023 at 11:17:32 AM UTC-4 Jeffrey Walton wrote:

> On Fri, May 12, 2023 at 10:48 AM Dwight Kulkarni  
> wrote:
> >
> > The new library is much faster, but I am still not getting that speed in 
> the code. 1 second to encrypt 5 mb versus 3 seconds before.
> >
> > I added the .reserve(...) code also.
>
> Well, you should profile your code to find the bottlenecks.
>
> Jeff
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/e51a4bd3-8196-4ac4-8a95-1e8dd58fa5fcn%40googlegroups.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Jeffrey Walton
On Fri, May 12, 2023 at 10:48 AM Dwight Kulkarni  wrote:
>
> The new library is much faster, but I am still not getting that speed in the 
> code. 1 second to encrypt 5 mb versus 3 seconds before.
>
> I added the .reserve(...) code also.

Well, you should profile your code to find the bottlenecks.

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8m1Ef-ArOZYX2JBwzkQ0bXLP3F3RO%3Ddj03760V%3DKvYJ-g%40mail.gmail.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
Two others:


string get_curr_datetime_str(){
return datetime_to_str(chrono::system_clock::now());

}

string datetime_to_str(std::chrono::high_resolution_clock::time_point 
utctime){ 
std::chrono::high_resolution_clock::time_point::duration tt = utctime.
time_since_epoch();
const time_t durs = std::chrono::duration_cast(tt).
count();
std::ostringstream ss;
string format = "%m/%d/%Y %H:%M:%S";
if (const std::tm *tm = std::gmtime()){
ss << std::put_time(tm,format.c_str());
const long long durms = std::chrono::duration_cast(tt).count();
ss << "." << std::setw(3) << std::setfill('0') << int(durms - durs * 1000);
return ss.str();
}else{
return "";
}
}

On Friday, May 12, 2023 at 10:50:38 AM UTC-4 Dwight Kulkarni wrote:

> I didn't give the load_aes_key functionhere it is :
>
>
>
> std::pair load_aes_key_from_b64_str(string bkey, 
> string biv){
>
> SecByteBlock key;
> SecByteBlock iv;
> try {
> AutoSeededRandomPool prng;
> key = SecByteBlock(udp_aes_key_size_in_bytes);
> iv = SecByteBlock(udp_aes_key_iv_in_bytes);
>
> //prng.GenerateBlock(key.data(), key.size());
> //prng.GenerateBlock(iv.data(), iv.size());
> bkey = b64decode(bkey);
> biv = b64decode(biv);
>
> ArraySink sk(key.data(), key.size());
> sk.ChannelPut(DEFAULT_CHANNEL, reinterpret_cast(bkey.c_str
> ()),key.size());
>
> ArraySink siv(iv.data(), iv.size());
> siv.ChannelPut(DEFAULT_CHANNEL, reinterpret_cast(biv.c_str
> ()),iv.size());
>
> //CryptoPP::GenerateIntoBufferedTransformation(s, DEFAULT_CHANNEL, size);
> // key.data() = reinterpret_cast(const_cast(nkey.c_str()));
> //iv.data() = reinterpret_cast(const_cast(niv.c_str()));
> std::cout << "Loaded blocks with key size " << int(key.size()) << " and 
> iv " << int(iv.size()) << endl;
>
> return std::make_pair(key,iv);
>
> }
>
> catch (CryptoPP::Exception e) {
> std::cerr << e.what() << std::endl;
> return std::make_pair(key,iv);
> }
>
> }
>
> On Friday, May 12, 2023 at 10:48:42 AM UTC-4 Dwight Kulkarni wrote:
>
>> Hi Jeff,
>>
>> The new library is much faster, but I am still not getting that speed in 
>> the code. 1 second to encrypt 5 mb versus 3 seconds before.
>>
>>
>> *I added the .reserve(...) code also.*
>>
>>
>>
>>  Start at: 05/12/2023 14:46:39.358
>>  Start Encrypted at: 05/12/2023 14:46:39.607
>>  in encrypt aes 
>>  returning cipher 
>>  Encrypted at: 05/12/2023 14:46:40.626
>>
>>
>> string bkey1 = "cX/8AascXHJz6Anr02GHZg==";
>> string biv2 = "WdHMzK+OrQOTjxZ8cAXQ6g==";
>> std::pair akeys = 
>> load_aes_key_from_b64_str(bkey1, 
>> biv2);
>> cout << " Start at: " << get_curr_datetime_str() << endl;
>>
>> const int num_bytes = 503;
>> std::random_device rd;
>> std::mt19937 gen(rd());
>> std::uniform_int_distribution dist(0,255);
>> std::string random_string;
>> random_string.reserve(num_bytes);
>> for(int i=0; i> random_string += static_cast(dist(gen));
>> }
>>
>> cout << " Start Encrypted at: " << get_curr_datetime_str() << endl;
>> string message_bytes = encrypt_aes(random_string, akeys.first, akeys.
>> second);
>> cout << " Encrypted at: " << get_curr_datetime_str() << endl;
>>
>>
>>
>> std::string encrypt_aes(std::string message, SecByteBlock key, 
>> SecByteBlock iv) {
>> try {
>> cout <<" in encrypt aes " <> AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 1
>> /*8-bits*/)
>> (Name::IV(), ConstByteArrayParameter(iv));
>> CFB_Mode::Encryption e;
>> std::string cipher;
>> cipher.reserve(message.size()+16); 
>> e.SetKey(key, key.size(), params);
>> StringSource ss(message, true, new StreamTransformationFilter(e, new 
>> StringSink(cipher)));
>> cout << " returning cipher " << endl;
>> return cipher;
>> }
>> catch (CryptoPP::Exception e) {
>> std::cerr << e.what() << std::endl;
>> return "";
>> }
>> }
>>
>>
>>
>> On Friday, May 12, 2023 at 10:40:10 AM UTC-4 Jeffrey Walton wrote:
>>
>>> On Fri, May 12, 2023 at 10:27 AM Dwight Kulkarni  
>>> wrote: 
>>> > 
>>> > These are the results from CryptoPP 8.7 vs 8.1 earlier: 
>>> > [...] 
>>> > AES/CFB (128-bit key)ARMv83444.991.1352044 
>>> > [...] 
>>>
>>> 5 MB / 344 MB/s = 0.01453 s = 14/53 ms. That is below 200 ms. 
>>>
>>> Jeff 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/22b58042-13b1-4b3d-a941-d33acdfa1031n%40googlegroups.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
I didn't give the load_aes_key functionhere it is :



std::pair load_aes_key_from_b64_str(string bkey, 
string biv){

SecByteBlock key;
SecByteBlock iv;
try {
AutoSeededRandomPool prng;
key = SecByteBlock(udp_aes_key_size_in_bytes);
iv = SecByteBlock(udp_aes_key_iv_in_bytes);

//prng.GenerateBlock(key.data(), key.size());
//prng.GenerateBlock(iv.data(), iv.size());
bkey = b64decode(bkey);
biv = b64decode(biv);

ArraySink sk(key.data(), key.size());
sk.ChannelPut(DEFAULT_CHANNEL, reinterpret_cast(bkey.c_str()),
key.size());

ArraySink siv(iv.data(), iv.size());
siv.ChannelPut(DEFAULT_CHANNEL, reinterpret_cast(biv.c_str()),
iv.size());

//CryptoPP::GenerateIntoBufferedTransformation(s, DEFAULT_CHANNEL, size);
// key.data() = reinterpret_cast(const_cast(nkey.c_str()));
//iv.data() = reinterpret_cast(const_cast(niv.c_str()));
std::cout << "Loaded blocks with key size " << int(key.size()) << " and iv " 
<< int(iv.size()) << endl;

return std::make_pair(key,iv);

}

catch (CryptoPP::Exception e) {
std::cerr << e.what() << std::endl;
return std::make_pair(key,iv);
}

}

On Friday, May 12, 2023 at 10:48:42 AM UTC-4 Dwight Kulkarni wrote:

> Hi Jeff,
>
> The new library is much faster, but I am still not getting that speed in 
> the code. 1 second to encrypt 5 mb versus 3 seconds before.
>
>
> *I added the .reserve(...) code also.*
>
>
>
>  Start at: 05/12/2023 14:46:39.358
>  Start Encrypted at: 05/12/2023 14:46:39.607
>  in encrypt aes 
>  returning cipher 
>  Encrypted at: 05/12/2023 14:46:40.626
>
>
> string bkey1 = "cX/8AascXHJz6Anr02GHZg==";
> string biv2 = "WdHMzK+OrQOTjxZ8cAXQ6g==";
> std::pair akeys = load_aes_key_from_b64_str(bkey1, 
> biv2);
> cout << " Start at: " << get_curr_datetime_str() << endl;
>
> const int num_bytes = 503;
> std::random_device rd;
> std::mt19937 gen(rd());
> std::uniform_int_distribution dist(0,255);
> std::string random_string;
> random_string.reserve(num_bytes);
> for(int i=0; i random_string += static_cast(dist(gen));
> }
>
> cout << " Start Encrypted at: " << get_curr_datetime_str() << endl;
> string message_bytes = encrypt_aes(random_string, akeys.first, akeys.
> second);
> cout << " Encrypted at: " << get_curr_datetime_str() << endl;
>
>
>
> std::string encrypt_aes(std::string message, SecByteBlock key, 
> SecByteBlock iv) {
> try {
> cout <<" in encrypt aes " < AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 1
> /*8-bits*/)
> (Name::IV(), ConstByteArrayParameter(iv));
> CFB_Mode::Encryption e;
> std::string cipher;
> cipher.reserve(message.size()+16); 
> e.SetKey(key, key.size(), params);
> StringSource ss(message, true, new StreamTransformationFilter(e, new 
> StringSink(cipher)));
> cout << " returning cipher " << endl;
> return cipher;
> }
> catch (CryptoPP::Exception e) {
> std::cerr << e.what() << std::endl;
> return "";
> }
> }
>
>
>
> On Friday, May 12, 2023 at 10:40:10 AM UTC-4 Jeffrey Walton wrote:
>
>> On Fri, May 12, 2023 at 10:27 AM Dwight Kulkarni  
>> wrote: 
>> > 
>> > These are the results from CryptoPP 8.7 vs 8.1 earlier: 
>> > [...] 
>> > AES/CFB (128-bit key)ARMv83444.991.1352044 
>> > [...] 
>>
>> 5 MB / 344 MB/s = 0.01453 s = 14/53 ms. That is below 200 ms. 
>>
>> Jeff 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/e8206090-f369-43d0-a5c6-7d3661211252n%40googlegroups.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
Hi Jeff,

The new library is much faster, but I am still not getting that speed in 
the code. 1 second to encrypt 5 mb versus 3 seconds before.


*I added the .reserve(...) code also.*



 Start at: 05/12/2023 14:46:39.358
 Start Encrypted at: 05/12/2023 14:46:39.607
 in encrypt aes 
 returning cipher 
 Encrypted at: 05/12/2023 14:46:40.626


string bkey1 = "cX/8AascXHJz6Anr02GHZg==";
string biv2 = "WdHMzK+OrQOTjxZ8cAXQ6g==";
std::pair akeys = load_aes_key_from_b64_str(bkey1, 
biv2);
cout << " Start at: " << get_curr_datetime_str() << endl;

const int num_bytes = 503;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution dist(0,255);
std::string random_string;
random_string.reserve(num_bytes);
for(int i=0; i(dist(gen));
}

cout << " Start Encrypted at: " << get_curr_datetime_str() << endl;
string message_bytes = encrypt_aes(random_string, akeys.first, akeys.second
);
cout << " Encrypted at: " << get_curr_datetime_str() << endl;



std::string encrypt_aes(std::string message, SecByteBlock key, SecByteBlock 
iv) {
try {
cout <<" in encrypt aes " <::Encryption e;
std::string cipher;
cipher.reserve(message.size()+16); 
e.SetKey(key, key.size(), params);
StringSource ss(message, true, new StreamTransformationFilter(e, new 
StringSink(cipher)));
cout << " returning cipher " << endl;
return cipher;
}
catch (CryptoPP::Exception e) {
std::cerr << e.what() << std::endl;
return "";
}
}





On Friday, May 12, 2023 at 10:40:10 AM UTC-4 Jeffrey Walton wrote:

> On Fri, May 12, 2023 at 10:27 AM Dwight Kulkarni  
> wrote:
> >
> > These are the results from CryptoPP 8.7 vs 8.1 earlier:
> > [...]
> > AES/CFB (128-bit key)ARMv83444.991.1352044
> > [...]
>
> 5 MB / 344 MB/s = 0.01453 s = 14/53 ms. That is below 200 ms.
>
> Jeff
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/61cf4a2f-56b3-4328-903f-96015e6441e6n%40googlegroups.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Jeffrey Walton
On Fri, May 12, 2023 at 10:27 AM Dwight Kulkarni  wrote:
>
> These are the results from CryptoPP 8.7 vs 8.1 earlier:
> [...]
> AES/CFB (128-bit key)ARMv83444.991.1352044
>  [...]

5 MB / 344 MB/s = 0.01453 s = 14/53 ms. That is below 200 ms.

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8%3DbjyKQXXarBk%3D6qSr2nrV1%2BgNNkJt-0c%3DbyfRy8wfXHg%40mail.gmail.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
*These are the results from CryptoPP 8.7 vs 8.1 earlier:*


root@imx8mpevk:~/p2p_sockets# ./cryptest.exe b 2 1.8




Speed Comparison of Popular Crypto Algorithms

  table {border-collapse: collapse;}
  table, th, td, tr {border: 1px solid black;}



http://www.cryptopp.com;>Crypto++ 8.7.0 Benchmarks
Here are speed benchmarks for some commonly used cryptographic 
algorithms.
CPU frequency of the test platform is 1.8 GHz.



AlgorithmProviderMiB/SecondCycles/Byte

NonblockingRngC++10416.44
AutoSeededRandomPoolC++7822.13
AutoSeededX917RNG(AES)ARMv89198.0
MT19937C++14311.98
AES/OFB RNGARMv83005.72
Hash_DRBG(SHA1)ARMv85829.4
Hash_DRBG(SHA256)ARMv88220.92
HMAC_DRBG(SHA1)ARMv816106.5
HMAC_DRBG(SHA256)ARMv82374.0

CRC32ARMv832560.53
CRC32CARMv832560.53
Adler32C++8012.14
MD5C++2267.59
SHA-1ARMv87622.25
SHA-256ARMv86672.57
SHA-512C++11514.95
SHA3-224C++11215.32
SHA3-256C++10616.27
SHA3-384C++8121.09
SHA3-512C++5730.2
Keccak-224C++11215.33
Keccak-256C++10516.28
Keccak-384C++8121.08
Keccak-512C++5730.2
TigerC++1799.61
WhirlpoolC++3254.0
RIPEMD-160C++11714.63
RIPEMD-320C++11415.11
RIPEMD-128C++2277.55
RIPEMD-256C++2148.02
SM3C++10116.94
BLAKE2sC++15011.48
BLAKE2bC++15111.37
LSH-256C++3549.3
LSH-512C++5630.7






AlgorithmProviderMiB/SecondCycles/ByteMicroseconds 
toSetup Key and IVCycles toSetup Key and IV

GMAC(AES)ARMv810331.661.5562801
VMAC(AES)-64 (128-bit key)ARMv813451.282.2224000
VMAC(AES)-128 (128-bit key)ARMv88202.092.5274549
HMAC(SHA-1) (128-bit key)ARMv87532.281.0971975
HMAC(SHA-256) (128-bit key)ARMv86632.591.0971975
Two-Track-MAC (160-bit key)C++14012.230.05090
CMAC(AES) (128-bit key)ARMv83405.050.7231301
DMAC(AES) (128-bit key)ARMv83454.982.0293653
Poly1305(AES) (256-bit key)ARMv83005.720.8311496
Poly1305TLS (256-bit key)C++3005.720.05191
BLAKE2s (256-bit key)C++15011.480.5971074
BLAKE2b (512-bit key)C++15111.360.6221120
SipHash-2-4 (128-bit key)C++5932.890.05498
SipHash-4-8 (128-bit key)C++3504.900.05498

Panama-LE (256-bit key)C++2576.673.8106859
Panama-BE (256-bit key)C++2506.863.8366904
Salsa20C++2227.740.485873
Salsa20/12C++3115.520.6021084
Salsa20/8C++3854.460.6081094
ChaCha20NEON2536.790.475854
ChaCha12NEON3964.340.5851052
ChaCha8NEON5493.120.5911064
ChaChaTLS (256-bit key)NEON2536.800.5641016
Sosemanuk (128-bit key)C++4843.551.3932507
Rabbit (128-bit key)C++13013.170.5991079
RabbitWithIV (128-bit key)C++13013.171.2852313
HC-128 (128-bit key)C++3504.9018.16032688
HC-256 (256-bit key)C++14312.01119.603215285
MARC4 (128-bit key)C++11415.024.4478004
SEAL-3.0-LE (160-bit key)C++2806.1331.42756569
WAKE-OFB-LE (256-bit key)C++1849.314.0167229

AES/CTR (128-bit key)ARMv85982.871.0091816
AES/CTR (192-bit key)ARMv85383.191.0181832
AES/CTR (256-bit key)ARMv85023.421.0711928
AES/CBC (128-bit key)ARMv83415.040.8171470
AES/CBC (192-bit key)ARMv83065.600.8301493
AES/CBC (256-bit key)ARMv82786.170.8881599
AES/XTS (256-bit key)ARMv82985.761.4302574
AES/XTS (384-bit key)ARMv82816.111.4742654
AES/XTS (512-bit key)ARMv82746.261.5832849
AES/OFB (128-bit key)ARMv83175.410.9631733
AES/CFB (128-bit key)ARMv83444.991.1352044
AES/ECB (128-bit key)ARMv87312.350.458825
ARIA/CTR (128-bit key)C++3450.10.7531356
ARIA/CTR (256-bit key)C++2862.20.7721390
HIGHT/CTR (128-bit key)C++17104.01.3022343
Camellia/CTR (128-bit key)C++5730.40.7361325
Camellia/CTR (256-bit key)C++4438.90.7741393
Twofish/CTR (128-bit key)C++6825.38.80715853
Threefish-256(256)/CTR (256-bit 
key)C++9318.550.7591366
Threefish-512(512)/CTR (512-bit 
key)C++10616.270.7681382
Threefish-1024(1024)/CTR (1024-bit 
key)C++5829.60.8351503
Serpent/CTR (128-bit key)C++4142.01.5612809
CAST-128/CTR (128-bit key)C++4637.31.1212018
CAST-256/CTR (256-bit key)C++4538.32.4174351
RC6/CTR (128-bit key)C++8619.862.7224899
MARS/CTR (128-bit key)C++4934.74.7148485
SHACAL-2/CTR (128-bit key)C++7522.961.0051809
SHACAL-2/CTR (512-bit key)C++7522.981.0511892
DES/CTR (64-bit key)C++3155.614.62226319
DES-XEX3/CTR (192-bit key)C++2665.614.73626525
DES-EDE3/CTR (192-bit key)C++12140.443.75478758
IDEA/CTR (128-bit key)C++3254.30.9021624
RC5 (r=16)C++7921.822.3204176
Blowfish/CTR (128-bit key)C++5929.264.819116674
SKIPJACK/CTR (80-bit key)C++1799.67.78114006
SEED/CTR (1/2 K table)C++3252.80.8421516
SM4/CTR (128-bit key)C++3844.61.0251846
Kalyna-128(128)/CTR (128-bit 
key)C++5730.21.1342041
Kalyna-128(256)/CTR (256-bit 
key)C++3944.51.3122361
Kalyna-256(256)/CTR (256-bit 
key)C++3647.41.9143445
Kalyna-256(512)/CTR (512-bit 
key)C++2959.72.2103978
Kalyna-512(512)/CTR (512-bit 
key)C++3056.53.5526393

CHAM-64(128)/CTR (128-bit key)C++2181.40.6251125
CHAM-128(128)/CTR (128-bit 
key)C++4637.50.6171110
CHAM-128(256)/CTR (256-bit 
key)C++4043.20.6631193
LEA-128(128)/CTR (128-bit 
key)NEON8919.280.8481526
LEA-128(192)/CTR (192-bit 
key)NEON7822.030.9671741
LEA-128(256)/CTR (256-bit 
key)NEON6924.81.0071812
SIMECK-32(64)/CTR (64-bit key)C++2084.80.8201476
SIMECK-64(128)/CTR (128-bit 
key)C++4439.00.8471525
SIMON-64(96)/CTR (96-bit key)C++5233.10.8441520
SIMON-64(128)/CTR (128-bit 

Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
Hi Jeff,

I am using an ARM64 cross compiler. I source into the sdk using:


*source 
/opt/fsl-imx-xwayland/5.10-hardknott/environment-setup-cortexa53-crypto-poky-linux*

I compile it on x86 and the move it to the embedded machine for testing.

This is the compiler command when I issue the make command :

*aarch64-poky-linux-g++  -mcpu=cortex-a53 -march=armv8-a+crc+crypto 
-fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat 
-Wformat-security -Werror=format-security 
--sysroot=/opt/fsl-imx-xwayland/5.10-hardknott/sysroots/cortexa53-crypto-poky-linux
 
-O2 -pipe -g -feliminate-unused-debug-types -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 
-DCRYPTOPP_DISABLE_ASM -fPIC -pthread -pipe -c zlib.cpp*

I am right now compiling the latest library and will let you know the 
results. 

Let me know if you see anything in the compiler flags.

On Friday, May 12, 2023 at 9:37:50 AM UTC-4 Jeffrey Walton wrote:

> On Fri, May 12, 2023 at 9:09 AM Dwight Kulkarni  
> wrote:
> >
> > See below benchmark test results:
> >
> > root@imx8mpevk:~/p2p_sockets# ./cryptest.exe b 2 1.8
> > [...]
> > AES/CTR (128-bit key)C++6327.30.8861595
> > AES/CTR (192-bit key)C++5531.30.8821587
> > AES/CTR (256-bit key)C++4935.20.9101637
> > AES/CBC (128-bit key)C++5630.40.7321317
> > AES/CBC (192-bit key)C++5034.40.7281311
> > AES/CBC (256-bit key)C++4538.30.7561361
> > AES/OFB (128-bit key)C++5929.00.9331679
> > AES/CFB (128-bit key)C++6327.11.1352043
> > AES/ECB (128-bit key)C++6327.40.329592
> > [...]
>
> For completeness, AES/CFB is 27.1 cycles-per-byte (cpb). Cycles per
> byte is what I am interested in when comparing benchmarks. The other
> number you are probably interested in is 63, which is 63
> megabytes-per-second (MB/s).
>
> These numbers are software-only implementations. And the provider is
> "C++", which is software only.
>
> Here is what an aarch64 machine looks like, from an early Pine64 board:
>
> AES/CTR (128-bit key)ARMv84282.671.1741408
> AES/CTR (192-bit key)ARMv83763.051.1901428
> AES/CTR (256-bit key)ARMv83433.331.2301476
> AES/CBC (128-bit key)ARMv82804.080.9941192
> AES/CBC (192-bit key)ARMv82454.671.0071208
> AES/CBC (256-bit key)ARMv82185.261.0471256
> AES/XTS (256-bit key)ARMv82255.091.7282074
> AES/XTS (384-bit key)ARMv82105.461.7652117
> AES/XTS (512-bit key)ARMv81995.761.8542225
> AES/OFB (128-bit key)ARMv82265.061.1521383
> AES/CFB (128-bit key)ARMv82494.601.4141697
> AES/ECB (128-bit key)ARMv86041.900.525630
>
> AES/CFB is 4.6 cpb. The provider is "ARMv8." 249 is 249 MB/s.
>
> Modern aarch64 machines can usually get down to 2.5 cpb or so for CFB
> mode. This is from a MacMini M1:
>
> AES/CTR (128-bit key)ARMv893160.330.109349
> AES/CTR (192-bit key)ARMv881940.370.117376
> AES/CTR (256-bit key)ARMv873030.420.129412
> AES/CBC (128-bit key)ARMv810832.820.097310
> AES/CBC (192-bit key)ARMv89383.250.106339
> AES/CBC (256-bit key)ARMv88343.660.118379
> AES/XTS (256-bit key)ARMv818071.690.181578
> AES/XTS (384-bit key)ARMv817681.730.203650
> AES/XTS (512-bit key)ARMv817121.780.227726
> AES/OFB (128-bit key)ARMv811332.690.106340
> AES/CFB (128-bit key)ARMv811212.720.117374
> AES/ECB (128-bit key)ARMv8108830.280.072232
>
> AES/CFB is running at 2.7 cpb. 1121 is 1.12 GB/s.
>
> There's something unusual about your setup. You will need to determine
> why it is not providing ARMv8 acceleration, or why the library is not
> picking it up.
>
> Since your benchmarks are missing AES/XTR results, I know you are
> using an old version of the library. Maybe you should update to
> Crypto++ 8.7 for starters.
>
> Jeff
>
> > On Thursday, May 11, 2023 at 5:30:26 PM UTC-4 Jeffrey Walton wrote:
> >>
> >> On Thu, May 11, 2023 at 4:24 PM Dwight Kulkarni  
> wrote:
> >> >
> >> > I created a 5 MB message and encrypted it. The message takes 3 
> seconds to encrypt. I needed something around 200 ms, even if the 
> encryption is weaker.
> >> >
> >> > My code is below, should I be setting any flags when compiling the 
> library to make it fast ?
> >> >
> >> > Got message str at: 05/11/2023 20:21:31.346
> >> > in encrypt aes
> >> > Encrypted at: 05/11/2023 20:21:33.027
> >> >
> >> > message_bytes = encrypt_aes(message_bytes, key, iv);
> >> > cout << " Encrypted at: " << get_curr_datetime_str() << endl;
> >> >
> >> >
> >> > std::string encrypt_aes(std::string message, SecByteBlock key, 
> SecByteBlock iv) {
> >> > try {
> >> > cout <<" in encrypt aes " < >> > AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 
> 1/*8-bits*/)
> >> > (Name::IV(), ConstByteArrayParameter(iv));
> >> > CFB_Mode::Encryption e;
> >> > std::string cipher;
> >> > e.SetKey(key, key.size(), params);
> >> > StringSource ss(message, true, new StreamTransformationFilter(e, new 
> StringSink(cipher)));
> >> > cout << " returning cipher " << endl;
> >> > return cipher;
> >> > }
> >> > catch (CryptoPP::Exception e) {
> >> > std::cerr << e.what() << std::endl;
> >> > return "";
> >> > }
> >> > }
> >>
> >> You should probably avoid multiple resizes on cipher object. Add 
> 

Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Jeffrey Walton
On Fri, May 12, 2023 at 9:09 AM Dwight Kulkarni  wrote:
>
> See below benchmark test results:
>
> root@imx8mpevk:~/p2p_sockets# ./cryptest.exe b 2 1.8
>  [...]
> AES/CTR (128-bit key)C++6327.30.8861595
> AES/CTR (192-bit key)C++5531.30.8821587
> AES/CTR (256-bit key)C++4935.20.9101637
> AES/CBC (128-bit key)C++5630.40.7321317
> AES/CBC (192-bit key)C++5034.40.7281311
> AES/CBC (256-bit key)C++4538.30.7561361
> AES/OFB (128-bit key)C++5929.00.9331679
> AES/CFB (128-bit key)C++6327.11.1352043
> AES/ECB (128-bit key)C++6327.40.329592
>  [...]

For completeness, AES/CFB is 27.1 cycles-per-byte (cpb). Cycles per
byte is what I am interested in when comparing benchmarks. The other
number you are probably interested in is 63, which is 63
megabytes-per-second (MB/s).

These numbers are software-only implementations. And the provider is
"C++", which is software only.

Here is what an aarch64 machine looks like, from an early Pine64 board:

AES/CTR (128-bit key)ARMv84282.671.1741408
AES/CTR (192-bit key)ARMv83763.051.1901428
AES/CTR (256-bit key)ARMv83433.331.2301476
AES/CBC (128-bit key)ARMv82804.080.9941192
AES/CBC (192-bit key)ARMv82454.671.0071208
AES/CBC (256-bit key)ARMv82185.261.0471256
AES/XTS (256-bit key)ARMv82255.091.7282074
AES/XTS (384-bit key)ARMv82105.461.7652117
AES/XTS (512-bit key)ARMv81995.761.8542225
AES/OFB (128-bit key)ARMv82265.061.1521383
AES/CFB (128-bit key)ARMv82494.601.4141697
AES/ECB (128-bit key)ARMv86041.900.525630

AES/CFB is 4.6 cpb. The provider is "ARMv8." 249 is 249 MB/s.

Modern aarch64 machines can usually get down to 2.5 cpb or so for CFB
mode. This is from a MacMini M1:

AES/CTR (128-bit key)ARMv893160.330.109349
AES/CTR (192-bit key)ARMv881940.370.117376
AES/CTR (256-bit key)ARMv873030.420.129412
AES/CBC (128-bit key)ARMv810832.820.097310
AES/CBC (192-bit key)ARMv89383.250.106339
AES/CBC (256-bit key)ARMv88343.660.118379
AES/XTS (256-bit key)ARMv818071.690.181578
AES/XTS (384-bit key)ARMv817681.730.203650
AES/XTS (512-bit key)ARMv817121.780.227726
AES/OFB (128-bit key)ARMv811332.690.106340
AES/CFB (128-bit key)ARMv811212.720.117374
AES/ECB (128-bit key)ARMv8108830.280.072232

AES/CFB is running at 2.7 cpb. 1121 is 1.12 GB/s.

There's something unusual about your setup. You will need to determine
why it is not providing ARMv8 acceleration, or why the library is not
picking it up.

Since your benchmarks are missing AES/XTR results, I know you are
using an old version of the library. Maybe you should update to
Crypto++ 8.7 for starters.

Jeff

> On Thursday, May 11, 2023 at 5:30:26 PM UTC-4 Jeffrey Walton wrote:
>>
>> On Thu, May 11, 2023 at 4:24 PM Dwight Kulkarni  
>> wrote:
>> >
>> > I created a 5 MB message and encrypted it. The message takes 3 seconds to 
>> > encrypt. I needed something around 200 ms, even if the encryption is 
>> > weaker.
>> >
>> > My code is below, should I be setting any flags when compiling the library 
>> > to make it fast ?
>> >
>> > Got message str at: 05/11/2023 20:21:31.346
>> > in encrypt aes
>> > Encrypted at: 05/11/2023 20:21:33.027
>> >
>> > message_bytes = encrypt_aes(message_bytes, key, iv);
>> > cout << " Encrypted at: " << get_curr_datetime_str() << endl;
>> >
>> >
>> > std::string encrypt_aes(std::string message, SecByteBlock key, 
>> > SecByteBlock iv) {
>> > try {
>> > cout <<" in encrypt aes " <> > AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 
>> > 1/*8-bits*/)
>> > (Name::IV(), ConstByteArrayParameter(iv));
>> > CFB_Mode::Encryption e;
>> > std::string cipher;
>> > e.SetKey(key, key.size(), params);
>> > StringSource ss(message, true, new StreamTransformationFilter(e, new 
>> > StringSink(cipher)));
>> > cout << " returning cipher " << endl;
>> > return cipher;
>> > }
>> > catch (CryptoPP::Exception e) {
>> > std::cerr << e.what() << std::endl;
>> > return "";
>> > }
>> > }
>>
>> You should probably avoid multiple resizes on cipher object. Add something 
>> like:
>>
>> std::string cipher;
>> cipher.reserve(message.size()+16);
>>
>> Otherwise, please run the benchmarks and report back:
>>
>> cryptest.exe b2 3 
>>
>> Also see https://cryptopp.com/wiki/Benchmarks .

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8nfFfA%3DuHj_4yTeLBfiLmCzEQQi369dy4ofOqgOTciwKQ%40mail.gmail.com.


Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-12 Thread Dwight Kulkarni
Hi Jeff,

See below benchmark test results:


root@imx8mpevk:~/p2p_sockets# ./cryptest.exe b 2 1.8




Speed Comparison of Popular Crypto Algorithms

  table {border-collapse: collapse;}
  table, th, td, tr {border: 1px solid black;}



http://www.cryptopp.com;>Crypto++ 8.1.0 Benchmarks
Here are speed benchmarks for some commonly used cryptographic 
algorithms.
CPU frequency of the test platform is 1.8 GHz.




AlgorithmProviderMiB/SecondCycles/Byte

NonblockingRngC++10416.45
AutoSeededRandomPoolC++4141.5
AutoSeededX917RNG(AES)C++7239.3
MT19937C++14311.96
AES/OFB RNGC++6028.5
Hash_DRBG(SHA1)C++3155.1
Hash_DRBG(SHA256)C++2764.3
HMAC_DRBG(SHA1)C++7231.6
HMAC_DRBG(SHA256)C++7242.4

CRC32C++2546.77
CRC32CC++2546.77
Adler32C++8012.14
MD5C++2267.59
SHA-1C++17010.08
SHA-256C++7323.42
SHA-512C++11514.93
SHA3-224C++10316.64
SHA3-256C++9817.53
SHA3-384C++7622.45
SHA3-512C++5431.7
Keccak-224C++10316.64
Keccak-256C++9817.53
Keccak-384C++7622.45
Keccak-512C++5431.7
TigerC++1799.60
WhirlpoolC++3254.0
RIPEMD-160C++11714.63
RIPEMD-320C++11415.12
RIPEMD-128C++2277.55
RIPEMD-256C++2148.02
SM3C++10216.80
BLAKE2sC++15011.46
BLAKE2bC++15311.25






AlgorithmProviderMiB/SecondCycles/ByteMicroseconds 
toSetup Key and IVCycles toSetup Key and IV

GMAC(AES) (2K tables)C++2068.322.6324738
GMAC(AES) (64K tables)C++13412.7924.25243654
VMAC(AES)-64 (128-bit key)C++10851.584.1047387
VMAC(AES)-128 (128-bit key)C++5063.394.8518731
HMAC(SHA-1) (128-bit key)C++16910.131.0981977
HMAC(SHA-256) (128-bit key)C++7323.421.1021983
Two-Track-MAC (160-bit key)C++14012.230.05090
CMAC(AES) (128-bit key)C++5630.40.7461343
DMAC(AES) (128-bit key)C++5630.41.9243464
Poly1305(AES) (256-bit key)C++3415.040.8441520
Poly1305TLS (256-bit key)C++3415.040.04988
BLAKE2s (256-bit key)C++15011.460.6361146
BLAKE2b (512-bit key)C++15311.190.6641196
SipHash-2-4 (128-bit key)C++6202.770.05498
SipHash-4-8 (128-bit key)C++3504.900.05498

Panama-LE (256-bit key)C++2596.623.8316896
Panama-BE (256-bit key)C++2496.903.8596947
Salsa20C++2247.660.499898
Salsa20/12C++3165.440.6141105
Salsa20/8C++3924.370.6141105
ChaCha20C++1869.220.489879
ChaCha12C++2885.960.6031085
ChaCha8C++3894.410.6031085
ChaChaTLS (256-bit key)C++1869.230.6001080
Sosemanuk (128-bit key)C++4823.561.4972694
Rabbit (128-bit key)C++12214.130.5951072
RabbitWithIV (128-bit key)C++12014.271.2952330
HC-128 (128-bit key)C++2905.9118.21632788
HC-256 (256-bit key)C++13013.20119.611215300
MARC4 (128-bit key)C++11415.024.4508010
SEAL-3.0-LE (160-bit key)C++2905.9263.126113627
WAKE-OFB-LE (256-bit key)C++1799.574.0167229

AES/CTR (128-bit key)C++6327.30.8861595
AES/CTR (192-bit key)C++5531.30.8821587
AES/CTR (256-bit key)C++4935.20.9101637
AES/CBC (128-bit key)C++5630.40.7321317
AES/CBC (192-bit key)C++5034.40.7281311
AES/CBC (256-bit key)C++4538.30.7561361
AES/OFB (128-bit key)C++5929.00.9331679
AES/CFB (128-bit key)C++6327.11.1352043
AES/ECB (128-bit key)C++6327.40.329592
ARIA/CTR (128-bit key)C++3253.60.8891600
ARIA/CTR (256-bit key)C++2665.40.9491708
HIGHT/CTR (128-bit key)C++17103.51.3172371
Camellia/CTR (128-bit key)C++5730.00.7091275
Camellia/CTR (256-bit key)C++4538.60.7881419
Twofish/CTR (128-bit key)C++6924.88.85415937
Threefish-256(256)/CTR (256-bit 
key)C++9418.330.8071453
Threefish-512(512)/CTR (512-bit 
key)C++10716.020.8111460
Threefish-1024(1024)/CTR (1024-bit 
key)C++6028.60.8651556
Serpent/CTR (128-bit key)C++4141.81.5682822
CAST-128/CTR (128-bit key)C++4736.81.0811946
CAST-256/CTR (256-bit key)C++4537.72.4344381
RC6/CTR (128-bit key)C++8320.682.7344921
MARS/CTR (128-bit key)C++5034.34.7388529
SHACAL-2/CTR (128-bit key)C++7622.641.0261846
SHACAL-2/CTR (512-bit key)C++7622.641.0711928
DES/CTR (64-bit key)C++3155.614.64926368
DES-XEX3/CTR (192-bit key)C++2567.614.75026550
DES-EDE3/CTR (192-bit key)C++12140.343.78478812
IDEA/CTR (128-bit key)C++4042.80.9411694
RC5 (r=16)C++7921.832.3074152
Blowfish/CTR (128-bit key)C++6028.764.804116647
SKIPJACK/CTR (80-bit key)C++1896.77.79714035
SEED/CTR (1/2 K table)C++3352.30.8891600
SM4/CTR (128-bit key)C++3944.41.0581905
Kalyna-128(128)/CTR (128-bit 
key)C++5730.11.2172191
Kalyna-128(256)/CTR (256-bit 
key)C++4042.61.2102178
Kalyna-256(256)/CTR (256-bit 
key)C++3647.31.8683362
Kalyna-256(512)/CTR (512-bit 
key)C++2860.42.1993958
Kalyna-512(512)/CTR (512-bit 
key)C++3056.63.5076312

CHAM-64(128)/CTR (128-bit key)C++2180.30.6501169
CHAM-128(128)/CTR (128-bit 
key)C++4637.10.6291133
CHAM-128(256)/CTR (256-bit 
key)C++4043.00.6641196
LEA-128(128)/CTR (128-bit key)C++5232.90.8741572
LEA-128(192)/CTR (192-bit key)C++4538.30.9541718
LEA-128(256)/CTR (256-bit key)C++3943.51.0411874
SIMECK-32(64)/CTR (64-bit key)C++2276.60.8361505
SIMECK-64(128)/CTR (128-bit 
key)C++5133.80.8641556
SIMON-64(96)/CTR (96-bit key)C++5232.70.8191474
SIMON-64(128)/CTR (128-bit 
key)C++5034.10.8521533
SIMON-128(128)/CTR (128-bit 
key)C++7024.60.9371687
SIMON-128(192)/CTR (192-bit 
key)C++6924.80.9401693
SIMON-128(256)/CTR (256-bit 
key)C++6725.80.9871777
SPECK-64(96)/CTR (96-bit 

Re: [cryptopp-users] AES Encryption Took Too Long on Arm64 Embedded Machine

2023-05-11 Thread Jeffrey Walton
On Thu, May 11, 2023 at 4:24 PM Dwight Kulkarni  wrote:
>
> I created a 5 MB message and encrypted it. The message takes 3 seconds to 
> encrypt. I needed something around 200 ms, even if the encryption is weaker.
>
> My code is below, should I be setting any flags when compiling the library to 
> make it fast ?
>
>  Got message str at: 05/11/2023 20:21:31.346
>  in encrypt aes
>  Encrypted at: 05/11/2023 20:21:33.027
>
> message_bytes = encrypt_aes(message_bytes, key, iv);
> cout << " Encrypted at: " << get_curr_datetime_str() << endl;
>
>
> std::string encrypt_aes(std::string message, SecByteBlock key, SecByteBlock 
> iv) {
> try {
> cout <<" in encrypt aes " < AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 1/*8-bits*/)
> (Name::IV(), ConstByteArrayParameter(iv));
> CFB_Mode::Encryption e;
> std::string cipher;
> e.SetKey(key, key.size(), params);
> StringSource ss(message, true, new StreamTransformationFilter(e, new 
> StringSink(cipher)));
> cout << " returning cipher " << endl;
> return cipher;
> }
> catch (CryptoPP::Exception e) {
> std::cerr << e.what() << std::endl;
> return "";
> }
> }

You should probably avoid multiple resizes on cipher object. Add something like:

std::string cipher;
cipher.reserve(message.size()+16);

Otherwise, please run the benchmarks and report back:

cryptest.exe b2 3 

Also see https://cryptopp.com/wiki/Benchmarks .

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8%3DFPNNNZzS6X4Tyht_0Q759AmOVrj_XSTYf8HNbvY-nKw%40mail.gmail.com.