SHA1(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… SHA1(3) β€” like, the whole hash family, bestie

okay so welcome to the SHA1(3) manual page πŸŽ€ this is one of those library-functions-manual situations and honestly it's giving "the entire SHA squad showed up to the group chat." we've got SHA1, SHA224, SHA256, SHA384, SHA512 and every _Init, _Update, _Final bestie that comes with them. buckle up πŸ’–

✨ NAME ✨

SHA1, SHA1_Init, SHA1_Update, SHA1_Final, SHA224, SHA224_Init, SHA224_Update, SHA224_Final, SHA256, SHA256_Init, SHA256_Update, SHA256_Final, SHA384, SHA384_Init, SHA384_Update, SHA384_Final, SHA512, SHA512_Init, SHA512_Update, SHA512_Final β€” Secure Hash Algorithm 🌸

like yes that's a lot of names, but they're all literally the same vibe at different digest sizes, iykyk.


πŸ¦‹ SYNOPSIS πŸ¦‹

you're gonna need the libcrypto library and this include, no cap:

#include <openssl/sha.h>

and then the whole squad of prototypes, in order, exactly as they are:

unsigned char *
SHA1(const unsigned char *d, size_t n, unsigned char *md);

int
SHA1_Init(SHA_CTX *c);

int
SHA1_Update(SHA_CTX *c, const void *data, size_t len);

int
SHA1_Final(unsigned char *md, SHA_CTX *c);

unsigned char *
SHA224(const unsigned char *d, size_t n, unsigned char *md);

int
SHA224_Init(SHA256_CTX *c);

int
SHA224_Update(SHA256_CTX *c, const void *data, size_t len);

int
SHA224_Final(unsigned char *md, SHA256_CTX *c);

unsigned char *
SHA256(const unsigned char *d, size_t n, unsigned char *md);

int
SHA256_Init(SHA256_CTX *c);

int
SHA256_Update(SHA256_CTX *c, const void *data, size_t len);

int
SHA256_Final(unsigned char *md, SHA256_CTX *c);

unsigned char *
SHA384(const unsigned char *d, size_t n, unsigned char *md);

int
SHA384_Init(SHA512_CTX *c);

int
SHA384_Update(SHA512_CTX *c, const void *data, size_t len);

int
SHA384_Final(unsigned char *md, SHA512_CTX *c);

unsigned char *
SHA512(const unsigned char *d, size_t n, unsigned char *md);

int
SHA512_Init(SHA512_CTX *c);

int
SHA512_Update(SHA512_CTX *c, const void *data, size_t len);

int
SHA512_Final(unsigned char *md, SHA512_CTX *c);

notice how SHA224 and SHA256 are out here borrowing SHA256_CTX, and SHA384/SHA512 are sharing SHA512_CTX? iconic group-project energy tbh πŸ‘‘


🌈 DESCRIPTION 🌈

so. SHA-1 (Secure Hash Algorithm) is a cryptographic hash function with a 160-bit output. yes, the classic. the original main character πŸ”₯

SHA1() computes the SHA-1 message digest of the n bytes at d and places it in md. and md must have space for SHA_DIGEST_LENGTH == 20 bytes of output. like, 20 bytes, don't skimp, she needs her room πŸ’…

🧚 when your message isn't fully in memory

the following functions may be used if the message is not completely stored in memory β€” very "streaming era" of them:

  • SHA1_Init() β€” initializes a SHA_CTX structure.
  • SHA1_Update() β€” can be called repeatedly with chunks of the message to be hashed (len bytes at data). call it as many times as you want bestie, she's not gonna judge 🫢
  • SHA1_Final() β€” places the message digest in md, which must have space for SHA_DIGEST_LENGTH == 20 bytes of output, and erases the SHA_CTX.

πŸ’œ the rest of the family

the SHA224, SHA256, SHA384, and SHA512 families of functions operate in the same way as the SHA1 functions. same vibe, different digest size ✨

but heads up, the context types are not all the same:

  • SHA224 and SHA256 use a SHA256_CTX object instead of SHA_CTX
  • SHA384 and SHA512 use SHA512_CTX

and the buffer md must have space for the output from the SHA variant being used: SHA224_DIGEST_LENGTH, SHA256_DIGEST_LENGTH, SHA384_DIGEST_LENGTH, or SHA512_DIGEST_LENGTH bytes. match the buffer to the variant, bestie, that's the whole bit πŸŽ€

πŸ™ˆ real talk though: applications should use the higher level functions EVP_DigestInit(3) etc. instead of calling the hash functions directly. like, the low-level ones are cute but EVP is the grown-and-sexy option, ngl.

πŸ’€ RETURN VALUES πŸ’€

  • SHA1(), SHA224(), SHA256(), SHA384(), and SHA512() return a pointer to the hash value πŸŽ‰
  • the other functions return 1 for success or 0 otherwise. classic binary mood swing fr fr.

πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're literally in the same friend group 🫢


⭐ STANDARDS ⭐

Secure Hash Standard (SHS), NIST FIPS Publication, 180-4, https://doi.org/10.6028/NIST.FIPS.180-4, 2015. the receipts, periodt πŸ“œ


🌸 HISTORY 🌸

SHA1(), SHA1_Init(), SHA1_Update(), and SHA1_Final() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4. elder emoji energy, honestly ancient and thriving πŸ¦‹

the other functions first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5. the little siblings showed up later and slayed too πŸ’–


πŸ“ CAVEATS πŸ“

read this one carefully bestie β€” other implementations allow md in SHA1(), SHA224(), SHA256(), SHA384(), and SHA512() to be NULL and return a static array, which is not thread safe. 😭 so like... don't count on that being a cute portable trick. static array = shared state = chaos in threads. no cap.

and that's the page!! mwah πŸ’‹ this little writeup comes to you from Debian, dated June 8, 2025 β€” go hash something responsibly, ily, bye πŸŽ€βœ¨πŸ’œ

πŸ“¦ where this page comes from