I didn't give the load_aes_key function....here it is :


std::pair<SecByteBlock,SecByteBlock> 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<const byte*>(bkey.c_str()),
key.size());

ArraySink siv(iv.data(), iv.size());
siv.ChannelPut(DEFAULT_CHANNEL, reinterpret_cast<const byte*>(biv.c_str()),
iv.size());

//CryptoPP::GenerateIntoBufferedTransformation(s, DEFAULT_CHANNEL, size);
// key.data() = reinterpret_cast<byte*>(const_cast<char*>(nkey.c_str()));
//iv.data() = reinterpret_cast<byte*>(const_cast<char*>(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<SecByteBlock,SecByteBlock> akeys = load_aes_key_from_b64_str(bkey1, 
> biv2);
> cout << " Start at: " << get_curr_datetime_str() << endl;
>
> const int num_bytes = 5000003;
> std::random_device rd;
> std::mt19937 gen(rd());
> std::uniform_int_distribution<int> dist(0,255);
> std::string random_string;
> random_string.reserve(num_bytes);
> for(int i=0; i<num_bytes; i++){
> random_string += static_cast<char>(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 " <<endl;
> AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 1
> /*8-bits*/)
> (Name::IV(), ConstByteArrayParameter(iv));
> CFB_Mode<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 <dwi...@realtime-7.com> 
>> wrote: 
>> > 
>> > These are the results from CryptoPP 8.7 vs 8.1 earlier: 
>> > [...] 
>> > <TR><TD>AES/CFB (128-bit key)<TD>ARMv8<TD>344<TD>4.99<TD>1.135<TD>2044 
>> > [...] 
>>
>> 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.

Reply via email to