swift-crypto icon indicating copy to clipboard operation
swift-crypto copied to clipboard

Crypto operations on streamed data

Open kodlian opened this issue 3 years ago • 0 comments

New API Proposal: Crypto operations on streamed data

Motivation:

Add APIs to handle crypto operations on streamed data, meaning by processing chunks of data of arbitrary size in a non-continuous way. These APIs should offer three phases:

  • context initialization
  • update(s): update through a method that takes as input a chunk of data (can be called multiple times)
  • finalization: Get the output of the crypto operation

Cipher, Digest, and HMac operations would benefit from such API. Although it may not be possible to add this kind of streamed operation on all the algorithms.

Such APIs exist in Common Crypto on the Apple Platforms through for instance CCCryptorCreate, CCCryptorUpdate, and CCCryptorFinal.

Importance:

When performing a crypto operation on a large file, it must be done by streaming the data instead of keeping it all in memory/loading all in memory.

kodlian avatar Feb 03 '22 12:02 kodlian