I'm a computer engineering student and I want to implement a cryptographic function for a college project. I want to realize my personal implementation of a WPA2 hash producer in C (and upload it to my FPGA). The main goal would be to use such FPGA as an alternative to Hashcat in bruteforcing passwords.

To do so, I need various implementations of Cryptographic Hash Functions such as SHA1 and HMAC-SHA1 and, while writing down the code, peeking into Hashcat's open source code and other users' custom code, I noticed that in both of them, the implementation followed a precise standard:

  • sha1_init
  • sha1_update
  • sha1_transform
  • sha1_final

I haven't found any specific implementation standard across the web so I was wondering if you had any information about this: is the above-mentioned standard a thing? If so, where can I find some guidelines about it?

  • $\begingroup$ I'm not sure that you mean "standard". I think it's just a process. $\endgroup$ – schroeder Mar 11 at 9:17
  • 1
    $\begingroup$ Have you looked up the SHA1 process? en.wikipedia.org/wiki/SHA-1#Examples_and_pseudocode and linux.die.net/man/3/sha1_update $\endgroup$ – schroeder Mar 11 at 9:20
  • $\begingroup$ How is this a security question? $\endgroup$ – MechMK1 Mar 11 at 9:23
  • $\begingroup$ @schroeder thanks for both the edit and the answer. I've already checked out the wikipedia pseudocode and I've used it already to model my own code. $\endgroup$ – Lyn Cassidy Mar 11 at 9:25
  • $\begingroup$ right, and can you see how those 4 steps fit into the pseudocode? $\endgroup$ – schroeder Mar 11 at 9:26

The usual lectures about the (in)securities of SHA-1 will be skipped.

The standard defining SHA-1 is NIST FIPS 180 (recent revision(s)), it specifies how to pad a bit-string into a form suitable for processing in the compression function specified for SHA-1, which it also specifies.

As of 2019, all current SHA-series hash functions are single-pass - that means you don't have to rewind to the beginning or any previous part of the message once you've done processing it, and this is a desirable property as not all computing systems (think embedded) are capable of storing all messages and go through them twice.

And we have firm reason to believe any future hash functions, either standardized by NIST (e.g. in the lightweight cryptography process) or any other bodies (CFRG from IETF) will continue to be single-pass.

The APIs you saw reflects this:

  1. It initializes a working context for computing the hash of a particular message,
  2. It feeds data to it with the "update" functions, and
  3. It finalizes it by padding the message and process the remaining data block(s).

The "transform" part you saw is usually not exported to external modules and is only invoked internally by the update and finalization functions.

| improve this answer | |

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.