crypto: implement rfc4231 test cases
[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 typedef struct
21 {
22   u32 length;
23   u8 *data;
24 } unittest_crypto_test_data_t;
25
26 typedef struct unittest_crypto_test_registration
27 {
28   char *name;
29   vnet_crypto_alg_t alg:8;
30   vnet_crypto_op_type_t op:8;
31   unittest_crypto_test_data_t iv, key, data, expected;
32   u8 hmac_trunc_len;
33
34   /* next */
35   struct unittest_crypto_test_registration *next;
36 } unittest_crypto_test_registration_t;
37
38
39 typedef struct
40 {
41   int verbose;
42   unittest_crypto_test_registration_t *test_registrations;
43 } crypto_test_main_t;
44
45 extern crypto_test_main_t crypto_test_main;
46
47 #define TEST_DATA(n) { .data = (u8 *) n, .length = sizeof (n)}
48
49 #define UNITTEST_REGISTER_CRYPTO_TEST(x)                                     \
50   unittest_crypto_test_registration_t __unittest_crypto_test_##x;            \
51 static void __clib_constructor                                               \
52 __unittest_crypto_test_registration_##x (void)                               \
53 {                                                                            \
54   crypto_test_main_t * cm = &crypto_test_main;                               \
55   __unittest_crypto_test_##x.next = cm->test_registrations;                  \
56     cm->test_registrations = & __unittest_crypto_test_##x;                   \
57 }                                                                            \
58 unittest_crypto_test_registration_t __unittest_crypto_test_##x
59
60 #endif
61
62 /*
63  * fd.io coding-style-patch-verification: ON
64  *
65  * Local Variables:
66  * eval: (c-set-style "gnu")
67  * End:
68  */