]>
Commit | Line | Data |
---|---|---|
21dcbebc RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
d02b48c6 | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
ae4186b0 DMSP |
10 | #ifndef OPENSSL_SHA_H |
11 | # define OPENSSL_SHA_H | |
d86167ec DMSP |
12 | # pragma once |
13 | ||
14 | # include <openssl/macros.h> | |
936c2b9e | 15 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
d86167ec DMSP |
16 | # define HEADER_SHA_H |
17 | # endif | |
d02b48c6 | 18 | |
0f113f3e MC |
19 | # include <openssl/e_os2.h> |
20 | # include <stddef.h> | |
cf1b7d96 | 21 | |
8720b177 | 22 | # ifdef __cplusplus |
d02b48c6 | 23 | extern "C" { |
8720b177 | 24 | # endif |
d02b48c6 | 25 | |
1d97c843 | 26 | /*- |
8e7f966b | 27 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
04f8bcf1 | 28 | * ! SHA_LONG has to be at least 32 bits wide. ! |
8e7f966b UM |
29 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
30 | */ | |
a978dc3b | 31 | # define SHA_LONG unsigned int |
0f113f3e | 32 | |
a978dc3b P |
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 | |
0f113f3e MC |
39 | |
40 | typedef struct SHAstate_st { | |
41 | SHA_LONG h0, h1, h2, h3, h4; | |
42 | SHA_LONG Nl, Nh; | |
43 | SHA_LONG data[SHA_LBLOCK]; | |
44 | unsigned int num; | |
45 | } SHA_CTX; | |
46 | ||
a978dc3b P |
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); | |
0f113f3e | 52 | |
a978dc3b | 53 | # define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a |
0f113f3e MC |
54 | * contiguous array of 32 bit wide |
55 | * big-endian values. */ | |
0f113f3e MC |
56 | |
57 | typedef struct SHA256state_st { | |
58 | SHA_LONG h[8]; | |
59 | SHA_LONG Nl, Nh; | |
60 | SHA_LONG data[SHA_LBLOCK]; | |
61 | unsigned int num, md_len; | |
62 | } SHA256_CTX; | |
a978dc3b P |
63 | |
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); | |
c842261b | 73 | |
474e469b RS |
74 | # define SHA224_DIGEST_LENGTH 28 |
75 | # define SHA256_DIGEST_LENGTH 32 | |
0f113f3e MC |
76 | # define SHA384_DIGEST_LENGTH 48 |
77 | # define SHA512_DIGEST_LENGTH 64 | |
c842261b AP |
78 | |
79 | /* | |
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. | |
83 | */ | |
dbd87ffc MC |
84 | /* |
85 | * SHA-512 treats input data as a | |
86 | * contiguous array of 64 bit | |
87 | * wide big-endian values. | |
88 | */ | |
a978dc3b P |
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 | |
94 | # else | |
95 | # define SHA_LONG64 unsigned long long | |
96 | # endif | |
0f113f3e MC |
97 | |
98 | typedef struct SHA512state_st { | |
99 | SHA_LONG64 h[8]; | |
100 | SHA_LONG64 Nl, Nh; | |
101 | union { | |
102 | SHA_LONG64 d[SHA_LBLOCK]; | |
103 | unsigned char p[SHA512_CBLOCK]; | |
104 | } u; | |
105 | unsigned int num, md_len; | |
106 | } SHA512_CTX; | |
a978dc3b P |
107 | |
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); | |
c842261b | 117 | |
8720b177 | 118 | # ifdef __cplusplus |
d02b48c6 | 119 | } |
8720b177 | 120 | # endif |
d02b48c6 RE |
121 | |
122 | #endif |