Embedded SDK
Embedded SDK
cx_blake3.h
Go to the documentation of this file.
1 #ifdef HAVE_BLAKE3
2 
3 #ifndef CX_BLAKE3_H
4 #define CX_BLAKE3_H
5 
6 #include "lcx_blake3.h"
7 #include <stddef.h>
8 #include <stdint.h>
9 #include "cx_errors.h"
10 
11 #define BLAKE3_KEY_LEN 32
12 #define BLAKE3_CHUNK_LEN 1024
13 
14 enum blake3_flags {
15  CHUNK_START = 1 << 0,
16  CHUNK_END = 1 << 1,
17  PARENT = 1 << 2,
18  ROOT = 1 << 3,
19  KEYED_HASH = 1 << 4,
20  DERIVE_KEY_CONTEXT = 1 << 5,
21  DERIVE_KEY_MATERIAL = 1 << 6,
22  LAST = 1 << 7,
23 };
24 
25 typedef struct {
26  uint32_t input_cv[BLAKE3_NB_OF_WORDS];
27  uint64_t counter;
28  uint8_t block[BLAKE3_BLOCK_LEN];
29  uint8_t block_len;
30  uint8_t d;
31 } cx_blake3_state_out_t;
32 
33 // Initialization vectors
34 static const uint32_t IV[8] = {0x6A09E667UL,
35  0xBB67AE85UL,
36  0x3C6EF372UL,
37  0xA54FF53AUL,
38  0x510E527FUL,
39  0x9B05688CUL,
40  0x1F83D9ABUL,
41  0x5BE0CD19UL};
42 // Permutational key schedule used to permute the message words after each round
43 // of the compression function
44 static const uint8_t MSG_SCHEDULE[7][16] = {
45  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
46  {2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8 },
47  {3, 4, 10, 12, 13, 2, 7, 14, 6, 5, 9, 0, 11, 15, 8, 1 },
48  {10, 7, 12, 9, 14, 3, 13, 15, 4, 0, 11, 2, 5, 8, 1, 6 },
49  {12, 13, 9, 11, 15, 10, 14, 8, 7, 2, 5, 3, 0, 1, 6, 4 },
50  {9, 14, 11, 5, 8, 12, 15, 1, 13, 3, 0, 10, 2, 6, 4, 7 },
51  {11, 15, 5, 0, 1, 9, 8, 6, 14, 10, 2, 12, 3, 4, 7, 13}
52 };
53 
54 #endif // CX_BLAKE3_H
55 #endif // HAVE_BLAKE3
BLAKE3 hash function.
unsigned char uint8_t
Definition: usbd_conf.h:53