wg: Trim compat shims for versions older than current stable/13.
Reviewed by: kevans, markj, emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36913
This commit is contained in:
parent
c640d1af2c
commit
854d066251
@ -9,110 +9,9 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#if (__FreeBSD_version < 1400036 && __FreeBSD_version >= 1400000) || __FreeBSD_version < 1300519
|
||||
#define COMPAT_NEED_CHACHA20POLY1305_MBUF
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 1400048
|
||||
#define COMPAT_NEED_CHACHA20POLY1305
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 1400049
|
||||
#define COMPAT_NEED_CURVE25519
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 0x7fffffff /* TODO: update this when implemented */
|
||||
#define COMPAT_NEED_BLAKE2S
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 1400059
|
||||
#include <sys/sockbuf.h>
|
||||
#define sbcreatecontrol(a, b, c, d, e) sbcreatecontrol(a, b, c, d)
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 1300507
|
||||
#include <sys/smp.h>
|
||||
#include <sys/gtaskqueue.h>
|
||||
|
||||
struct taskqgroup_cpu {
|
||||
LIST_HEAD(, grouptask) tgc_tasks;
|
||||
struct gtaskqueue *tgc_taskq;
|
||||
int tgc_cnt;
|
||||
int tgc_cpu;
|
||||
};
|
||||
|
||||
struct taskqgroup {
|
||||
struct taskqgroup_cpu tqg_queue[MAXCPU];
|
||||
/* Other members trimmed from compat. */
|
||||
};
|
||||
|
||||
static inline void taskqgroup_drain_all(struct taskqgroup *tqg)
|
||||
{
|
||||
struct gtaskqueue *q;
|
||||
|
||||
for (int i = 0; i < mp_ncpus; i++) {
|
||||
q = tqg->tqg_queue[i].tgc_taskq;
|
||||
if (q == NULL)
|
||||
continue;
|
||||
gtaskqueue_drain_all(q);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 1300000
|
||||
#define VIMAGE
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/limits.h>
|
||||
#include <sys/endian.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/libkern.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <net/vnet.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_var.h>
|
||||
#include <vm/uma.h>
|
||||
|
||||
#define taskqgroup_attach(a, b, c, d, e, f) taskqgroup_attach((a), (b), (c), -1, (f))
|
||||
#define taskqgroup_attach_cpu(a, b, c, d, e, f, g) taskqgroup_attach_cpu((a), (b), (c), (d), -1, (g))
|
||||
|
||||
#undef NET_EPOCH_ENTER
|
||||
#define NET_EPOCH_ENTER(et) NET_EPOCH_ENTER_ET(et)
|
||||
#undef NET_EPOCH_EXIT
|
||||
#define NET_EPOCH_EXIT(et) NET_EPOCH_EXIT_ET(et)
|
||||
#define NET_EPOCH_CALL(f, c) epoch_call(net_epoch_preempt, (c), (f))
|
||||
#define NET_EPOCH_ASSERT() MPASS(in_epoch(net_epoch_preempt))
|
||||
|
||||
#undef atomic_load_ptr
|
||||
#define atomic_load_ptr(p) (*(volatile __typeof(*p) *)(p))
|
||||
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 1202000
|
||||
static inline uint32_t arc4random_uniform(uint32_t bound)
|
||||
{
|
||||
uint32_t ret, max_mod_bound;
|
||||
|
||||
if (bound < 2)
|
||||
return 0;
|
||||
|
||||
max_mod_bound = (1 + ~bound) % bound;
|
||||
|
||||
do {
|
||||
ret = arc4random();
|
||||
} while (ret < max_mod_bound);
|
||||
|
||||
return ret % bound;
|
||||
}
|
||||
|
||||
typedef void callout_func_t(void *);
|
||||
|
||||
#ifndef CSUM_SND_TAG
|
||||
#define CSUM_SND_TAG 0x80000000
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -8,6 +8,9 @@
|
||||
#define _WG_CRYPTO
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/endian.h>
|
||||
#include <crypto/chacha20_poly1305.h>
|
||||
#include <crypto/curve25519.h>
|
||||
|
||||
struct mbuf;
|
||||
|
||||
@ -20,36 +23,6 @@ enum chacha20poly1305_lengths {
|
||||
CHACHA20POLY1305_AUTHTAG_SIZE = 16
|
||||
};
|
||||
|
||||
#ifdef COMPAT_NEED_CHACHA20POLY1305
|
||||
void
|
||||
chacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src, const size_t src_len,
|
||||
const uint8_t *ad, const size_t ad_len,
|
||||
const uint64_t nonce,
|
||||
const uint8_t key[CHACHA20POLY1305_KEY_SIZE]);
|
||||
|
||||
bool
|
||||
chacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src, const size_t src_len,
|
||||
const uint8_t *ad, const size_t ad_len,
|
||||
const uint64_t nonce,
|
||||
const uint8_t key[CHACHA20POLY1305_KEY_SIZE]);
|
||||
|
||||
void
|
||||
xchacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src,
|
||||
const size_t src_len, const uint8_t *ad,
|
||||
const size_t ad_len,
|
||||
const uint8_t nonce[XCHACHA20POLY1305_NONCE_SIZE],
|
||||
const uint8_t key[CHACHA20POLY1305_KEY_SIZE]);
|
||||
|
||||
bool
|
||||
xchacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src,
|
||||
const size_t src_len, const uint8_t *ad,
|
||||
const size_t ad_len,
|
||||
const uint8_t nonce[XCHACHA20POLY1305_NONCE_SIZE],
|
||||
const uint8_t key[CHACHA20POLY1305_KEY_SIZE]);
|
||||
#else
|
||||
#include <sys/endian.h>
|
||||
#include <crypto/chacha20_poly1305.h>
|
||||
|
||||
static inline void
|
||||
chacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src, const size_t src_len,
|
||||
const uint8_t *ad, const size_t ad_len,
|
||||
@ -95,7 +68,6 @@ xchacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src,
|
||||
{
|
||||
return (xchacha20_poly1305_decrypt(dst, src, src_len, ad, ad_len, nonce, key));
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
chacha20poly1305_encrypt_mbuf(struct mbuf *, const uint64_t nonce,
|
||||
@ -146,37 +118,4 @@ static inline void blake2s(uint8_t *out, const uint8_t *in, const uint8_t *key,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef COMPAT_NEED_CURVE25519
|
||||
enum curve25519_lengths {
|
||||
CURVE25519_KEY_SIZE = 32
|
||||
};
|
||||
|
||||
bool curve25519(uint8_t mypublic[static CURVE25519_KEY_SIZE],
|
||||
const uint8_t secret[static CURVE25519_KEY_SIZE],
|
||||
const uint8_t basepoint[static CURVE25519_KEY_SIZE]);
|
||||
|
||||
static inline bool
|
||||
curve25519_generate_public(uint8_t pub[static CURVE25519_KEY_SIZE],
|
||||
const uint8_t secret[static CURVE25519_KEY_SIZE])
|
||||
{
|
||||
static const uint8_t basepoint[CURVE25519_KEY_SIZE] = { 9 };
|
||||
|
||||
return curve25519(pub, secret, basepoint);
|
||||
}
|
||||
|
||||
static inline void curve25519_clamp_secret(uint8_t secret[static CURVE25519_KEY_SIZE])
|
||||
{
|
||||
secret[0] &= 248;
|
||||
secret[31] = (secret[31] & 127) | 64;
|
||||
}
|
||||
|
||||
static inline void curve25519_generate_secret(uint8_t secret[CURVE25519_KEY_SIZE])
|
||||
{
|
||||
arc4random_buf(secret, CURVE25519_KEY_SIZE);
|
||||
curve25519_clamp_secret(secret);
|
||||
}
|
||||
#else
|
||||
#include <crypto/curve25519.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user