diff options
author | Fan Zhang <roy.fan.zhang@intel.com> | 2020-04-29 14:00:03 +0100 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2020-04-30 14:38:33 +0000 |
commit | f539578bac8b64886b57c460c9d74273e6613f8b (patch) | |
tree | 190e09705fe1ebb46ca86a48c19de49fcaf0cbb0 /src/vnet/ipsec/esp.h | |
parent | 162330f25aeec09694fffaaa31ba9b318620eb9c (diff) |
crypto: introduce async crypto infra
Type: feature
Signed-off-by: Damjan Marion <damarion@cisco.com>
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Signed-off-by: Piotr Bronowski <piotrx.bronowski@intel.com>
Signed-off-by: Dariusz Kazimierski <dariuszx.kazimierski@intel.com>
Signed-off-by: Piotr Kleski <piotrx.kleski@intel.com>
Change-Id: I4c3fcccf55c36842b7b48aed260fef2802b5c54b
Diffstat (limited to 'src/vnet/ipsec/esp.h')
-rw-r--r-- | src/vnet/ipsec/esp.h | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/src/vnet/ipsec/esp.h b/src/vnet/ipsec/esp.h index b1736453b93..6c47bb05428 100644 --- a/src/vnet/ipsec/esp.h +++ b/src/vnet/ipsec/esp.h @@ -105,29 +105,101 @@ esp_seq_advance (ipsec_sa_t * sa) return 0; } -always_inline void -esp_aad_fill (vnet_crypto_op_t * op, - const esp_header_t * esp, const ipsec_sa_t * sa) +always_inline u16 +esp_aad_fill (u8 * data, const esp_header_t * esp, const ipsec_sa_t * sa) { esp_aead_t *aad; - aad = (esp_aead_t *) op->aad; + aad = (esp_aead_t *) data; aad->data[0] = esp->spi; if (ipsec_sa_is_set_USE_ESN (sa)) { /* SPI, seq-hi, seq-low */ - aad->data[1] = clib_host_to_net_u32 (sa->seq_hi); + aad->data[1] = (u32) clib_host_to_net_u32 (sa->seq_hi); aad->data[2] = esp->seq; - op->aad_len = 12; + return 12; } else { /* SPI, seq-low */ aad->data[1] = esp->seq; - op->aad_len = 8; + return 8; } } + +/** + * The post data structure to for esp_encrypt/decrypt_inline to write to + * vib_buffer_t opaque unused field, and for post nodes to pick up after + * dequeue. + **/ +typedef struct +{ + union + { + struct + { + u8 icv_sz; + u8 iv_sz; + ipsec_sa_flags_t flags; + u32 sa_index; + }; + u64 sa_data; + }; + + u32 seq; + i16 current_data; + i16 current_length; + u16 hdr_sz; + u16 is_chain; + u32 protect_index; +} esp_decrypt_packet_data_t; + +STATIC_ASSERT_SIZEOF (esp_decrypt_packet_data_t, 3 * sizeof (u64)); + +/* we are forced to store the decrypt post data into 2 separate places - + vlib_opaque and opaque2. */ +typedef struct +{ + vlib_buffer_t *lb; + u32 free_buffer_index; + u8 icv_removed; +} esp_decrypt_packet_data2_t; + +typedef union +{ + u16 next_index; + esp_decrypt_packet_data_t decrypt_data; +} esp_post_data_t; + +STATIC_ASSERT (sizeof (esp_post_data_t) <= + STRUCT_SIZE_OF (vnet_buffer_opaque_t, unused), + "Custom meta-data too large for vnet_buffer_opaque_t"); + +#define esp_post_data(b) \ + ((esp_post_data_t *)((u8 *)((b)->opaque) \ + + STRUCT_OFFSET_OF (vnet_buffer_opaque_t, unused))) + +STATIC_ASSERT (sizeof (esp_decrypt_packet_data2_t) <= + STRUCT_SIZE_OF (vnet_buffer_opaque2_t, unused), + "Custom meta-data too large for vnet_buffer_opaque2_t"); + +#define esp_post_data2(b) \ + ((esp_decrypt_packet_data2_t *)((u8 *)((b)->opaque2) \ + + STRUCT_OFFSET_OF (vnet_buffer_opaque2_t, unused))) + +typedef struct +{ + /* esp post node index for async crypto */ + u32 esp4_post_next; + u32 esp6_post_next; + u32 esp4_tun_post_next; + u32 esp6_tun_post_next; +} esp_async_post_next_t; + +extern esp_async_post_next_t esp_encrypt_async_next; +extern esp_async_post_next_t esp_decrypt_async_next; + #endif /* __ESP_H__ */ /* |