Kagome
Polkadot Runtime Engine in C++17
blake2b.h
Go to the documentation of this file.
1 
6 // taken from here
7 // https://github.com/mjosaarinen/blake2_mjosref/blob/master/blake2b.h
8 
9 #ifndef CORE_BLAKE2B_H
10 #define CORE_BLAKE2B_H
11 
12 #include <cstddef>
13 #include <cstdint>
14 
15 namespace kagome::crypto {
16 
17  // state context
18  typedef struct {
19  uint8_t b[128]; // input buffer
20  uint64_t h[8]; // chained state
21  uint64_t t[2]; // total number of bytes
22  size_t c; // pointer for b[]
23  size_t outlen; // digest size
24  } blake2b_ctx;
25 
26  // Initialize the hashing context "ctx" with optional key "key".
27  // 1 <= outlen <= 64 gives the digest size in bytes.
28  // Secret key (also <= 64 bytes) is optional (keylen = 0).
29  int blake2b_init(blake2b_ctx *ctx,
30  size_t outlen,
31  const void *key,
32  size_t keylen); // secret key
33 
34  // Add "inlen" bytes from "in" into the hash.
35  void blake2b_update(blake2b_ctx *ctx, // context
36  const void *in,
37  size_t inlen); // data to be hashed
38 
39  // Generate the message digest (size given in init).
40  // Result placed in "out".
41  void blake2b_final(blake2b_ctx *ctx, void *out);
42 
43  // All-in-one convenience function.
44  int blake2b(void *out,
45  size_t outlen, // return buffer for digest
46  const void *key,
47  size_t keylen, // optional secret key
48  const void *in,
49  size_t inlen); // data to be hashed
50 
51 } // namespace kagome::crypto
52 
53 #endif
int blake2b_init(blake2b_ctx *ctx, size_t outlen, const void *key, size_t keylen)
Definition: blake2b.cpp:113
int blake2b(void *out, size_t outlen, const void *key, size_t keylen, const void *in, size_t inlen)
Definition: blake2b.cpp:190
void blake2b_final(blake2b_ctx *ctx, void *out)
Definition: blake2b.cpp:169
void blake2b_update(blake2b_ctx *ctx, const void *in, size_t inlen)
Definition: blake2b.cpp:147