FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
blake2s.h
Go to the documentation of this file.
1 /*
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:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  More information about the BLAKE2 hash function can be found at
18  https://blake2.net.
19 */
20 
21 #ifndef __included_crypto_blake2s_h__
22 #define __included_crypto_blake2s_h__
23 
24 #include <vlib/vlib.h>
25 
26 #if defined(_MSC_VER)
27 #define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
28 #else
29 #define BLAKE2_PACKED(x) x __attribute__((packed))
30 #endif
31 
33 {
40 };
41 
42 typedef struct blake2s_state
43 {
44  uint32_t h[8];
45  uint32_t t[2];
46  uint32_t f[2];
48  size_t buflen;
49  size_t outlen;
50  uint8_t last_node;
52 
53 BLAKE2_PACKED (struct blake2s_param
54  {
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 */
67  });
68 
69 typedef struct blake2s_param blake2s_param_t;
70 
71 /* Streaming API */
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,
74  size_t keylen);
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);
78 
79 int blake2s (void *out, size_t outlen, const void *in, size_t inlen,
80  const void *key, size_t keylen);
81 
82 #endif /* __included_crypto_blake2s_h__ */
83 
84 /*
85  * fd.io coding-style-patch-verification: ON
86  *
87  * Local Variables:
88  * eval: (c-set-style "gnu")
89  * End:
90  */
int blake2s_init(blake2s_state_t *S, size_t outlen)
Definition: blake2s.c:105
uint32_t h[8]
Definition: blake2s.h:44
int blake2s_init_key(blake2s_state_t *S, size_t outlen, const void *key, size_t keylen)
Definition: blake2s.c:129
blake2s_constant
Definition: blake2s.h:32
#define S(mp)
struct blake2s_param blake2s_param_t
Definition: blake2s.h:69
uint8_t last_node
Definition: blake2s.h:50
int blake2s_final(blake2s_state_t *S, void *out, size_t outlen)
Definition: blake2s.c:267
size_t buflen
Definition: blake2s.h:48
uint32_t f[2]
Definition: blake2s.h:46
#define P(fmt,...)
u32 salt
size_t outlen
Definition: blake2s.h:49
int blake2s_update(blake2s_state_t *S, const void *in, size_t inlen)
Definition: blake2s.c:237
uint32_t t[2]
Definition: blake2s.h:45
typedef key
Definition: ipsec_types.api:85
#define BLAKE2_PACKED(x)
Definition: blake2s.h:29
int blake2s(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
Definition: blake2s.c:292
int blake2s_init_param(blake2s_state_t *S, const blake2s_param_t *P)
Definition: blake2s.c:87
uint8_t buf[BLAKE2S_BLOCK_BYTES]
Definition: blake2s.h:47
struct blake2s_state blake2s_state_t