wireguard: use clib helpers for endianness 64/40764/9
authorGuillaume Solignac <gsoligna@cisco.com>
Thu, 20 Apr 2023 15:59:22 +0000 (17:59 +0200)
committerDamjan Marion <dmarion@0xa5.net>
Mon, 13 May 2024 14:57:50 +0000 (14:57 +0000)
In some cases, the Linux helpers for endianness conversion are not
present. We use clib helpers to fix this.

Type: fix

Signed-off-by: Guillaume Solignac <gsoligna@cisco.com>
Change-Id: I4d21fb5edae6fa6413b10f298a84ff4b88bda5db
Signed-off-by: Pierre Pfister <ppfister@cisco.com>
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
src/plugins/wireguard/wireguard_chachapoly.c
src/plugins/wireguard/wireguard_noise.c

index 0dd7908..ad644ff 100644 (file)
@@ -72,11 +72,11 @@ wg_xchacha20poly1305_encrypt (vlib_main_t *vm, u8 *src, u32 src_len, u8 *dst,
   u64 h_nonce;
 
   clib_memcpy (&h_nonce, nonce + 16, sizeof (h_nonce));
-  h_nonce = le64toh (h_nonce);
+  h_nonce = clib_little_to_host_u64 (h_nonce);
   hchacha20 (derived_key, nonce, key);
 
   for (i = 0; i < (sizeof (derived_key) / sizeof (derived_key[0])); i++)
-    (derived_key[i]) = htole32 ((derived_key[i]));
+    (derived_key[i]) = clib_host_to_little_u32 ((derived_key[i]));
 
   uint32_t key_idx;
 
@@ -102,11 +102,11 @@ wg_xchacha20poly1305_decrypt (vlib_main_t *vm, u8 *src, u32 src_len, u8 *dst,
   u64 h_nonce;
 
   clib_memcpy (&h_nonce, nonce + 16, sizeof (h_nonce));
-  h_nonce = le64toh (h_nonce);
+  h_nonce = clib_little_to_host_u64 (h_nonce);
   hchacha20 (derived_key, nonce, key);
 
   for (i = 0; i < (sizeof (derived_key) / sizeof (derived_key[0])); i++)
-    (derived_key[i]) = htole32 ((derived_key[i]));
+    (derived_key[i]) = clib_host_to_little_u32 ((derived_key[i]));
 
   uint32_t key_idx;
 
index 5fe2e44..c3f28f4 100644 (file)
@@ -751,8 +751,8 @@ noise_tai64n_now (uint8_t output[NOISE_TIMESTAMP_LEN])
   unix_nanosec &= REJECT_INTERVAL_MASK;
 
   /* https://cr.yp.to/libtai/tai64.html */
-  sec = htobe64 (0x400000000000000aULL + unix_sec);
-  nsec = htobe32 (unix_nanosec);
+  sec = clib_host_to_big_u64 (0x400000000000000aULL + unix_sec);
+  nsec = clib_host_to_big_u32 (unix_nanosec);
 
   /* memcpy to output buffer, assuming output could be unaligned. */
   clib_memcpy (output, &sec, sizeof (sec));