ipsec: add support for chained buffers
[vpp.git] / src / plugins / unittest / crypto / crypto.h
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16
17 #ifndef included_unittest_crypto_crypto_h
18 #define included_unittest_crypto_crypto_h
19
20 #define CRYPTO_TEST_MAX_OP_CHUNKS 8
21
22 typedef struct
23 {
24   u32 length;
25   u8 *data;
26 } unittest_crypto_test_data_t;
27
28 typedef struct unittest_crypto_test_registration
29 {
30   char *name;
31   vnet_crypto_alg_t alg;
32   unittest_crypto_test_data_t iv, key, digest, plaintext, ciphertext, aad,
33     tag;
34   u8 is_chained;
35
36   /* plaintext and cipher text data used for testing chained buffers */
37   unittest_crypto_test_data_t pt_chunks[CRYPTO_TEST_MAX_OP_CHUNKS + 1];
38   unittest_crypto_test_data_t ct_chunks[CRYPTO_TEST_MAX_OP_CHUNKS + 1];
39
40   /* next */
41   struct unittest_crypto_test_registration *next;
42 } unittest_crypto_test_registration_t;
43
44
45 typedef struct
46 {
47   int verbose;
48
49   /* perf */
50   vnet_crypto_alg_t alg;
51   u32 warmup_rounds;
52   u32 rounds;
53   u32 buffer_size;
54   u32 n_buffers;
55
56   unittest_crypto_test_registration_t *test_registrations;
57 } crypto_test_main_t;
58
59 extern crypto_test_main_t crypto_test_main;
60
61 #define TEST_DATA(n) { .data = (u8 *) n, .length = sizeof (n)}
62 #define TEST_DATA_CHUNK(s,off,n) { .data = (u8 *) s + off, .length = n}
63
64 #define UNITTEST_REGISTER_CRYPTO_TEST(x)                                     \
65   unittest_crypto_test_registration_t __unittest_crypto_test_##x;            \
66 static void __clib_constructor                                               \
67 __unittest_crypto_test_registration_##x (void)                               \
68 {                                                                            \
69   crypto_test_main_t * cm = &crypto_test_main;                               \
70   __unittest_crypto_test_##x.next = cm->test_registrations;                  \
71     cm->test_registrations = & __unittest_crypto_test_##x;                   \
72 }                                                                            \
73 unittest_crypto_test_registration_t __unittest_crypto_test_##x
74
75 #endif
76
77 /*
78  * fd.io coding-style-patch-verification: ON
79  *
80  * Local Variables:
81  * eval: (c-set-style "gnu")
82  * End:
83  */