SHA1(3)
π 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 aSHA_CTXstructure.SHA1_Update()β can be called repeatedly with chunks of the message to be hashed (lenbytes atdata). call it as many times as you want bestie, she's not gonna judge π«ΆSHA1_Final()β places the message digest inmd, which must have space forSHA_DIGEST_LENGTH == 20bytes of output, and erases theSHA_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:
SHA224andSHA256use aSHA256_CTXobject instead ofSHA_CTXSHA384andSHA512useSHA512_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(), andSHA512()return a pointer to the hash value π- the other functions return
1for success or0otherwise. 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 allowmdinSHA1(),SHA224(),SHA256(),SHA384(), andSHA512()to beNULLand 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
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2000, 2006, 2015 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms