3c8ec70e93df9bde2e1d116fa65d57c8c9795d88
[openssl.git] / crypto / ec / curve448 / decaf / sha512.h
1 /**
2  * @file decaf/shake.h
3  * @copyright Public domain.
4  * @author Mike Hamburg
5  * @brief SHA2-512
6  */
7
8 #ifndef __DECAF_SHA512_H__
9 #define __DECAF_SHA512_H__
10
11 #include <stdint.h>
12 #include <sys/types.h>
13 #include <stdlib.h> /* for NULL */
14
15 #include <decaf/common.h>
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20     
21
22 typedef struct decaf_sha512_ctx_s {
23     uint64_t state[8];
24     uint8_t block[128];
25     uint64_t bytes_processed;
26 } decaf_sha512_ctx_s, decaf_sha512_ctx_t[1];
27
28 void decaf_sha512_init(decaf_sha512_ctx_t ctx) DECAF_NONNULL DECAF_API_VIS;
29 void decaf_sha512_update(decaf_sha512_ctx_t ctx, const uint8_t *message, size_t length) DECAF_NONNULL DECAF_API_VIS;
30 void decaf_sha512_final(decaf_sha512_ctx_t ctx, uint8_t *out, size_t length) DECAF_NONNULL DECAF_API_VIS;
31
32 static inline void decaf_sha512_destroy(decaf_sha512_ctx_t ctx) {
33     decaf_bzero(ctx,sizeof(*ctx));
34 }
35
36 static inline void decaf_sha512_hash(
37     uint8_t *output,
38     size_t output_len,
39     const uint8_t *message,
40     size_t message_len
41 ) {
42     decaf_sha512_ctx_t ctx;
43     decaf_sha512_init(ctx);
44     decaf_sha512_update(ctx,message,message_len);
45     decaf_sha512_final(ctx,output,output_len);
46     decaf_sha512_destroy(ctx);
47 }
48
49 #ifdef __cplusplus
50 } /* extern "C" */
51 #endif
52     
53 #endif /* __DECAF_SHA512_H__ */