2 * Copyright (c) 2020 Doc.ai and/or its affiliates.
3 * Copyright (c) 2012 Samuel Neves <sneves@dei.uc.pt>.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 More information about the BLAKE2 hash function can be found at
21 #ifndef __included_crypto_blake2s_h__
22 #define __included_crypto_blake2s_h__
24 #include <vlib/vlib.h>
27 #define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
29 #define BLAKE2_PACKED(x) x __attribute__((packed))
34 BLAKE2S_BLOCK_BYTES = 64,
35 BLAKE2S_OUT_BYTES = 32,
36 BLAKE2S_KEY_BYTES = 32,
37 BLAKE2S_HASH_SIZE = BLAKE2S_OUT_BYTES,
38 BLAKE2S_SALT_BYTES = 8,
39 BLAKE2S_PERSONAL_BYTES = 8
42 typedef struct blake2s_state
47 uint8_t buf[BLAKE2S_BLOCK_BYTES];
53 BLAKE2_PACKED (struct blake2s_param
55 uint8_t digest_length; /* 1 */
56 uint8_t key_length; /* 2 */
57 uint8_t fanout; /* 3 */
58 uint8_t depth; /* 4 */
59 uint32_t leaf_length; /* 8 */
60 uint32_t node_offset; /* 12 */
61 uint16_t xof_length; /* 14 */
62 uint8_t node_depth; /* 15 */
63 uint8_t inner_length; /* 16 */
64 /* uint8_t reserved[0]; */
65 uint8_t salt[BLAKE2S_SALT_BYTES]; /* 24 */
66 uint8_t personal[BLAKE2S_PERSONAL_BYTES]; /* 32 */
69 typedef struct blake2s_param blake2s_param_t;
72 int blake2s_init (blake2s_state_t * S, size_t outlen);
73 int blake2s_init_key (blake2s_state_t * S, size_t outlen, const void *key,
75 int blake2s_init_param (blake2s_state_t * S, const blake2s_param_t * P);
76 int blake2s_update (blake2s_state_t * S, const void *in, size_t inlen);
77 int blake2s_final (blake2s_state_t * S, void *out, size_t outlen);
79 int blake2s (void *out, size_t outlen, const void *in, size_t inlen,
80 const void *key, size_t keylen);
82 #endif /* __included_crypto_blake2s_h__ */
85 * fd.io coding-style-patch-verification: ON
88 * eval: (c-set-style "gnu")