libdecaf
sha512.h
1 
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 
22 typedef struct decaf_sha512_ctx_s {
24  uint64_t state[8];
25  uint8_t block[128];
26  uint64_t bytes_processed;
27  /* @endcond */
28 } decaf_sha512_ctx_s, decaf_sha512_ctx_t[1];
29 
31 void DECAF_API_VIS decaf_sha512_init(decaf_sha512_ctx_t ctx) DECAF_NONNULL;
32 
34 void DECAF_API_VIS decaf_sha512_update(decaf_sha512_ctx_t ctx, const uint8_t *message, size_t message_len) DECAF_NONNULL;
35 
41 void DECAF_API_VIS decaf_sha512_final(decaf_sha512_ctx_t ctx, uint8_t *output, size_t output_len) DECAF_NONNULL;
42 
44 static inline void decaf_sha512_destroy(decaf_sha512_ctx_t ctx) {
45  decaf_bzero(ctx,sizeof(*ctx));
46 }
47 
54 static inline void decaf_sha512_hash(
55  uint8_t *output,
56  size_t output_len,
57  const uint8_t *message,
58  size_t message_len
59 ) {
60  decaf_sha512_ctx_t ctx;
61  decaf_sha512_init(ctx);
62  decaf_sha512_update(ctx,message,message_len);
63  decaf_sha512_final(ctx,output,output_len);
64  decaf_sha512_destroy(ctx);
65 }
66 
67 #ifdef __cplusplus
68 } /* extern "C" */
69 #endif
70 
71 #endif /* __DECAF_SHA512_H__ */
Hash context for SHA-512.
Definition: sha512.h:22
void DECAF_API_VIS decaf_bzero(void *data, size_t size) DECAF_NONNULL
Overwrite data with zeros.
Common utility headers for Decaf library.