]>
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 | |
d02b48c6 RE |
22 | #ifdef __cplusplus |
23 | extern "C" { | |
24 | #endif | |
25 | ||
1d97c843 | 26 | /*- |
8e7f966b | 27 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
04f8bcf1 | 28 | * ! SHA_LONG has to be at least 32 bits wide. ! |
8e7f966b UM |
29 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
30 | */ | |
04f8bcf1 | 31 | # define SHA_LONG unsigned int |
0f113f3e MC |
32 | |
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 | |
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 | ||
2dc769a1 | 47 | int SHA1_Init(SHA_CTX *c); |
9e0aad9f | 48 | int SHA1_Update(SHA_CTX *c, const void *data, size_t len); |
2dc769a1 | 49 | int SHA1_Final(unsigned char *md, SHA_CTX *c); |
9e0aad9f | 50 | unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); |
7f7c318c | 51 | void SHA1_Transform(SHA_CTX *c, const unsigned char *data); |
0f113f3e MC |
52 | |
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. */ | |
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; | |
63 | ||
c842261b AP |
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); | |
0f113f3e | 67 | unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); |
c842261b AP |
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); | |
0f113f3e | 71 | unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); |
c842261b | 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 | */ | |
474e469b RS |
89 | # define SHA512_CBLOCK (SHA_LBLOCK*8) |
90 | # if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) | |
91 | # define SHA_LONG64 unsigned __int64 | |
92 | # define U64(C) C##UI64 | |
93 | # elif defined(__arch64__) | |
94 | # define SHA_LONG64 unsigned long | |
95 | # define U64(C) C##UL | |
96 | # else | |
97 | # define SHA_LONG64 unsigned long long | |
98 | # define U64(C) C##ULL | |
99 | # endif | |
0f113f3e MC |
100 | |
101 | typedef struct SHA512state_st { | |
102 | SHA_LONG64 h[8]; | |
103 | SHA_LONG64 Nl, Nh; | |
104 | union { | |
105 | SHA_LONG64 d[SHA_LBLOCK]; | |
106 | unsigned char p[SHA512_CBLOCK]; | |
107 | } u; | |
108 | unsigned int num, md_len; | |
109 | } SHA512_CTX; | |
0f113f3e | 110 | |
c842261b AP |
111 | int SHA384_Init(SHA512_CTX *c); |
112 | int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); | |
113 | int SHA384_Final(unsigned char *md, SHA512_CTX *c); | |
0f113f3e | 114 | unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md); |
c842261b AP |
115 | int SHA512_Init(SHA512_CTX *c); |
116 | int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); | |
117 | int SHA512_Final(unsigned char *md, SHA512_CTX *c); | |
0f113f3e | 118 | unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md); |
c842261b | 119 | void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); |
c842261b | 120 | |
d02b48c6 RE |
121 | #ifdef __cplusplus |
122 | } | |
123 | #endif | |
124 | ||
125 | #endif |