---
name: "libressl-SHA1"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-SHA1"
---

# libressl-SHA1(3)

Secure Hash Algorithm

## 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

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/sha.h\>**

*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*);

## DESCRIPTION

SHA-1 (Secure Hash Algorithm) is a cryptographic hash function with a 160-bit output.

**SHA1**() computes the SHA-1 message digest of the *n* bytes at *d* and places it in *md*, which must have space for SHA\_DIGEST\_LENGTH == 20 bytes of output.

The following functions may be used if the message is not completely stored in memory:

**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*).

**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 SHA224, SHA256, SHA384, and SHA512 families of functions operate in the same way as the SHA1 functions. Note that SHA224 and SHA256 use a *SHA256\_CTX* object instead of *SHA\_CTX*, and SHA384 and SHA512 use *SHA512\_CTX*. 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.

Applications should use the higher level functions EVP\_DigestInit(3) etc.  instead of calling the hash functions directly.

## 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.

## SEE ALSO

EVP\_DigestInit(3), HMAC(3), RIPEMD160(3)

## STANDARDS

*Secure Hash Standard (SHS)*, NIST FIPS Publication, 180-4, 2015, https://doi.org/10.6028/NIST.FIPS.180-4.

## HISTORY

**SHA1**(), **SHA1\_Init**(), **SHA1\_Update**(), and **SHA1\_Final**() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.

The other functions first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5.

## CAVEATS

Other implementations allow *md* in **SHA1**(), **SHA224**(), **SHA256**(), **SHA384**(), and **SHA512**() to be NULL and return a static array, which is not thread safe.
