Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make encryption/decryption faster with big files #219

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chiyutianyi
Copy link

I notice that encryption/decryption will be slow when doing with big files.

  1. use byte_counter++ & (BLOCK_LEN -1) will be faster than byte_counter++ % BLOCK_LEN.
  2. use EVP methods will be faster than aes-core:
$ openssl speed aes-256-cbc
Doing aes-256 cbc for 3s on 16 size blocks: 20421982 aes-256 cbc's in 2.99s
Doing aes-256 cbc for 3s on 64 size blocks: 5347742 aes-256 cbc's in 3.00s
Doing aes-256 cbc for 3s on 256 size blocks: 1263704 aes-256 cbc's in 2.99s
Doing aes-256 cbc for 3s on 1024 size blocks: 308552 aes-256 cbc's in 2.96s
Doing aes-256 cbc for 3s on 8192 size blocks: 40526 aes-256 cbc's in 2.98s
LibreSSL 2.8.3
built on: date not available
options:bn(64,64) rc4(16x,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler: information not available
The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
aes-256 cbc     109248.19k   114155.14k   108162.40k   106682.45k   111352.49k
$ openssl speed -evp aes-256-cbc
Doing aes-256-cbc for 3s on 16 size blocks: 171610892 aes-256-cbc's in 2.99s
Doing aes-256-cbc for 3s on 64 size blocks: 39061952 aes-256-cbc's in 2.94s
Doing aes-256-cbc for 3s on 256 size blocks: 9160896 aes-256-cbc's in 2.93s
Doing aes-256-cbc for 3s on 1024 size blocks: 2470343 aes-256-cbc's in 2.93s
Doing aes-256-cbc for 3s on 8192 size blocks: 349873 aes-256-cbc's in 3.00s
LibreSSL 2.8.3
built on: date not available
options:bn(64,64) rc4(16x,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler: information not available
The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
aes-256-cbc     917066.85k   850782.25k   799582.06k   862127.79k   956856.91k

As `x % 16` is equals to `x & 15` which will be faster during
encrypt/decrypt big files.
EVP_aes_256_ecb will be faster when encrypt/decrypt big files.
@@ -51,14 +51,14 @@ void Aes_ctr_encryptor::process (const unsigned char* in, unsigned char* out, si
for (size_t i = 0; i < len; ++i) {
if (byte_counter % BLOCK_LEN == 0) {
// Set last 4 bytes of CTR to the (big-endian) block number (sequentially increasing with each block)
store_be32(ctr_value + NONCE_LEN, byte_counter / BLOCK_LEN);
store_be32(ctr_value + NONCE_LEN, byte_counter >> 4);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use BLOCK_LEN here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants