|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
18 #include <openssl/hmac.h>
41 static void noise_kdf (uint8_t *, uint8_t *, uint8_t *,
const uint8_t *,
42 size_t,
size_t,
size_t,
size_t,
97 r->r_peer_idx = peer_pool_idx;
98 r->r_local_idx = noise_local_idx;
353 if (
r->r_handshake.hs_state == hs.
hs_state &&
380 noise_kdf (key_send, key_recv, NULL, NULL,
387 noise_kdf (key_recv, key_send, NULL, NULL,
398 VNET_CRYPTO_ALG_CHACHA20_POLY1305,
401 VNET_CRYPTO_ALG_CHACHA20_POLY1305,
411 current =
r->r_current;
412 previous =
r->r_previous;
419 r->r_previous =
next;
424 r->r_previous = current;
435 r->r_previous = NULL;
461 r->r_previous = NULL;
469 if (
r->r_next != NULL)
470 r->r_next->kp_valid = 0;
471 if (
r->r_current != NULL)
472 r->r_current->kp_valid = 0;
483 if ((kp =
r->r_current) == NULL ||
517 if (op_id == VNET_CRYPTO_OP_CHACHA20_POLY1305_DEC)
536 if (op_id == VNET_CRYPTO_OP_CHACHA20_POLY1305_ENC)
541 return (op->
status == VNET_CRYPTO_OP_STATUS_COMPLETED);
546 uint64_t * nonce, uint8_t *
src,
size_t srclen,
553 if ((kp =
r->r_current) == NULL)
574 VNET_CRYPTO_OP_CHACHA20_POLY1305_ENC,
598 uint64_t nonce, uint8_t *
src,
size_t srclen,
605 if (
r->r_current != NULL &&
r->r_current->kp_local_index == r_idx)
609 else if (
r->r_previous != NULL &&
r->r_previous->kp_local_index == r_idx)
613 else if (
r->r_next != NULL &&
r->r_next->kp_local_index == r_idx)
634 VNET_CRYPTO_OP_CHACHA20_POLY1305_DEC,
652 r->r_previous =
r->r_current;
653 r->r_current =
r->r_next;
698 struct noise_upcall *u = &local->
l_upcall;
712 struct noise_upcall *u = &local->
l_upcall;
721 struct noise_upcall *u = &local->
l_upcall;
737 uint64_t
i, top, index_recv, index_ctr;
746 if (recv + COUNTER_WINDOW_SIZE < ctr->c_recv)
757 for (
i = 1;
i <= top;
i++)
777 size_t a_len,
size_t b_len,
size_t c_len,
size_t x_len,
787 if (
a == NULL || a_len == 0)
796 if (
b == NULL || b_len == 0)
806 if (
c == NULL || c_len == 0)
899 size_t src_len, uint32_t key_idx,
904 VNET_CRYPTO_OP_CHACHA20_POLY1305_ENC, key_idx);
910 size_t src_len, uint32_t key_idx,
915 VNET_CRYPTO_OP_CHACHA20_POLY1305_DEC, key_idx))
934 uint32_t unix_nanosec;
945 sec = htobe64 (0x400000000000000aULL + unix_sec);
946 nsec = htobe32 (unix_nanosec);
950 clib_memcpy (output +
sizeof (sec), &nsec,
sizeof (nsec));
956 static void *(*
const volatile memset_v) (
void *,
int,
size_t) = &memset;
bool curve25519_gen_public(u8 public_key[CURVE25519_KEY_SIZE], const u8 secret_key[CURVE25519_KEY_SIZE])
void(* u_index_drop)(uint32_t)
static_always_inline void vnet_crypto_op_init(vnet_crypto_op_t *op, vnet_crypto_op_id_t type)
void noise_remote_expire_current(noise_remote_t *r)
#define clib_memcpy(d, s, n)
void vnet_crypto_key_del(vlib_main_t *vm, vnet_crypto_key_index_t index)
#define NOISE_SYMMETRIC_KEY_LEN
#define clib_memcmp(s1, s2, m1)
#define NOISE_AUTHTAG_LEN
static bool noise_mix_ss(uint8_t ck[NOISE_HASH_LEN], uint8_t key[NOISE_SYMMETRIC_KEY_LEN], const uint8_t ss[NOISE_PUBLIC_KEY_LEN])
uint8_t hs_hash[NOISE_HASH_LEN]
vnet_crypto_op_status_t status
static void clib_mem_free(void *p)
struct noise_local::noise_upcall l_upcall
unsigned long c_backtrack[COUNTER_NUM]
#define REJECT_AFTER_MESSAGES
static bool wg_birthdate_has_expired(f64 birthday_seconds, f64 expiration_seconds)
static bool chacha20poly1305_calc(vlib_main_t *vm, u8 *src, u32 src_len, u8 *dst, u8 *aad, u32 aad_len, u64 nonce, vnet_crypto_op_id_t op_id, vnet_crypto_key_index_t key_index)
u32 vnet_crypto_key_index_t
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
bool noise_consume_initiation(vlib_main_t *vm, noise_local_t *l, noise_remote_t **rp, uint32_t s_idx, uint8_t ue[NOISE_PUBLIC_KEY_LEN], uint8_t es[NOISE_PUBLIC_KEY_LEN+NOISE_AUTHTAG_LEN], uint8_t ets[NOISE_TIMESTAMP_LEN+NOISE_AUTHTAG_LEN])
bool noise_remote_ready(noise_remote_t *r)
#define REJECT_AFTER_TIME
static void noise_msg_ephemeral(uint8_t[NOISE_HASH_LEN], uint8_t[NOISE_HASH_LEN], const uint8_t src[NOISE_PUBLIC_KEY_LEN])
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
vnet_hw_if_output_node_runtime_t * r
uint8_t l_private[NOISE_PUBLIC_KEY_LEN]
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
#define VNET_CRYPTO_OP_FLAG_HMAC_CHECK
static void noise_tai64n_now(uint8_t[NOISE_TIMESTAMP_LEN])
uint8_t hs_ck[NOISE_HASH_LEN]
#define REKEY_AFTER_TIME_RECV
#define NOISE_HANDSHAKE_NAME
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
void noise_remote_clear(vlib_main_t *vm, noise_remote_t *r)
static void noise_remote_handshake_index_drop(noise_remote_t *)
noise_remote_t *(* u_remote_get)(const uint8_t[NOISE_PUBLIC_KEY_LEN])
#define REJECT_INTERVAL_MASK
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
enum noise_state_crypt noise_remote_encrypt(vlib_main_t *vm, noise_remote_t *r, uint32_t *r_idx, uint64_t *nonce, uint8_t *src, size_t srclen, uint8_t *dst)
static void noise_mix_hash(uint8_t[NOISE_HASH_LEN], const uint8_t *, size_t)
static_always_inline vnet_crypto_key_t * vnet_crypto_get_key(vnet_crypto_key_index_t index)
#define NOISE_IDENTIFIER_NAME
bool curve25519_gen_secret(u8 secret_key[CURVE25519_KEY_SIZE])
enum noise_state_hs hs_state
static void clib_rwlock_init(clib_rwlock_t *p)
enum noise_state_crypt noise_remote_decrypt(vlib_main_t *vm, noise_remote_t *r, uint32_t r_idx, uint64_t nonce, uint8_t *src, size_t srclen, uint8_t *dst)
void noise_remote_init(noise_remote_t *r, uint32_t peer_pool_idx, const uint8_t public[NOISE_PUBLIC_KEY_LEN], u32 noise_local_idx)
bool noise_create_initiation(vlib_main_t *vm, noise_remote_t *r, uint32_t *s_idx, uint8_t ue[NOISE_PUBLIC_KEY_LEN], uint8_t es[NOISE_PUBLIC_KEY_LEN+NOISE_AUTHTAG_LEN], uint8_t ets[NOISE_TIMESTAMP_LEN+NOISE_AUTHTAG_LEN])
noise_local_t * noise_local_pool
u32 vnet_crypto_key_add(vlib_main_t *vm, vnet_crypto_alg_t alg, u8 *data, u16 length)
static void unix_time_now_nsec_fraction(u32 *sec, u32 *nsec)
void noise_remote_precompute(noise_remote_t *r)
static void secure_zero_memory(void *v, size_t n)
static void noise_remote_keypair_free(vlib_main_t *vm, noise_remote_t *, noise_keypair_t **)
static void noise_mix_psk(uint8_t[NOISE_HASH_LEN], uint8_t[NOISE_HASH_LEN], uint8_t[NOISE_SYMMETRIC_KEY_LEN], const uint8_t[NOISE_SYMMETRIC_KEY_LEN])
static_always_inline noise_local_t * noise_local_get(uint32_t locali)
static noise_keypair_t * noise_remote_keypair_allocate(noise_remote_t *)
int blake2s_final(blake2s_state_t *S, void *out, size_t outlen)
#define NOISE_PUBLIC_KEY_LEN
static bool noise_mix_dh(uint8_t[NOISE_HASH_LEN], uint8_t[NOISE_SYMMETRIC_KEY_LEN], const uint8_t[NOISE_PUBLIC_KEY_LEN], const uint8_t[NOISE_PUBLIC_KEY_LEN])
vl_api_ikev2_sa_transform_t dh
int blake2s_init(blake2s_state_t *S, size_t outlen)
bool noise_consume_response(vlib_main_t *vm, noise_remote_t *r, uint32_t s_idx, uint32_t r_idx, uint8_t ue[NOISE_PUBLIC_KEY_LEN], uint8_t en[0+NOISE_AUTHTAG_LEN])
static void noise_param_init(uint8_t[NOISE_HASH_LEN], uint8_t[NOISE_HASH_LEN], const uint8_t[NOISE_PUBLIC_KEY_LEN])
static bool noise_counter_recv(noise_counter_t *, uint64_t)
bool noise_create_response(vlib_main_t *vm, noise_remote_t *r, uint32_t *s_idx, uint32_t *r_idx, uint8_t ue[NOISE_PUBLIC_KEY_LEN], uint8_t en[0+NOISE_AUTHTAG_LEN])
bool curve25519_gen_shared(u8 shared_key[CURVE25519_KEY_SIZE], const u8 secret_key[CURVE25519_KEY_SIZE], const u8 basepoint[CURVE25519_KEY_SIZE])
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static uint64_t noise_counter_send(noise_counter_t *)
uint8_t l_public[NOISE_PUBLIC_KEY_LEN]
void noise_local_init(noise_local_t *l, struct noise_upcall *upcall)
int blake2s(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
int blake2s_update(blake2s_state_t *S, const void *pin, size_t inlen)
uint8_t hs_e[NOISE_PUBLIC_KEY_LEN]
static uint32_t noise_remote_handshake_index_get(noise_remote_t *)
#define REKEY_AFTER_MESSAGES
bool noise_local_set_private(noise_local_t *l, const uint8_t private[NOISE_PUBLIC_KEY_LEN])
static f64 vlib_time_now(vlib_main_t *vm)
vnet_crypto_key_index_t kp_recv_index
#define NOISE_TIMESTAMP_LEN
static void noise_kdf(uint8_t *, uint8_t *, uint8_t *, const uint8_t *, size_t, size_t, size_t, size_t, const uint8_t[NOISE_HASH_LEN])
bool noise_remote_begin_session(vlib_main_t *vm, noise_remote_t *r)
static void * clib_mem_alloc(uword size)
static void noise_msg_encrypt(vlib_main_t *vm, uint8_t *, uint8_t *, size_t, uint32_t key_idx, uint8_t[NOISE_HASH_LEN])
uint32_t(* u_index_set)(noise_remote_t *)
static bool noise_msg_decrypt(vlib_main_t *vm, uint8_t *, uint8_t *, size_t, uint32_t key_idx, uint8_t[NOISE_HASH_LEN])
vnet_crypto_key_index_t kp_send_index