2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/ip/ip.h>
19 #include <vnet/crypto/crypto.h>
20 #include <vnet/ipsec/ipsec.h>
36 typedef CLIB_PACKED (struct {
39 }) ip4_and_esp_header_t;
43 typedef CLIB_PACKED (struct {
47 }) ip4_and_udp_and_esp_header_t;
51 typedef CLIB_PACKED (struct {
54 }) ip6_and_esp_header_t;
57 #define ESP_SEQ_MAX (4294967295UL)
58 #define ESP_MAX_BLOCK_SIZE (16)
59 #define ESP_MAX_ICV_SIZE (16)
61 u8 *format_esp_header (u8 * s, va_list * args);
63 /* TODO seq increment should be atomic to be accessed by multiple workers */
65 esp_seq_advance (ipsec_sa_t * sa)
67 if (PREDICT_TRUE (ipsec_sa_is_set_USE_EXTENDED_SEQ_NUM (sa)))
69 if (PREDICT_FALSE (sa->seq == ESP_SEQ_MAX))
71 if (PREDICT_FALSE (ipsec_sa_is_set_USE_ANTI_REPLAY (sa) &&
72 sa->seq_hi == ESP_SEQ_MAX))
80 if (PREDICT_FALSE (ipsec_sa_is_set_USE_ANTI_REPLAY (sa) &&
81 sa->seq == ESP_SEQ_MAX))
90 always_inline unsigned int
91 hmac_calc (vlib_main_t * vm, ipsec_sa_t * sa, u8 * data, int data_len,
94 vnet_crypto_op_t _op, *op = &_op;
96 if (PREDICT_FALSE (sa->integ_op_type == 0))
99 op->op = sa->integ_op_type;
100 op->key = sa->integ_key.data;
101 op->key_len = sa->integ_key.len;
105 op->hmac_trunc_len = sa->integ_trunc_size;
107 if (ipsec_sa_is_set_USE_EXTENDED_SEQ_NUM (sa))
109 u32 seq_hi = clib_host_to_net_u32 (sa->seq_hi);
112 clib_memcpy (data + data_len, &seq_hi, 4);
115 vnet_crypto_process_ops (vm, op, 1);
116 return sa->integ_trunc_size;
119 #endif /* __ESP_H__ */
122 * fd.io coding-style-patch-verification: ON
125 * eval: (c-set-style "gnu")