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