2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 # define OPENSSL_SHA_H
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
19 # include <openssl/e_os2.h>
27 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 * ! SHA_LONG has to be at least 32 bits wide. !
29 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 # define SHA_LONG unsigned int
33 # define SHA_LBLOCK 16
34 # define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a
35 * contiguous array of 32 bit wide
36 * big-endian values. */
37 # define SHA_LAST_BLOCK (SHA_CBLOCK-8)
38 # define SHA_DIGEST_LENGTH 20
40 typedef struct SHAstate_st {
41 SHA_LONG h0, h1, h2, h3, h4;
43 SHA_LONG data[SHA_LBLOCK];
47 int SHA1_Init(SHA_CTX *c);
48 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
49 int SHA1_Final(unsigned char *md, SHA_CTX *c);
50 unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
51 void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
53 # define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a
54 * contiguous array of 32 bit wide
55 * big-endian values. */
57 typedef struct SHA256state_st {
60 SHA_LONG data[SHA_LBLOCK];
61 unsigned int num, md_len;
64 int SHA224_Init(SHA256_CTX *c);
65 int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
66 int SHA224_Final(unsigned char *md, SHA256_CTX *c);
67 unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
68 int SHA256_Init(SHA256_CTX *c);
69 int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
70 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
71 unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
72 void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
74 # define SHA224_DIGEST_LENGTH 28
75 # define SHA256_DIGEST_LENGTH 32
76 # define SHA384_DIGEST_LENGTH 48
77 # define SHA512_DIGEST_LENGTH 64
80 * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
81 * being exactly 64-bit wide. See Implementation Notes in sha512.c
82 * for further details.
85 * SHA-512 treats input data as a
86 * contiguous array of 64 bit
87 * wide big-endian values.
89 # define SHA512_CBLOCK (SHA_LBLOCK*8)
90 # if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
91 # define SHA_LONG64 unsigned __int64
92 # elif defined(__arch64__)
93 # define SHA_LONG64 unsigned long
95 # define SHA_LONG64 unsigned long long
98 typedef struct SHA512state_st {
102 SHA_LONG64 d[SHA_LBLOCK];
103 unsigned char p[SHA512_CBLOCK];
105 unsigned int num, md_len;
108 int SHA384_Init(SHA512_CTX *c);
109 int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
110 int SHA384_Final(unsigned char *md, SHA512_CTX *c);
111 unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
112 int SHA512_Init(SHA512_CTX *c);
113 int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
114 int SHA512_Final(unsigned char *md, SHA512_CTX *c);
115 unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
116 void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);