Some initial work to use the MUtilities library.
[simple-x264-launcher.git] / src / 3rd_party / blake2.h
blob09333525d4dd7b22eb52b66b309b1f5a6f7a7415
1 /*
2 BLAKE2 reference source code package - reference C implementations
4 Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
6 To the extent possible under law, the author(s) have dedicated all copyright
7 and related and neighboring rights to this software to the public domain
8 worldwide. This software is distributed without any warranty.
10 You should have received a copy of the CC0 Public Domain Dedication along with
11 this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13 #pragma once
14 #ifndef __BLAKE2_H__
15 #define __BLAKE2_H__
17 #include <stddef.h>
18 #include <stdint.h>
20 #if defined(_MSC_VER)
21 #define ALIGN(x) __declspec(align(x))
22 #ifndef __cplusplus
23 #define inline __inline
24 #endif
25 #else
26 #define ALIGN(x) __attribute__((aligned(x)))
27 #endif
29 #if defined(__cplusplus)
30 extern "C" {
31 #endif
33 enum blake2b_constant
35 BLAKE2B_BLOCKBYTES = 128,
36 BLAKE2B_OUTBYTES = 64,
37 BLAKE2B_KEYBYTES = 64,
38 BLAKE2B_SALTBYTES = 16,
39 BLAKE2B_PERSONALBYTES = 16
42 #pragma pack(push, 1)
43 typedef struct __blake2b_param
45 uint8_t digest_length; // 1
46 uint8_t key_length; // 2
47 uint8_t fanout; // 3
48 uint8_t depth; // 4
49 uint32_t leaf_length; // 8
50 uint64_t node_offset; // 16
51 uint8_t node_depth; // 17
52 uint8_t inner_length; // 18
53 uint8_t reserved[14]; // 32
54 uint8_t salt[BLAKE2B_SALTBYTES]; // 48
55 uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64
56 } blake2b_param;
58 ALIGN( 64 ) typedef struct __blake2b_state
60 uint64_t h[8];
61 uint64_t t[2];
62 uint64_t f[2];
63 uint8_t buf[2 * BLAKE2B_BLOCKBYTES];
64 size_t buflen;
65 uint8_t last_node;
66 } blake2b_state;
67 #pragma pack(pop)
69 // Streaming API
70 int blake2b_init( blake2b_state *S, const uint8_t outlen );
71 int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
72 int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
73 int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen );
74 int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen );
76 // Simple API
77 int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
79 static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
81 return blake2b( out, in, key, outlen, inlen, keylen );
84 #if defined(__cplusplus)
86 #endif
88 #endif