Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 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 | #ifndef included_vnet_crypto_crypto_h |
| 17 | #define included_vnet_crypto_crypto_h |
| 18 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 19 | #include <vlib/vlib.h> |
| 20 | |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 21 | #define VNET_CRYPTO_FRAME_SIZE 64 |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 22 | |
Benoît Ganne | be95444 | 2019-04-29 16:05:46 +0200 | [diff] [blame] | 23 | /* CRYPTO_ID, PRETTY_NAME, KEY_LENGTH_IN_BYTES */ |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 24 | #define foreach_crypto_cipher_alg \ |
Benoît Ganne | be95444 | 2019-04-29 16:05:46 +0200 | [diff] [blame] | 25 | _(DES_CBC, "des-cbc", 7) \ |
Neale Ranns | e6be702 | 2019-06-04 15:37:34 +0000 | [diff] [blame] | 26 | _(3DES_CBC, "3des-cbc", 24) \ |
Benoît Ganne | be95444 | 2019-04-29 16:05:46 +0200 | [diff] [blame] | 27 | _(AES_128_CBC, "aes-128-cbc", 16) \ |
| 28 | _(AES_192_CBC, "aes-192-cbc", 24) \ |
| 29 | _(AES_256_CBC, "aes-256-cbc", 32) \ |
| 30 | _(AES_128_CTR, "aes-128-ctr", 16) \ |
| 31 | _(AES_192_CTR, "aes-192-ctr", 24) \ |
| 32 | _(AES_256_CTR, "aes-256-ctr", 32) |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 33 | |
Benoît Ganne | be95444 | 2019-04-29 16:05:46 +0200 | [diff] [blame] | 34 | /* CRYPTO_ID, PRETTY_NAME, KEY_LENGTH_IN_BYTES */ |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 35 | #define foreach_crypto_aead_alg \ |
Benoît Ganne | be95444 | 2019-04-29 16:05:46 +0200 | [diff] [blame] | 36 | _(AES_128_GCM, "aes-128-gcm", 16) \ |
| 37 | _(AES_192_GCM, "aes-192-gcm", 24) \ |
Artem Glazychev | 61f49aa | 2020-08-31 15:37:39 +0700 | [diff] [blame] | 38 | _(AES_256_GCM, "aes-256-gcm", 32) \ |
| 39 | _(CHACHA20_POLY1305, "chacha20-poly1305", 32) |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 40 | |
| 41 | #define foreach_crypto_hmac_alg \ |
Filip Tehlar | e225f71 | 2019-03-19 10:37:06 -0700 | [diff] [blame] | 42 | _(MD5, "md5") \ |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 43 | _(SHA1, "sha-1") \ |
| 44 | _(SHA224, "sha-224") \ |
| 45 | _(SHA256, "sha-256") \ |
| 46 | _(SHA384, "sha-384") \ |
| 47 | _(SHA512, "sha-512") |
| 48 | |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 49 | #define foreach_crypto_op_type \ |
| 50 | _(ENCRYPT, "encrypt") \ |
| 51 | _(DECRYPT, "decrypt") \ |
| 52 | _(AEAD_ENCRYPT, "aead-encrypt") \ |
| 53 | _(AEAD_DECRYPT, "aead-decrypt") \ |
| 54 | _(HMAC, "hmac") |
| 55 | |
| 56 | typedef enum |
| 57 | { |
| 58 | #define _(n, s) VNET_CRYPTO_OP_TYPE_##n, |
| 59 | foreach_crypto_op_type |
| 60 | #undef _ |
| 61 | VNET_CRYPTO_OP_N_TYPES, |
| 62 | } vnet_crypto_op_type_t; |
| 63 | |
| 64 | #define foreach_crypto_op_status \ |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 65 | _(IDLE, "idle") \ |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 66 | _(PENDING, "pending") \ |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 67 | _(WORK_IN_PROGRESS, "work-in-progress") \ |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 68 | _(COMPLETED, "completed") \ |
| 69 | _(FAIL_NO_HANDLER, "no-handler") \ |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 70 | _(FAIL_BAD_HMAC, "bad-hmac") \ |
| 71 | _(FAIL_ENGINE_ERR, "engine-error") |
| 72 | |
| 73 | /** async crypto **/ |
| 74 | |
| 75 | /* CRYPTO_ID, PRETTY_NAME, KEY_LENGTH_IN_BYTES, TAG_LEN, AAD_LEN */ |
| 76 | #define foreach_crypto_aead_async_alg \ |
| 77 | _(AES_128_GCM, "aes-128-gcm-aad8", 16, 16, 8) \ |
| 78 | _(AES_128_GCM, "aes-128-gcm-aad12", 16, 16, 12) \ |
| 79 | _(AES_192_GCM, "aes-192-gcm-aad8", 24, 16, 8) \ |
| 80 | _(AES_192_GCM, "aes-192-gcm-aad12", 24, 16, 12) \ |
| 81 | _(AES_256_GCM, "aes-256-gcm-aad8", 32, 16, 8) \ |
Artem Glazychev | 61f49aa | 2020-08-31 15:37:39 +0700 | [diff] [blame] | 82 | _(AES_256_GCM, "aes-256-gcm-aad12", 32, 16, 12) \ |
| 83 | _(CHACHA20_POLY1305, "chacha20-poly1305-aad8", 32, 16, 8) \ |
| 84 | _(CHACHA20_POLY1305, "chacha20-poly1305-aad12", 32, 16, 12) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 85 | |
| 86 | /* CRYPTO_ID, INTEG_ID, PRETTY_NAME, KEY_LENGTH_IN_BYTES, DIGEST_LEN */ |
Benoît Ganne | 40ee200 | 2021-01-22 18:09:40 +0100 | [diff] [blame] | 87 | #define foreach_crypto_link_async_alg \ |
| 88 | _ (AES_128_CBC, SHA1, "aes-128-cbc-hmac-sha-1", 16, 12) \ |
| 89 | _ (AES_192_CBC, SHA1, "aes-192-cbc-hmac-sha-1", 24, 12) \ |
| 90 | _ (AES_256_CBC, SHA1, "aes-256-cbc-hmac-sha-1", 32, 12) \ |
| 91 | _ (AES_128_CBC, SHA224, "aes-128-cbc-hmac-sha-224", 16, 14) \ |
| 92 | _ (AES_192_CBC, SHA224, "aes-192-cbc-hmac-sha-224", 24, 14) \ |
| 93 | _ (AES_256_CBC, SHA224, "aes-256-cbc-hmac-sha-224", 32, 14) \ |
| 94 | _ (AES_128_CBC, SHA256, "aes-128-cbc-hmac-sha-256", 16, 16) \ |
| 95 | _ (AES_192_CBC, SHA256, "aes-192-cbc-hmac-sha-256", 24, 16) \ |
| 96 | _ (AES_256_CBC, SHA256, "aes-256-cbc-hmac-sha-256", 32, 16) \ |
| 97 | _ (AES_128_CBC, SHA384, "aes-128-cbc-hmac-sha-384", 16, 24) \ |
| 98 | _ (AES_192_CBC, SHA384, "aes-192-cbc-hmac-sha-384", 24, 24) \ |
| 99 | _ (AES_256_CBC, SHA384, "aes-256-cbc-hmac-sha-384", 32, 24) \ |
| 100 | _ (AES_128_CBC, SHA512, "aes-128-cbc-hmac-sha-512", 16, 32) \ |
| 101 | _ (AES_192_CBC, SHA512, "aes-192-cbc-hmac-sha-512", 24, 32) \ |
| 102 | _ (AES_256_CBC, SHA512, "aes-256-cbc-hmac-sha-512", 32, 32) \ |
| 103 | _ (AES_128_CTR, SHA1, "aes-128-ctr-hmac-sha-1", 16, 12) \ |
| 104 | _ (AES_192_CTR, SHA1, "aes-192-ctr-hmac-sha-1", 24, 12) \ |
| 105 | _ (AES_256_CTR, SHA1, "aes-256-ctr-hmac-sha-1", 32, 12) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 106 | |
| 107 | #define foreach_crypto_async_op_type \ |
| 108 | _(ENCRYPT, "async-encrypt") \ |
| 109 | _(DECRYPT, "async-decrypt") |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 110 | |
| 111 | typedef enum |
| 112 | { |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 113 | VNET_CRYPTO_KEY_OP_ADD, |
| 114 | VNET_CRYPTO_KEY_OP_DEL, |
| 115 | VNET_CRYPTO_KEY_OP_MODIFY, |
| 116 | } vnet_crypto_key_op_t; |
| 117 | |
| 118 | typedef enum |
| 119 | { |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 120 | #define _(n, s) VNET_CRYPTO_OP_STATUS_##n, |
| 121 | foreach_crypto_op_status |
| 122 | #undef _ |
| 123 | VNET_CRYPTO_OP_N_STATUS, |
| 124 | } vnet_crypto_op_status_t; |
| 125 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 126 | /* *INDENT-OFF* */ |
| 127 | typedef enum |
| 128 | { |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 129 | VNET_CRYPTO_ALG_NONE = 0, |
Benoît Ganne | be95444 | 2019-04-29 16:05:46 +0200 | [diff] [blame] | 130 | #define _(n, s, l) VNET_CRYPTO_ALG_##n, |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 131 | foreach_crypto_cipher_alg |
| 132 | foreach_crypto_aead_alg |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 133 | #undef _ |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 134 | #define _(n, s) VNET_CRYPTO_ALG_HMAC_##n, |
| 135 | foreach_crypto_hmac_alg |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 136 | #undef _ |
| 137 | VNET_CRYPTO_N_ALGS, |
| 138 | } vnet_crypto_alg_t; |
| 139 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 140 | typedef enum |
| 141 | { |
| 142 | #define _(n, s) VNET_CRYPTO_ASYNC_OP_TYPE_##n, |
| 143 | foreach_crypto_async_op_type |
| 144 | #undef _ |
| 145 | VNET_CRYPTO_ASYNC_OP_N_TYPES, |
| 146 | } vnet_crypto_async_op_type_t; |
| 147 | |
| 148 | typedef enum |
| 149 | { |
| 150 | VNET_CRYPTO_ASYNC_ALG_NONE = 0, |
| 151 | #define _(n, s, k, t, a) \ |
| 152 | VNET_CRYPTO_ALG_##n##_TAG##t##_AAD##a, |
| 153 | foreach_crypto_aead_async_alg |
| 154 | #undef _ |
| 155 | #define _(c, h, s, k ,d) \ |
| 156 | VNET_CRYPTO_ALG_##c##_##h##_TAG##d, |
| 157 | foreach_crypto_link_async_alg |
| 158 | #undef _ |
| 159 | VNET_CRYPTO_N_ASYNC_ALGS, |
| 160 | } vnet_crypto_async_alg_t; |
| 161 | |
| 162 | typedef enum |
| 163 | { |
| 164 | VNET_CRYPTO_ASYNC_OP_NONE = 0, |
| 165 | #define _(n, s, k, t, a) \ |
| 166 | VNET_CRYPTO_OP_##n##_TAG##t##_AAD##a##_ENC, \ |
| 167 | VNET_CRYPTO_OP_##n##_TAG##t##_AAD##a##_DEC, |
| 168 | foreach_crypto_aead_async_alg |
| 169 | #undef _ |
| 170 | #define _(c, h, s, k ,d) \ |
| 171 | VNET_CRYPTO_OP_##c##_##h##_TAG##d##_ENC, \ |
| 172 | VNET_CRYPTO_OP_##c##_##h##_TAG##d##_DEC, |
| 173 | foreach_crypto_link_async_alg |
| 174 | #undef _ |
| 175 | VNET_CRYPTO_ASYNC_OP_N_IDS, |
| 176 | } vnet_crypto_async_op_id_t; |
| 177 | |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 178 | typedef struct |
| 179 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 180 | union |
| 181 | { |
| 182 | struct |
| 183 | { |
| 184 | u8 *data; |
| 185 | vnet_crypto_alg_t alg:8; |
| 186 | }; |
| 187 | struct |
| 188 | { |
| 189 | u32 index_crypto; |
| 190 | u32 index_integ; |
| 191 | vnet_crypto_async_alg_t async_alg:8; |
| 192 | }; |
| 193 | }; |
| 194 | #define VNET_CRYPTO_KEY_TYPE_DATA 0 |
| 195 | #define VNET_CRYPTO_KEY_TYPE_LINK 1 |
| 196 | u8 type; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 197 | } vnet_crypto_key_t; |
| 198 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 199 | typedef enum |
| 200 | { |
| 201 | VNET_CRYPTO_OP_NONE = 0, |
Benoît Ganne | be95444 | 2019-04-29 16:05:46 +0200 | [diff] [blame] | 202 | #define _(n, s, l) VNET_CRYPTO_OP_##n##_ENC, VNET_CRYPTO_OP_##n##_DEC, |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 203 | foreach_crypto_cipher_alg |
| 204 | foreach_crypto_aead_alg |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 205 | #undef _ |
| 206 | #define _(n, s) VNET_CRYPTO_OP_##n##_HMAC, |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 207 | foreach_crypto_hmac_alg |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 208 | #undef _ |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 209 | VNET_CRYPTO_N_OP_IDS, |
| 210 | } vnet_crypto_op_id_t; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 211 | /* *INDENT-ON* */ |
| 212 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 213 | typedef enum |
| 214 | { |
| 215 | CRYPTO_OP_SIMPLE, |
| 216 | CRYPTO_OP_CHAINED, |
| 217 | CRYPTO_OP_BOTH, |
| 218 | } crypto_op_class_type_t; |
| 219 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 220 | typedef struct |
| 221 | { |
| 222 | char *name; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 223 | vnet_crypto_op_id_t op_by_type[VNET_CRYPTO_OP_N_TYPES]; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 224 | } vnet_crypto_alg_data_t; |
| 225 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 226 | typedef struct |
| 227 | { |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 228 | u8 *src; |
| 229 | u8 *dst; |
| 230 | u32 len; |
| 231 | } vnet_crypto_op_chunk_t; |
| 232 | |
| 233 | typedef struct |
| 234 | { |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 235 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 236 | uword user_data; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 237 | vnet_crypto_op_id_t op:16; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 238 | vnet_crypto_op_status_t status:8; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 239 | u8 flags; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 240 | #define VNET_CRYPTO_OP_FLAG_INIT_IV (1 << 0) |
| 241 | #define VNET_CRYPTO_OP_FLAG_HMAC_CHECK (1 << 1) |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 242 | #define VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS (1 << 2) |
| 243 | |
| 244 | union |
| 245 | { |
| 246 | u8 digest_len; |
| 247 | u8 tag_len; |
| 248 | }; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 249 | u16 aad_len; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 250 | |
| 251 | union |
| 252 | { |
| 253 | struct |
| 254 | { |
| 255 | u8 *src; |
| 256 | u8 *dst; |
| 257 | }; |
| 258 | |
| 259 | /* valid if VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS is set */ |
| 260 | u16 n_chunks; |
| 261 | }; |
| 262 | |
| 263 | union |
| 264 | { |
| 265 | u32 len; |
| 266 | /* valid if VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS is set */ |
| 267 | u32 chunk_index; |
| 268 | }; |
| 269 | |
| 270 | u32 key_index; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 271 | u8 *iv; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 272 | u8 *aad; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 273 | |
| 274 | union |
| 275 | { |
| 276 | u8 *tag; |
| 277 | u8 *digest; |
| 278 | }; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 279 | } vnet_crypto_op_t; |
| 280 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 281 | STATIC_ASSERT_SIZEOF (vnet_crypto_op_t, CLIB_CACHE_LINE_BYTES); |
| 282 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 283 | typedef struct |
| 284 | { |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 285 | vnet_crypto_op_type_t type; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 286 | vnet_crypto_alg_t alg; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 287 | u32 active_engine_index_simple; |
| 288 | u32 active_engine_index_chained; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 289 | } vnet_crypto_op_data_t; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 290 | |
| 291 | typedef struct |
| 292 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 293 | vnet_crypto_async_op_type_t type; |
| 294 | vnet_crypto_async_alg_t alg; |
| 295 | u32 active_engine_index_async; |
| 296 | } vnet_crypto_async_op_data_t; |
| 297 | |
| 298 | typedef struct |
| 299 | { |
| 300 | char *name; |
| 301 | vnet_crypto_async_op_id_t op_by_type[VNET_CRYPTO_ASYNC_OP_N_TYPES]; |
| 302 | } vnet_crypto_async_alg_data_t; |
| 303 | |
| 304 | typedef struct |
| 305 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 306 | u8 *iv; |
| 307 | union |
| 308 | { |
| 309 | u8 *digest; |
| 310 | u8 *tag; |
| 311 | }; |
| 312 | u8 *aad; |
Neale Ranns | 63ab851 | 2021-02-24 09:18:53 +0000 | [diff] [blame] | 313 | u32 key_index; |
| 314 | u32 crypto_total_length; |
| 315 | i16 crypto_start_offset; /* first buffer offset */ |
| 316 | i16 integ_start_offset; |
| 317 | /* adj total_length for integ, e.g.4 bytes for IPSec ESN */ |
| 318 | u16 integ_length_adj; |
| 319 | vnet_crypto_op_status_t status : 8; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 320 | u8 flags; /**< share same VNET_CRYPTO_OP_FLAG_* values */ |
| 321 | } vnet_crypto_async_frame_elt_t; |
| 322 | |
Neale Ranns | 63ab851 | 2021-02-24 09:18:53 +0000 | [diff] [blame] | 323 | /* Assert the size so the compiler will warn us when it changes */ |
| 324 | STATIC_ASSERT_SIZEOF (vnet_crypto_async_frame_elt_t, 5 * sizeof (u64)); |
| 325 | |
| 326 | typedef enum vnet_crypto_async_frame_state_t_ |
| 327 | { |
| 328 | VNET_CRYPTO_FRAME_STATE_NOT_PROCESSED, |
| 329 | /* frame waiting to be processed */ |
| 330 | VNET_CRYPTO_FRAME_STATE_PENDING, |
| 331 | VNET_CRYPTO_FRAME_STATE_WORK_IN_PROGRESS, |
| 332 | VNET_CRYPTO_FRAME_STATE_SUCCESS, |
| 333 | VNET_CRYPTO_FRAME_STATE_ELT_ERROR |
| 334 | } __clib_packed vnet_crypto_async_frame_state_t; |
| 335 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 336 | typedef struct |
| 337 | { |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 338 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Neale Ranns | 63ab851 | 2021-02-24 09:18:53 +0000 | [diff] [blame] | 339 | vnet_crypto_async_frame_state_t state; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 340 | vnet_crypto_async_op_id_t op:8; |
| 341 | u16 n_elts; |
| 342 | vnet_crypto_async_frame_elt_t elts[VNET_CRYPTO_FRAME_SIZE]; |
| 343 | u32 buffer_indices[VNET_CRYPTO_FRAME_SIZE]; |
| 344 | u16 next_node_index[VNET_CRYPTO_FRAME_SIZE]; |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 345 | u32 enqueue_thread_index; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 346 | } vnet_crypto_async_frame_t; |
| 347 | |
| 348 | typedef struct |
| 349 | { |
| 350 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 351 | vnet_crypto_async_frame_t *frame_pool; |
Neale Ranns | 63ab851 | 2021-02-24 09:18:53 +0000 | [diff] [blame] | 352 | u32 *buffer_indices; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 353 | u16 *nexts; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 354 | } vnet_crypto_thread_t; |
| 355 | |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 356 | typedef u32 vnet_crypto_key_index_t; |
| 357 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 358 | typedef u32 (vnet_crypto_chained_ops_handler_t) (vlib_main_t * vm, |
| 359 | vnet_crypto_op_t * ops[], |
| 360 | vnet_crypto_op_chunk_t * |
| 361 | chunks, u32 n_ops); |
| 362 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 363 | typedef u32 (vnet_crypto_ops_handler_t) (vlib_main_t * vm, |
| 364 | vnet_crypto_op_t * ops[], u32 n_ops); |
| 365 | |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 366 | typedef void (vnet_crypto_key_handler_t) (vlib_main_t * vm, |
| 367 | vnet_crypto_key_op_t kop, |
| 368 | vnet_crypto_key_index_t idx); |
| 369 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 370 | /** async crypto function handlers **/ |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 371 | typedef int |
| 372 | (vnet_crypto_frame_enqueue_t) (vlib_main_t * vm, |
| 373 | vnet_crypto_async_frame_t * frame); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 374 | typedef vnet_crypto_async_frame_t * |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 375 | (vnet_crypto_frame_dequeue_t) (vlib_main_t * vm, u32 * nb_elts_processed, |
| 376 | u32 * enqueue_thread_idx); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 377 | |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 378 | u32 |
| 379 | vnet_crypto_register_engine (vlib_main_t * vm, char *name, int prio, |
| 380 | char *desc); |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 381 | |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 382 | void vnet_crypto_register_ops_handler (vlib_main_t * vm, u32 engine_index, |
| 383 | vnet_crypto_op_id_t opt, |
| 384 | vnet_crypto_ops_handler_t * oph); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 385 | |
| 386 | void vnet_crypto_register_chained_ops_handler (vlib_main_t * vm, |
| 387 | u32 engine_index, |
| 388 | vnet_crypto_op_id_t opt, |
| 389 | vnet_crypto_chained_ops_handler_t |
| 390 | * oph); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 391 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 392 | void vnet_crypto_register_ops_handlers (vlib_main_t * vm, u32 engine_index, |
| 393 | vnet_crypto_op_id_t opt, |
| 394 | vnet_crypto_ops_handler_t * fn, |
| 395 | vnet_crypto_chained_ops_handler_t * |
| 396 | cfn); |
| 397 | |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 398 | void vnet_crypto_register_key_handler (vlib_main_t * vm, u32 engine_index, |
| 399 | vnet_crypto_key_handler_t * keyh); |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 400 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 401 | /** async crypto register functions */ |
| 402 | u32 vnet_crypto_register_post_node (vlib_main_t * vm, char *post_node_name); |
| 403 | void vnet_crypto_register_async_handler (vlib_main_t * vm, |
| 404 | u32 engine_index, |
| 405 | vnet_crypto_async_op_id_t opt, |
| 406 | vnet_crypto_frame_enqueue_t * enq_fn, |
| 407 | vnet_crypto_frame_dequeue_t * |
| 408 | deq_fn); |
| 409 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 410 | typedef struct |
| 411 | { |
| 412 | char *name; |
| 413 | char *desc; |
| 414 | int priority; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 415 | vnet_crypto_key_handler_t *key_op_handler; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 416 | vnet_crypto_ops_handler_t *ops_handlers[VNET_CRYPTO_N_OP_IDS]; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 417 | vnet_crypto_chained_ops_handler_t |
| 418 | * chained_ops_handlers[VNET_CRYPTO_N_OP_IDS]; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 419 | vnet_crypto_frame_enqueue_t *enqueue_handlers[VNET_CRYPTO_ASYNC_OP_N_IDS]; |
| 420 | vnet_crypto_frame_dequeue_t *dequeue_handlers[VNET_CRYPTO_ASYNC_OP_N_IDS]; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 421 | } vnet_crypto_engine_t; |
| 422 | |
| 423 | typedef struct |
| 424 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 425 | u32 node_idx; |
| 426 | u32 next_idx; |
| 427 | } vnet_crypto_async_next_node_t; |
| 428 | |
| 429 | typedef struct |
| 430 | { |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 431 | vnet_crypto_alg_data_t *algs; |
| 432 | vnet_crypto_thread_t *threads; |
| 433 | vnet_crypto_ops_handler_t **ops_handlers; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 434 | vnet_crypto_chained_ops_handler_t **chained_ops_handlers; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 435 | vnet_crypto_frame_enqueue_t **enqueue_handlers; |
| 436 | vnet_crypto_frame_dequeue_t **dequeue_handlers; |
| 437 | clib_bitmap_t *async_active_ids; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 438 | vnet_crypto_op_data_t opt_data[VNET_CRYPTO_N_OP_IDS]; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 439 | vnet_crypto_async_op_data_t async_opt_data[VNET_CRYPTO_ASYNC_OP_N_IDS]; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 440 | vnet_crypto_engine_t *engines; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 441 | vnet_crypto_key_t *keys; |
Filip Tehlar | 1469d54 | 2019-03-25 09:04:41 -0700 | [diff] [blame] | 442 | uword *engine_index_by_name; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 443 | uword *alg_index_by_name; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 444 | uword *async_alg_index_by_name; |
| 445 | vnet_crypto_async_alg_data_t *async_algs; |
| 446 | u32 async_refcnt; |
| 447 | vnet_crypto_async_next_node_t *next_nodes; |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 448 | u32 crypto_node_index; |
| 449 | #define VNET_CRYPTO_ASYNC_DISPATCH_POLLING 0 |
| 450 | #define VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT 1 |
| 451 | u8 dispatch_mode; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 452 | } vnet_crypto_main_t; |
| 453 | |
| 454 | extern vnet_crypto_main_t crypto_main; |
| 455 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 456 | u32 vnet_crypto_process_chained_ops (vlib_main_t * vm, vnet_crypto_op_t ops[], |
| 457 | vnet_crypto_op_chunk_t * chunks, |
| 458 | u32 n_ops); |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 459 | u32 vnet_crypto_process_ops (vlib_main_t * vm, vnet_crypto_op_t ops[], |
| 460 | u32 n_ops); |
| 461 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 462 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 463 | int vnet_crypto_set_handler2 (char *ops_handler_name, char *engine, |
| 464 | crypto_op_class_type_t oct); |
Neale Ranns | ece2ae0 | 2019-06-21 12:44:11 +0000 | [diff] [blame] | 465 | int vnet_crypto_is_set_handler (vnet_crypto_alg_t alg); |
Filip Tehlar | 1469d54 | 2019-03-25 09:04:41 -0700 | [diff] [blame] | 466 | |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 467 | u32 vnet_crypto_key_add (vlib_main_t * vm, vnet_crypto_alg_t alg, |
| 468 | u8 * data, u16 length); |
| 469 | void vnet_crypto_key_del (vlib_main_t * vm, vnet_crypto_key_index_t index); |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 470 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 471 | /** |
| 472 | * Use 2 created keys to generate new key for linked algs (cipher + integ) |
| 473 | * The returned key index is to be used for linked alg only. |
| 474 | **/ |
| 475 | u32 vnet_crypto_key_add_linked (vlib_main_t * vm, |
| 476 | vnet_crypto_key_index_t index_crypto, |
| 477 | vnet_crypto_key_index_t index_integ); |
| 478 | |
| 479 | clib_error_t *crypto_dispatch_enable_disable (int is_enable); |
| 480 | |
| 481 | int vnet_crypto_set_async_handler2 (char *alg_name, char *engine); |
| 482 | |
| 483 | int vnet_crypto_is_set_async_handler (vnet_crypto_async_op_id_t opt); |
| 484 | |
| 485 | void vnet_crypto_request_async_mode (int is_enable); |
| 486 | |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 487 | void vnet_crypto_set_async_dispatch_mode (u8 mode); |
| 488 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 489 | vnet_crypto_async_alg_t vnet_crypto_link_algs (vnet_crypto_alg_t crypto_alg, |
| 490 | vnet_crypto_alg_t integ_alg); |
| 491 | |
| 492 | clib_error_t *crypto_dispatch_enable_disable (int is_enable); |
| 493 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 494 | format_function_t format_vnet_crypto_alg; |
| 495 | format_function_t format_vnet_crypto_engine; |
| 496 | format_function_t format_vnet_crypto_op; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 497 | format_function_t format_vnet_crypto_op_type; |
| 498 | format_function_t format_vnet_crypto_op_status; |
Damjan Marion | 61c0a3d | 2019-04-05 19:42:21 +0200 | [diff] [blame] | 499 | unformat_function_t unformat_vnet_crypto_alg; |
Damjan Marion | a03d182 | 2019-03-28 21:40:48 +0100 | [diff] [blame] | 500 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 501 | format_function_t format_vnet_crypto_async_op; |
| 502 | format_function_t format_vnet_crypto_async_alg; |
| 503 | format_function_t format_vnet_crypto_async_op_type; |
| 504 | |
Damjan Marion | a03d182 | 2019-03-28 21:40:48 +0100 | [diff] [blame] | 505 | static_always_inline void |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 506 | vnet_crypto_op_init (vnet_crypto_op_t * op, vnet_crypto_op_id_t type) |
Damjan Marion | a03d182 | 2019-03-28 21:40:48 +0100 | [diff] [blame] | 507 | { |
| 508 | if (CLIB_DEBUG > 0) |
| 509 | clib_memset (op, 0xfe, sizeof (*op)); |
| 510 | op->op = type; |
| 511 | op->flags = 0; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 512 | op->key_index = ~0; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 513 | op->n_chunks = 0; |
Damjan Marion | a03d182 | 2019-03-28 21:40:48 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 516 | static_always_inline vnet_crypto_op_type_t |
| 517 | vnet_crypto_get_op_type (vnet_crypto_op_id_t id) |
| 518 | { |
| 519 | vnet_crypto_main_t *cm = &crypto_main; |
Lijian Zhang | b15d796 | 2019-09-27 16:25:35 +0800 | [diff] [blame] | 520 | ASSERT (id < VNET_CRYPTO_N_OP_IDS); |
| 521 | vnet_crypto_op_data_t *od = cm->opt_data + id; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 522 | return od->type; |
| 523 | } |
| 524 | |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 525 | static_always_inline vnet_crypto_key_t * |
| 526 | vnet_crypto_get_key (vnet_crypto_key_index_t index) |
| 527 | { |
| 528 | vnet_crypto_main_t *cm = &crypto_main; |
| 529 | return vec_elt_at_index (cm->keys, index); |
| 530 | } |
| 531 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 532 | static_always_inline int |
| 533 | vnet_crypto_set_handler (char *alg_name, char *engine) |
| 534 | { |
| 535 | return vnet_crypto_set_handler2 (alg_name, engine, CRYPTO_OP_BOTH); |
| 536 | } |
| 537 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 538 | /** async crypto inline functions **/ |
| 539 | |
| 540 | static_always_inline vnet_crypto_async_frame_t * |
| 541 | vnet_crypto_async_get_frame (vlib_main_t * vm, vnet_crypto_async_op_id_t opt) |
| 542 | { |
| 543 | vnet_crypto_main_t *cm = &crypto_main; |
| 544 | vnet_crypto_thread_t *ct = cm->threads + vm->thread_index; |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 545 | vnet_crypto_async_frame_t *f = NULL; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 546 | |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 547 | pool_get_aligned (ct->frame_pool, f, CLIB_CACHE_LINE_BYTES); |
| 548 | if (CLIB_DEBUG > 0) |
| 549 | clib_memset (f, 0xfe, sizeof (*f)); |
| 550 | f->state = VNET_CRYPTO_FRAME_STATE_NOT_PROCESSED; |
| 551 | f->op = opt; |
| 552 | f->n_elts = 0; |
| 553 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 554 | return f; |
| 555 | } |
| 556 | |
| 557 | static_always_inline void |
| 558 | vnet_crypto_async_free_frame (vlib_main_t * vm, |
| 559 | vnet_crypto_async_frame_t * frame) |
| 560 | { |
| 561 | vnet_crypto_main_t *cm = &crypto_main; |
| 562 | vnet_crypto_thread_t *ct = cm->threads + vm->thread_index; |
| 563 | pool_put (ct->frame_pool, frame); |
| 564 | } |
| 565 | |
| 566 | static_always_inline int |
| 567 | vnet_crypto_async_submit_open_frame (vlib_main_t * vm, |
| 568 | vnet_crypto_async_frame_t * frame) |
| 569 | { |
| 570 | vnet_crypto_main_t *cm = &crypto_main; |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 571 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 572 | vnet_crypto_async_op_id_t opt = frame->op; |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 573 | u32 i = vlib_num_workers () > 0; |
| 574 | |
PiotrX Kleski | ef69b51 | 2020-11-24 08:26:26 +0000 | [diff] [blame] | 575 | frame->state = VNET_CRYPTO_FRAME_STATE_PENDING; |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 576 | frame->enqueue_thread_index = vm->thread_index; |
PiotrX Kleski | ef69b51 | 2020-11-24 08:26:26 +0000 | [diff] [blame] | 577 | |
| 578 | int ret = (cm->enqueue_handlers[frame->op]) (vm, frame); |
| 579 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 580 | clib_bitmap_set_no_check (cm->async_active_ids, opt, 1); |
| 581 | if (PREDICT_TRUE (ret == 0)) |
| 582 | { |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 583 | if (cm->dispatch_mode == VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT) |
| 584 | { |
| 585 | for (; i < tm->n_vlib_mains; i++) |
| 586 | vlib_node_set_interrupt_pending (vlib_mains[i], |
| 587 | cm->crypto_node_index); |
| 588 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 589 | } |
PiotrX Kleski | ef69b51 | 2020-11-24 08:26:26 +0000 | [diff] [blame] | 590 | else |
| 591 | { |
| 592 | frame->state = VNET_CRYPTO_FRAME_STATE_ELT_ERROR; |
| 593 | } |
PiotrX Kleski | 2284817 | 2020-07-08 14:36:34 +0200 | [diff] [blame] | 594 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 595 | return ret; |
| 596 | } |
| 597 | |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 598 | static_always_inline void |
| 599 | vnet_crypto_async_add_to_frame (vlib_main_t *vm, vnet_crypto_async_frame_t *f, |
| 600 | u32 key_index, u32 crypto_len, |
| 601 | i16 integ_len_adj, i16 crypto_start_offset, |
| 602 | u16 integ_start_offset, u32 buffer_index, |
| 603 | u16 next_node, u8 *iv, u8 *tag, u8 *aad, |
| 604 | u8 flags) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 605 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 606 | vnet_crypto_async_frame_elt_t *fe; |
| 607 | u16 index; |
| 608 | |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 609 | ASSERT (f->n_elts < VNET_CRYPTO_FRAME_SIZE); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 610 | |
| 611 | index = f->n_elts; |
| 612 | fe = &f->elts[index]; |
| 613 | f->n_elts++; |
| 614 | fe->key_index = key_index; |
| 615 | fe->crypto_total_length = crypto_len; |
| 616 | fe->crypto_start_offset = crypto_start_offset; |
| 617 | fe->integ_start_offset = integ_start_offset; |
| 618 | fe->integ_length_adj = integ_len_adj; |
| 619 | fe->iv = iv; |
| 620 | fe->tag = tag; |
| 621 | fe->aad = aad; |
| 622 | fe->flags = flags; |
| 623 | f->buffer_indices[index] = buffer_index; |
| 624 | f->next_node_index[index] = next_node; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static_always_inline void |
| 628 | vnet_crypto_async_reset_frame (vnet_crypto_async_frame_t * f) |
| 629 | { |
| 630 | vnet_crypto_async_op_id_t opt; |
| 631 | ASSERT (f != 0); |
PiotrX Kleski | 8ed06c0 | 2020-11-24 07:34:09 +0000 | [diff] [blame] | 632 | ASSERT ((f->state == VNET_CRYPTO_FRAME_STATE_NOT_PROCESSED |
| 633 | || f->state == VNET_CRYPTO_FRAME_STATE_ELT_ERROR)); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 634 | opt = f->op; |
| 635 | if (CLIB_DEBUG > 0) |
| 636 | clib_memset (f, 0xfe, sizeof (*f)); |
| 637 | f->state = VNET_CRYPTO_FRAME_STATE_NOT_PROCESSED; |
| 638 | f->op = opt; |
| 639 | f->n_elts = 0; |
| 640 | } |
| 641 | |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 642 | static_always_inline u8 |
| 643 | vnet_crypto_async_frame_is_full (const vnet_crypto_async_frame_t *f) |
| 644 | { |
| 645 | return (f->n_elts == VNET_CRYPTO_FRAME_SIZE); |
| 646 | } |
| 647 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 648 | #endif /* included_vnet_crypto_crypto_h */ |
| 649 | |
| 650 | /* |
| 651 | * fd.io coding-style-patch-verification: ON |
| 652 | * |
| 653 | * Local Variables: |
| 654 | * eval: (c-set-style "gnu") |
| 655 | * End: |
| 656 | */ |