Crypto: Add deprecation compatibility declarations for SHA* message digest functions
[openssl.git] / include / openssl / sha.h
1 /*
2  * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #ifndef OPENSSL_SHA_H
11 # define OPENSSL_SHA_H
12 # pragma once
13
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
16 #  define HEADER_SHA_H
17 # endif
18
19 # include <openssl/e_os2.h>
20 # include <openssl/evp.h>
21 # include <stddef.h>
22
23 # ifdef  __cplusplus
24 extern "C" {
25 # endif
26
27 # define SHA_DIGEST_LENGTH 20
28
29 # ifndef OPENSSL_NO_DEPRECATED_3_0
30 /*-
31  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32  * ! SHA_LONG has to be at least 32 bits wide.                    !
33  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34  */
35 #  define SHA_LONG unsigned int
36
37 #  define SHA_LBLOCK      16
38 #  define SHA_CBLOCK      (SHA_LBLOCK*4)/* SHA treats input data as a
39                                          * contiguous array of 32 bit wide
40                                          * big-endian values. */
41 #  define SHA_LAST_BLOCK  (SHA_CBLOCK-8)
42
43 typedef struct SHAstate_st {
44     SHA_LONG h0, h1, h2, h3, h4;
45     SHA_LONG Nl, Nh;
46     SHA_LONG data[SHA_LBLOCK];
47     unsigned int num;
48 } SHA_CTX;
49
50 OSSL_DEPRECATEDIN_3_0 int SHA1_Init(SHA_CTX *c);
51 OSSL_DEPRECATEDIN_3_0 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
52 OSSL_DEPRECATEDIN_3_0 int SHA1_Final(unsigned char *md, SHA_CTX *c);
53 OSSL_DEPRECATEDIN_3_0 void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
54 # endif
55
56 # define SHA1(d, n, md) \
57     (EVP_Q_digest(NULL, "SHA1", NULL, d, n, md, NULL) ? md : NULL)
58
59 # ifndef OPENSSL_NO_DEPRECATED_3_0
60 #  define SHA256_CBLOCK   (SHA_LBLOCK*4)/* SHA-256 treats input data as a
61                                         * contiguous array of 32 bit wide
62                                         * big-endian values. */
63
64 typedef struct SHA256state_st {
65     SHA_LONG h[8];
66     SHA_LONG Nl, Nh;
67     SHA_LONG data[SHA_LBLOCK];
68     unsigned int num, md_len;
69 } SHA256_CTX;
70
71 OSSL_DEPRECATEDIN_3_0 int SHA224_Init(SHA256_CTX *c);
72 OSSL_DEPRECATEDIN_3_0 int SHA224_Update(SHA256_CTX *c,
73                                         const void *data, size_t len);
74 OSSL_DEPRECATEDIN_3_0 int SHA224_Final(unsigned char *md, SHA256_CTX *c);
75 OSSL_DEPRECATEDIN_3_0 int SHA256_Init(SHA256_CTX *c);
76 OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX *c,
77                                         const void *data, size_t len);
78 OSSL_DEPRECATEDIN_3_0 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
79 OSSL_DEPRECATEDIN_3_0 void SHA256_Transform(SHA256_CTX *c,
80                                             const unsigned char *data);
81 # endif
82
83 # define SHA224(d, n, md) \
84     (EVP_Q_digest(NULL, "SHA224", NULL, d, n, md, NULL) ? md : NULL)
85 # define SHA256(d, n, md) \
86     (EVP_Q_digest(NULL, "SHA256", NULL, d, n, md, NULL) ? md : NULL)
87
88 # define SHA224_DIGEST_LENGTH    28
89 # define SHA256_DIGEST_LENGTH    32
90 # define SHA384_DIGEST_LENGTH    48
91 # define SHA512_DIGEST_LENGTH    64
92
93 # ifndef OPENSSL_NO_DEPRECATED_3_0
94 /*
95  * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
96  * being exactly 64-bit wide. See Implementation Notes in sha512.c
97  * for further details.
98  */
99 /*
100  * SHA-512 treats input data as a
101  * contiguous array of 64 bit
102  * wide big-endian values.
103  */
104 #  define SHA512_CBLOCK   (SHA_LBLOCK*8)
105 #  if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
106 #   define SHA_LONG64 unsigned __int64
107 #  elif defined(__arch64__)
108 #   define SHA_LONG64 unsigned long
109 #  else
110 #   define SHA_LONG64 unsigned long long
111 #  endif
112
113 typedef struct SHA512state_st {
114     SHA_LONG64 h[8];
115     SHA_LONG64 Nl, Nh;
116     union {
117         SHA_LONG64 d[SHA_LBLOCK];
118         unsigned char p[SHA512_CBLOCK];
119     } u;
120     unsigned int num, md_len;
121 } SHA512_CTX;
122
123 OSSL_DEPRECATEDIN_3_0 int SHA384_Init(SHA512_CTX *c);
124 OSSL_DEPRECATEDIN_3_0 int SHA384_Update(SHA512_CTX *c,
125                                         const void *data, size_t len);
126 OSSL_DEPRECATEDIN_3_0 int SHA384_Final(unsigned char *md, SHA512_CTX *c);
127 OSSL_DEPRECATEDIN_3_0 int SHA512_Init(SHA512_CTX *c);
128 OSSL_DEPRECATEDIN_3_0 int SHA512_Update(SHA512_CTX *c,
129                                         const void *data, size_t len);
130 OSSL_DEPRECATEDIN_3_0 int SHA512_Final(unsigned char *md, SHA512_CTX *c);
131 OSSL_DEPRECATEDIN_3_0 void SHA512_Transform(SHA512_CTX *c,
132                                             const unsigned char *data);
133 # endif
134
135 # define SHA384(d, n, md) \
136     (EVP_Q_digest(NULL, "SHA384", NULL, d, n, md, NULL) ? md : NULL)
137 # define SHA512(d, n, md) \
138     (EVP_Q_digest(NULL, "SHA512", NULL, d, n, md, NULL) ? md : NULL)
139
140 # ifdef  __cplusplus
141 }
142 # endif
143
144 #endif