6 * Written by Aaron D. Gifford <me@aarongifford.com>
8 * Copyright 2000 Aaron D. Gifford. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
39 #ifdef HAVE_INTTYPES_H
55 typedef uint8_t sha2_byte
; /* Exactly 1 byte */
56 typedef uint32_t sha2_word32
; /* Exactly 4 bytes */
57 typedef uint64_t sha2_word64
; /* Exactly 8 bytes */
59 /*** SHA-256/384/512 Various Length Definitions ***********************/
60 #define SHA256_BLOCK_LENGTH 64
61 #define SHA256_DIGEST_LENGTH 32
62 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
63 #define SHA384_BLOCK_LENGTH 128
64 #define SHA384_DIGEST_LENGTH 48
65 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
66 #define SHA512_BLOCK_LENGTH 128
67 #define SHA512_DIGEST_LENGTH 64
68 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
71 /*** SHA-256/384/512 Context Structures *******************************/
72 typedef struct _SHA256_CTX
{
75 uint8_t buffer
[SHA256_BLOCK_LENGTH
];
77 typedef struct _SHA512_CTX
{
80 uint8_t buffer
[SHA512_BLOCK_LENGTH
];
83 typedef SHA512_CTX SHA384_CTX
;
86 void SHA256_Init(SHA256_CTX
*);
87 void SHA256_Update(SHA256_CTX
*, const uint8_t*, size_t);
88 void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH
], SHA256_CTX
*);
89 char* SHA256_End(SHA256_CTX
*, char[SHA256_DIGEST_STRING_LENGTH
]);
90 char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH
]);
91 char *SHA256_File(char *, char *);
93 void SHA384_Init(SHA384_CTX
*);
94 void SHA384_Update(SHA384_CTX
*, const uint8_t*, size_t);
95 void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH
], SHA384_CTX
*);
96 char* SHA384_End(SHA384_CTX
*, char[SHA384_DIGEST_STRING_LENGTH
]);
97 char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH
]);
98 char *SHA384_File(char *, char *);
100 void SHA512_Init(SHA512_CTX
*);
101 void SHA512_Update(SHA512_CTX
*, const uint8_t*, size_t);
102 void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH
], SHA512_CTX
*);
103 char* SHA512_End(SHA512_CTX
*, char[SHA512_DIGEST_STRING_LENGTH
]);
104 char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH
]);
105 char *SHA512_File(char *, char *);
109 #endif /* __cplusplus */
111 #endif /* __SHA2_H__ */