I am encrypting large file sizes (>1GB) using AES encryption with a key size of 256 and over a 1000 hash iterations. To make the program memory efficient I'm reading the file from the stream, chunk by chunk (of specific buffer lengths) and encrypting them.

However, to encrypt a file of roughly 1GB it just takes me ~6 secs on a Mac with 16GB memory and 2.2 GHz i7 processor. Is it normal that it takes only this much time? Or should I be concerned? does it usually take longer? Or (as I read) is it given AES's quality to be fast?

Any help in understanding the scenario will be appreciated.

Thank You

  • 3
    $\begingroup$ My computer processes AES-128 at 3GB/s $\endgroup$ – Richie Frame Mar 22 '17 at 2:03
  • $\begingroup$ @RichieFrame - So it's not an abnormal behaviour? It's an acceptable thing is it? $\endgroup$ – Shabirmean Mar 22 '17 at 2:17
  • 1
    $\begingroup$ AES itself is very fast. Your 'over a 1000 hash iterations' suggests you are using a Password-Based encryption scheme, which is different from plain AES. The Password-Based Key Derivation step should be relatively slow; that's what the iteration count is for, although in the last two decades there are now PBKD schemes that are much safer than a plain iterated hash. $\endgroup$ – dave_thompson_085 Mar 22 '17 at 3:01
  • 3
    $\begingroup$ CAUTION: most likely 1000 hash iterations is not enough. These likely are for key stretching, perhaps PBKDF2 or similar, or iterating a standard hash. Since you find that 6 seconds is acceptable, you can probably spend 1 second at key stretching, and with proper implementation we are talking orders of magnitude more that 1000 hash iterations! $\endgroup$ – fgrieu Mar 22 '17 at 9:46

From this answer Different ways/algorithms for implementing AES you can see that AES is already pretty fast. By using the hardware instruction you can even get down to $\sim1.3$ cycles/byte[1].

$1 GB = 2^{30} B \approx 10^9 B$

Your CPU is working at $2.2$ GHz, in other word $2.2 \times 10^9$ cycles per second. To encrypt $1 GB$ you need $1.3 \times 2^{30}$ cycles. In other word, it would take $\frac{1.3 \times 2^{30}}{2.2 \times 10^9} = 0.634$ seconds. So clearly AES is super fast.

read more:

| improve this answer | |
  • $\begingroup$ Thanks Very Much. This solves my dilemma and I will mark it as correct since it also directs me to sources I can further understand this. $\endgroup$ – Shabirmean Mar 22 '17 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.