5

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

Shabirmean
  • 153
  • 1
  • 1
  • 4
  • 3
    My computer processes AES-128 at 3GB/s – Richie Frame Mar 22 '17 at 02:03
  • @RichieFrame - So it's not an abnormal behaviour? It's an acceptable thing is it? – Shabirmean Mar 22 '17 at 02:17
  • 1
    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. – dave_thompson_085 Mar 22 '17 at 03:01
  • 3
    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! – fgrieu Mar 22 '17 at 09:46

1 Answers1

10

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:

Biv
  • 9,979
  • 2
  • 39
  • 67
  • 1
    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. – Shabirmean Mar 22 '17 at 14:30