Rizin
unix-like reverse engineering framework and cli tools
sha2.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2000-2001, Aaron D. Gifford
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 /*
5  * FILE: sha2.h
6  * AUTHOR: Aaron D. Gifford <me@aarongifford.com>
7  *
8  * Copyright (c) 2000-2001, Aaron D. Gifford
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the copyright holder nor the names of contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 #ifndef __SHA2_H__
38 #define __SHA2_H__
39 #include <rz_types.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * Import u_intXX_t size_t type definitions from system headers. You
47  * may need to change this, or define these things yourself in this
48  * file.
49  */
50 #include <sys/types.h>
51 
52 #ifdef SHA2_USE_INTTYPES_H
53 
54 #include <inttypes.h>
55 
56 #endif /* SHA2_USE_INTTYPES_H */
57 
58 /*** SHA-256/384/512 Various Length Definitions ***********************/
59 #define SHA256_BLOCK_LENGTH 64
60 #define SHA256_DIGEST_LENGTH 32
61 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
62 #define SHA384_BLOCK_LENGTH 128
63 #define SHA384_DIGEST_LENGTH 48
64 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
65 #define SHA512_BLOCK_LENGTH 128
66 #define SHA512_DIGEST_LENGTH 64
67 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
68 
69 /*** SHA-256/384/512 Context Structures *******************************/
70 /* NOTE: If your architecture does not define either u_intXX_t types or
71  * uintXX_t (from inttypes.h), you may need to define things by hand
72  * for your system:
73  */
74 #ifndef u_int8_t
75 #define u_int8_t unsigned char
76 #define u_int32_t unsigned int
77 #define u_int64_t unsigned long long
78 #endif
79 /*
80  * Most BSD systems already define u_intXX_t types, as does Linux.
81  * Some systems, however, like Compaq's Trut64 Unix instead can use
82  * uintXX_t types defined by very recent ANSI C standards and included
83  * in the file:
84  *
85  * #include <inttypes.h>
86  *
87  * If you choose to use <inttypes.h> then please define:
88  *
89  * #define SHA2_USE_INTTYPES_H
90  *
91  * Or on the command line during compile:
92  *
93  * cc -DSHA2_USE_INTTYPES_H ...
94  */
95 
96 #define SHA256_BLOCK_LENGTH 64
97 typedef struct _SHA256_CTX {
98  ut32 state[8];
102 
103 #define SHA384_BLOCK_LENGTH 128
104 #define SHA512_BLOCK_LENGTH 128
105 typedef struct _SHA512_CTX {
111 
112 /*** SHA-256/384/512 Function Prototypes ******************************/
113 #ifndef NOPROTO
114 #ifdef SHA2_USE_INTTYPES_H
115 
116 void SHA256_Init(RZ_SHA256_CTX *);
117 void SHA256_Update(RZ_SHA256_CTX *, const uint8_t *, size_t);
119 char *SHA256_End(RZ_SHA256_CTX *, char *);
120 char *SHA256_Data(const uint8_t *, size_t, char *);
121 
122 void SHA384_Init(RZ_SHA384_CTX *);
123 void SHA384_Update(RZ_SHA384_CTX *, const uint8_t *, size_t);
125 char *SHA384_End(RZ_SHA384_CTX *, char *);
126 char *SHA384_Data(const uint8_t *, size_t, char *);
127 
128 void SHA512_Init(RZ_SHA512_CTX *);
129 void SHA512_Update(RZ_SHA512_CTX *, const uint8_t *, size_t);
131 char *SHA512_End(RZ_SHA512_CTX *, char *);
132 char *SHA512_Data(const uint8_t *, size_t, char *);
133 
134 #else /* SHA2_USE_INTTYPES_H */
135 
136 void SHA256_Init(RZ_SHA256_CTX *);
137 void SHA256_Update(RZ_SHA256_CTX *, const u_int8_t *, size_t);
139 char *SHA256_End(RZ_SHA256_CTX *, char *);
140 char *SHA256_Data(const u_int8_t *, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
141 
142 void SHA384_Init(RZ_SHA384_CTX *);
143 void SHA384_Update(RZ_SHA384_CTX *, const u_int8_t *, size_t);
145 char *SHA384_End(RZ_SHA384_CTX *, char *);
146 char *SHA384_Data(const u_int8_t *, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
147 
148 void SHA512_Init(RZ_SHA512_CTX *);
149 void SHA512_Update(RZ_SHA512_CTX *, const u_int8_t *, size_t);
151 char *SHA512_End(RZ_SHA512_CTX *, char *);
152 char *SHA512_Data(const u_int8_t *, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
153 
154 #endif /* SHA2_USE_INTTYPES_H */
155 
156 #else /* NOPROTO */
157 
158 void SHA256_Init(void);
159 void SHA256_Update(void);
160 void SHA256_Final(void);
161 char *SHA256_End(void);
162 char *SHA256_Data(void);
163 
164 void SHA384_Init(void);
165 void SHA384_Update(void);
166 void SHA384_Final(void);
167 char *SHA384_End(void);
168 char *SHA384_Data(void);
169 
170 void SHA512_Init(void);
171 void SHA512_Update(void);
172 void SHA512_Final(void);
173 char *SHA512_End(void);
174 char *SHA512_Data(void);
175 
176 #endif /* NOPROTO */
177 
178 #ifdef __cplusplus
179 }
180 #endif /* __cplusplus */
181 
182 #endif /* __SHA2_H__ */
uint32_t ut32
uint8_t ut8
Definition: lh5801.h:11
unsigned char uint8_t
Definition: sftypes.h:31
void SHA384_Init(RZ_SHA384_CTX *)
Definition: sha2.c:938
#define SHA256_DIGEST_STRING_LENGTH
Definition: sha2.h:61
void SHA512_Update(RZ_SHA512_CTX *, const u_int8_t *, size_t)
char * SHA384_Data(const u_int8_t *, size_t, char[SHA384_DIGEST_STRING_LENGTH])
void SHA256_Final(u_int8_t *, RZ_SHA256_CTX *)
void SHA256_Update(RZ_SHA256_CTX *, const u_int8_t *, size_t)
void SHA512_Final(u_int8_t *, RZ_SHA512_CTX *)
struct _SHA512_CTX RZ_SHA512_CTX
char * SHA256_End(RZ_SHA256_CTX *, char *)
char * SHA256_Data(const u_int8_t *, size_t, char[SHA256_DIGEST_STRING_LENGTH])
#define SHA384_DIGEST_STRING_LENGTH
Definition: sha2.h:64
char * SHA384_End(RZ_SHA384_CTX *, char *)
void SHA384_Update(RZ_SHA384_CTX *, const u_int8_t *, size_t)
#define SHA512_BLOCK_LENGTH
Definition: sha2.h:104
void SHA512_Init(RZ_SHA512_CTX *)
Definition: sha2.c:606
#define SHA512_DIGEST_STRING_LENGTH
Definition: sha2.h:67
void SHA384_Final(u_int8_t *, RZ_SHA384_CTX *)
RZ_SHA512_CTX RZ_SHA384_CTX
Definition: sha2.h:110
#define u_int8_t
Definition: sha2.h:75
struct _SHA256_CTX RZ_SHA256_CTX
char * SHA512_Data(const u_int8_t *, size_t, char[SHA512_DIGEST_STRING_LENGTH])
void SHA256_Init(RZ_SHA256_CTX *)
Definition: sha2.c:285
#define SHA256_BLOCK_LENGTH
Definition: sha2.h:96
char * SHA512_End(RZ_SHA512_CTX *, char *)
ut64 bitcount
Definition: sha2.h:99
ut64 bitcount[2]
Definition: sha2.h:107
Definition: buffer.h:15
Definition: dis.h:43
ut64(WINAPI *w32_GetEnabledXStateFeatures)()