# Cryptographic hasing functions init-update-final

Does anyone care to explain what is the idea behind the init-update-final functions of cartographic hash functions (e.g. SHA*_Init, SHA*_Update, SHA*_Final from OpenSSL)?

Many libraries, like Java and OpenSSL, provide an Init-Update-Final model for transformations. It's used to minimize memory requirements.

Let's suppose all you have is a single shot SHA-1 function which requires the input to be available.

Then, for example, with a 1GB RAM system, how would you hash a file of 2 GB ?

You simply cannot as the SHA-1 function will require to have the whole input in RAM and you simply can't do it.

What you can do, instead, is to call SHA_Init, read 1MB of the file into RAM, SHA_Update that 1MB, read the next 1MB of the file (overwriting the previous one), call SHA_Update on that 1MB, repeat 1998 more times and then call SHA_Final.

This requires only 1MB RAM to hash a 2GB file.

• Adding to this, there's also times when you might want to hash the same initial data with numerous differing ending. If you have the context, the value after updating the hash with the initial data, then this can be done with less computation. – Thomas M. DuBuisson Oct 11 '17 at 0:26