d6a18efc818f3333c355fd8143fdc960edd052ea
[deb_dpdk.git] / drivers / crypto / aesni_gcm / aesni_gcm_ops.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _AESNI_GCM_OPS_H_
34 #define _AESNI_GCM_OPS_H_
35
36 #ifndef LINUX
37 #define LINUX
38 #endif
39
40 #include <gcm_defines.h>
41 #include <aux_funcs.h>
42
43 /** Supported vector modes */
44 enum aesni_gcm_vector_mode {
45         RTE_AESNI_GCM_NOT_SUPPORTED = 0,
46         RTE_AESNI_GCM_SSE,
47         RTE_AESNI_GCM_AVX,
48         RTE_AESNI_GCM_AVX2,
49         RTE_AESNI_GCM_VECTOR_NUM
50 };
51
52 enum aesni_gcm_key {
53         AESNI_GCM_KEY_128,
54         AESNI_GCM_KEY_192,
55         AESNI_GCM_KEY_256,
56         AESNI_GCM_KEY_NUM
57 };
58
59
60 typedef void (*aesni_gcm_t)(const struct gcm_key_data *gcm_key_data,
61                 struct gcm_context_data *gcm_ctx_data, uint8_t *out,
62                 const uint8_t *in, uint64_t plaintext_len, const uint8_t *iv,
63                 const uint8_t *aad, uint64_t aad_len,
64                 uint8_t *auth_tag, uint64_t auth_tag_len);
65
66 typedef void (*aesni_gcm_precomp_t)(const void *key, struct gcm_key_data *gcm_data);
67
68 typedef void (*aesni_gcm_init_t)(const struct gcm_key_data *gcm_key_data,
69                 struct gcm_context_data *gcm_ctx_data,
70                 const uint8_t *iv,
71                 uint8_t const *aad,
72                 uint64_t aad_len);
73
74 typedef void (*aesni_gcm_update_t)(const struct gcm_key_data *gcm_key_data,
75                 struct gcm_context_data *gcm_ctx_data,
76                 uint8_t *out,
77                 const uint8_t *in,
78                 uint64_t plaintext_len);
79
80 typedef void (*aesni_gcm_finalize_t)(const struct gcm_key_data *gcm_key_data,
81                 struct gcm_context_data *gcm_ctx_data,
82                 uint8_t *auth_tag,
83                 uint64_t auth_tag_len);
84
85 /** GCM library function pointer table */
86 struct aesni_gcm_ops {
87         aesni_gcm_t enc;        /**< GCM encode function pointer */
88         aesni_gcm_t dec;        /**< GCM decode function pointer */
89         aesni_gcm_precomp_t precomp;    /**< GCM pre-compute */
90         aesni_gcm_init_t init;
91         aesni_gcm_update_t update_enc;
92         aesni_gcm_update_t update_dec;
93         aesni_gcm_finalize_t finalize;
94 };
95
96 #define AES_GCM_FN(keylen, arch) \
97 aes_gcm_enc_##keylen##_##arch,\
98 aes_gcm_dec_##keylen##_##arch,\
99 aes_gcm_pre_##keylen##_##arch,\
100 aes_gcm_init_##keylen##_##arch,\
101 aes_gcm_enc_##keylen##_update_##arch,\
102 aes_gcm_dec_##keylen##_update_##arch,\
103 aes_gcm_enc_##keylen##_finalize_##arch,
104
105 static const struct aesni_gcm_ops gcm_ops[RTE_AESNI_GCM_VECTOR_NUM][AESNI_GCM_KEY_NUM] = {
106         [RTE_AESNI_GCM_NOT_SUPPORTED] = {
107                 [AESNI_GCM_KEY_128] = {NULL},
108                 [AESNI_GCM_KEY_192] = {NULL},
109                 [AESNI_GCM_KEY_256] = {NULL}
110         },
111         [RTE_AESNI_GCM_SSE] = {
112                 [AESNI_GCM_KEY_128] = {
113                         AES_GCM_FN(128, sse)
114                 },
115                 [AESNI_GCM_KEY_192] = {
116                         AES_GCM_FN(192, sse)
117                 },
118                 [AESNI_GCM_KEY_256] = {
119                         AES_GCM_FN(256, sse)
120                 }
121         },
122         [RTE_AESNI_GCM_AVX] = {
123                 [AESNI_GCM_KEY_128] = {
124                         AES_GCM_FN(128, avx_gen2)
125                 },
126                 [AESNI_GCM_KEY_192] = {
127                         AES_GCM_FN(192, avx_gen2)
128                 },
129                 [AESNI_GCM_KEY_256] = {
130                         AES_GCM_FN(256, avx_gen2)
131                 }
132         },
133         [RTE_AESNI_GCM_AVX2] = {
134                 [AESNI_GCM_KEY_128] = {
135                         AES_GCM_FN(128, avx_gen4)
136                 },
137                 [AESNI_GCM_KEY_192] = {
138                         AES_GCM_FN(192, avx_gen4)
139                 },
140                 [AESNI_GCM_KEY_256] = {
141                         AES_GCM_FN(256, avx_gen4)
142                 }
143         }
144 };
145 #endif /* _AESNI_GCM_OPS_H_ */