1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimSHA1, SHA1_Init, SHA1_Update, SHA1_Final, SHA224, SHA224_Init, SHA224_Update, 6e71b7053SJung-uk KimSHA224_Final, SHA256, SHA256_Init, SHA256_Update, SHA256_Final, SHA384, 7e71b7053SJung-uk KimSHA384_Init, SHA384_Update, SHA384_Final, SHA512, SHA512_Init, SHA512_Update, 8e71b7053SJung-uk KimSHA512_Final - Secure Hash Algorithm 9e71b7053SJung-uk Kim 10e71b7053SJung-uk Kim=head1 SYNOPSIS 11e71b7053SJung-uk Kim 12e71b7053SJung-uk Kim #include <openssl/sha.h> 13e71b7053SJung-uk Kim 14*b077aed3SPierre Pronchery unsigned char *SHA1(const unsigned char *data, size_t count, unsigned char *md_buf); 15*b077aed3SPierre Pronchery unsigned char *SHA224(const unsigned char *data, size_t count, unsigned char *md_buf); 16*b077aed3SPierre Pronchery unsigned char *SHA256(const unsigned char *data, size_t count, unsigned char *md_buf); 17*b077aed3SPierre Pronchery unsigned char *SHA384(const unsigned char *data, size_t count, unsigned char *md_buf); 18*b077aed3SPierre Pronchery unsigned char *SHA512(const unsigned char *data, size_t count, unsigned char *md_buf); 19*b077aed3SPierre Pronchery 20*b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be 21*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 22*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>: 23*b077aed3SPierre Pronchery 24e71b7053SJung-uk Kim int SHA1_Init(SHA_CTX *c); 25e71b7053SJung-uk Kim int SHA1_Update(SHA_CTX *c, const void *data, size_t len); 26e71b7053SJung-uk Kim int SHA1_Final(unsigned char *md, SHA_CTX *c); 27e71b7053SJung-uk Kim 28e71b7053SJung-uk Kim int SHA224_Init(SHA256_CTX *c); 29e71b7053SJung-uk Kim int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); 30e71b7053SJung-uk Kim int SHA224_Final(unsigned char *md, SHA256_CTX *c); 31e71b7053SJung-uk Kim 32e71b7053SJung-uk Kim int SHA256_Init(SHA256_CTX *c); 33e71b7053SJung-uk Kim int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 34e71b7053SJung-uk Kim int SHA256_Final(unsigned char *md, SHA256_CTX *c); 35e71b7053SJung-uk Kim 36e71b7053SJung-uk Kim int SHA384_Init(SHA512_CTX *c); 37e71b7053SJung-uk Kim int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); 38e71b7053SJung-uk Kim int SHA384_Final(unsigned char *md, SHA512_CTX *c); 39e71b7053SJung-uk Kim 40e71b7053SJung-uk Kim int SHA512_Init(SHA512_CTX *c); 41e71b7053SJung-uk Kim int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); 42e71b7053SJung-uk Kim int SHA512_Final(unsigned char *md, SHA512_CTX *c); 43e71b7053SJung-uk Kim 44e71b7053SJung-uk Kim=head1 DESCRIPTION 45e71b7053SJung-uk Kim 46*b077aed3SPierre ProncheryAll of the functions described on this page 47*b077aed3SPierre Proncheryexcept for SHA1(), SHA224(), SHA256(), SHA384() and SHA512() are deprecated. 48*b077aed3SPierre ProncheryApplications should instead use L<EVP_DigestInit_ex(3)>, L<EVP_DigestUpdate(3)> 49*b077aed3SPierre Proncheryand L<EVP_DigestFinal_ex(3)>, or the quick one-shot function L<EVP_Q_digest(3)>. 50*b077aed3SPierre ProncherySHA1(), SHA224(), SHA256(), SHA384(), and SHA256() 51*b077aed3SPierre Proncherycan continue to be used. They can also be replaced by, e.g., 52*b077aed3SPierre Pronchery 53*b077aed3SPierre Pronchery (EVP_Q_digest(d, n, md, NULL, NULL, "SHA256", NULL) ? md : NULL) 54e71b7053SJung-uk Kim 55e71b7053SJung-uk KimSHA-1 (Secure Hash Algorithm) is a cryptographic hash function with a 56e71b7053SJung-uk Kim160 bit output. 57e71b7053SJung-uk Kim 58e71b7053SJung-uk KimSHA1() computes the SHA-1 message digest of the B<n> 59e71b7053SJung-uk Kimbytes at B<d> and places it in B<md> (which must have space for 60e71b7053SJung-uk KimSHA_DIGEST_LENGTH == 20 bytes of output). If B<md> is NULL, the digest 61e71b7053SJung-uk Kimis placed in a static array. Note: setting B<md> to NULL is B<not thread safe>. 62e71b7053SJung-uk Kim 63e71b7053SJung-uk KimThe following functions may be used if the message is not completely 64e71b7053SJung-uk Kimstored in memory: 65e71b7053SJung-uk Kim 66e71b7053SJung-uk KimSHA1_Init() initializes a B<SHA_CTX> structure. 67e71b7053SJung-uk Kim 68e71b7053SJung-uk KimSHA1_Update() can be called repeatedly with chunks of the message to 69e71b7053SJung-uk Kimbe hashed (B<len> bytes at B<data>). 70e71b7053SJung-uk Kim 71e71b7053SJung-uk KimSHA1_Final() places the message digest in B<md>, which must have space 72e71b7053SJung-uk Kimfor SHA_DIGEST_LENGTH == 20 bytes of output, and erases the B<SHA_CTX>. 73e71b7053SJung-uk Kim 74e71b7053SJung-uk KimThe SHA224, SHA256, SHA384 and SHA512 families of functions operate in the 75e71b7053SJung-uk Kimsame way as for the SHA1 functions. Note that SHA224 and SHA256 use a 76e71b7053SJung-uk KimB<SHA256_CTX> object instead of B<SHA_CTX>. SHA384 and SHA512 use B<SHA512_CTX>. 77e71b7053SJung-uk KimThe buffer B<md> must have space for the output from the SHA variant being used 78e71b7053SJung-uk Kim(defined by SHA224_DIGEST_LENGTH, SHA256_DIGEST_LENGTH, SHA384_DIGEST_LENGTH and 79e71b7053SJung-uk KimSHA512_DIGEST_LENGTH). Also note that, as for the SHA1() function above, the 80e71b7053SJung-uk KimSHA224(), SHA256(), SHA384() and SHA512() functions are not thread safe if 81e71b7053SJung-uk KimB<md> is NULL. 82e71b7053SJung-uk Kim 83e71b7053SJung-uk Kim=head1 RETURN VALUES 84e71b7053SJung-uk Kim 85e71b7053SJung-uk KimSHA1(), SHA224(), SHA256(), SHA384() and SHA512() return a pointer to the hash 86e71b7053SJung-uk Kimvalue. 87e71b7053SJung-uk Kim 88e71b7053SJung-uk KimSHA1_Init(), SHA1_Update() and SHA1_Final() and equivalent SHA224, SHA256, 89e71b7053SJung-uk KimSHA384 and SHA512 functions return 1 for success, 0 otherwise. 90e71b7053SJung-uk Kim 91e71b7053SJung-uk Kim=head1 CONFORMING TO 92e71b7053SJung-uk Kim 93e71b7053SJung-uk KimUS Federal Information Processing Standard FIPS PUB 180-4 (Secure Hash 94e71b7053SJung-uk KimStandard), 95e71b7053SJung-uk KimANSI X9.30 96e71b7053SJung-uk Kim 97e71b7053SJung-uk Kim=head1 SEE ALSO 98e71b7053SJung-uk Kim 99*b077aed3SPierre ProncheryL<EVP_Q_digest(3)>, 100e71b7053SJung-uk KimL<EVP_DigestInit(3)> 101e71b7053SJung-uk Kim 102*b077aed3SPierre Pronchery=head1 HISTORY 103*b077aed3SPierre Pronchery 104*b077aed3SPierre ProncheryAll of these functions except SHA*() were deprecated in OpenSSL 3.0. 105*b077aed3SPierre Pronchery 106e71b7053SJung-uk Kim=head1 COPYRIGHT 107e71b7053SJung-uk Kim 108*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 109e71b7053SJung-uk Kim 110*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 111e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 112e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 113e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 114e71b7053SJung-uk Kim 115e71b7053SJung-uk Kim=cut 116