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