Debian Codegraph @

nbcompat/sha2.h

raw
1 /*
2 * sha2.h
3 *
4 * Version 1.0.0beta1
5 *
6 * Written by Aaron D. Gifford <[email protected]>
7 *
8 * Copyright 2000 Aaron D. Gifford. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the copyright holder nor the names of contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35
36 #ifndef NBCOMPAT_SHA2_H_
37 #define NBCOMPAT_SHA2_H_
38
39 #include <nbcompat/types.h>
40
41 #if defined(HAVE_NBCOMPAT_SHA2)
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /*** SHA-256/384/512 Various Length Definitions ***********************/
48 #define SHA256_BLOCK_LENGTH 64
49 #define SHA256_DIGEST_LENGTH 32
50 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
51 #define SHA384_BLOCK_LENGTH 128
52 #define SHA384_DIGEST_LENGTH 48
53 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
54 #define SHA512_BLOCK_LENGTH 128
55 #define SHA512_DIGEST_LENGTH 64
56 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
57
58
59 /*** SHA-256/384/512 Context Structures *******************************/
60 typedef struct _SHA256_CTX {
61 uint32_t state[8];
62 uint64_t bitcount;
63 uint8_t buffer[SHA256_BLOCK_LENGTH];
64 } SHA256_CTX;
65 typedef struct _SHA512_CTX {
66 uint64_t state[8];
67 uint64_t bitcount[2];
68 uint8_t buffer[SHA512_BLOCK_LENGTH];
69 } SHA512_CTX;
70
71 typedef SHA512_CTX SHA384_CTX;
72
73
74 /*** SHA-256/384/512 Function Prototypes ******************************/
75 #define SHA256_Init nbcompat_SHA256_Init
76 #define SHA256_Update nbcompat_SHA256_Update
77 #define SHA256_Final nbcompat_SHA256_Final
78 #define SHA256_End nbcompat_SHA256_End
79 #define SHA256_Data nbcompat_SHA256_Data
80 #define SHA256_File nbcompat_SHA256_File
81
82 void SHA256_Init(SHA256_CTX *);
83 void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
84 void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
85 char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
86 char* SHA256_Data(const uint8_t*, size_t, uint8_t *);
87 char *SHA256_File(char *, char *);
88
89 #define SHA384_Init nbcompat_SHA384_Init
90 #define SHA384_Update nbcompat_SHA384_Update
91 #define SHA384_Final nbcompat_SHA384_Final
92 #define SHA384_End nbcompat_SHA384_End
93 #define SHA384_Data nbcompat_SHA384_Data
94 #define SHA384_File nbcompat_SHA384_File
95
96 void SHA384_Init(SHA384_CTX*);
97 void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
98 void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
99 char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
100 char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
101 char *SHA384_File(char *, char *);
102
103 #define SHA512_Init nbcompat_SHA512_Init
104 #define SHA512_Update nbcompat_SHA512_Update
105 #define SHA512_Final nbcompat_SHA512_Final
106 #define SHA512_End nbcompat_SHA512_End
107 #define SHA512_Data nbcompat_SHA512_Data
108 #define SHA512_File nbcompat_SHA512_File
109
110 void SHA512_Init(SHA512_CTX*);
111 void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
112 void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
113 char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
114 char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
115 char *SHA512_File(char *, char *);
116
117 #ifdef __cplusplus
118 }
119 #endif /* __cplusplus */
120
121 #else /* HAVE_NBCOMPAT_SHA2 */
122 #include <sha2.h>
123 #endif /* HAVE_NBCOMPAT_SHA2 */
124
125 #endif /* NBCOMPAT_SHA2_H_ */