diff options
author | John Baldwin <jhb@FreeBSD.org> | 2021-11-22 10:39:20 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2022-06-14 00:55:29 +0200 |
commit | 613c964ee9241c3e8e312faa967684f1068365ee (patch) | |
tree | ce248c0b37dda290ad2833b0d1fb100c13a33a14 /src | |
parent | crypto: use <crypto/chacha20_poly1305.h> when present (diff) | |
download | wireguard-freebsd-613c964ee9241c3e8e312faa967684f1068365ee.tar.xz wireguard-freebsd-613c964ee9241c3e8e312faa967684f1068365ee.zip |
crypto: use curve25519 API from the kernel when available
Signed-off-by: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to '')
-rw-r--r-- | src/crypto.c | 5 | ||||
-rw-r--r-- | src/crypto.h | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/crypto.c b/src/crypto.c index dd80eae..7544065 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -33,12 +33,15 @@ static crypto_session_t chacha20_poly1305_sid; #define cpu_to_le32(a) htole32(a) #define cpu_to_le64(a) htole64(a) +#if !defined(OCF_CHACHA20_POLY1305) || !defined(KERNEL_CHACHA20_POLY1305) || \ + !defined(KERNEL_CURVE25519) static inline uint32_t get_unaligned_le32(const uint8_t *a) { uint32_t l; __builtin_memcpy(&l, a, sizeof(l)); return le32_to_cpup(&l); } +#endif #if !defined(OCF_CHACHA20_POLY1305) || !defined(KERNEL_CHACHA20_POLY1305) static inline uint64_t get_unaligned_le64(const uint8_t *a) { @@ -1000,6 +1003,7 @@ void blake2s_hmac(uint8_t *out, const uint8_t *in, const uint8_t *key, const siz } +#ifndef KERNEL_CURVE25519 /* Below here is fiat's implementation of x25519. * * Copyright (C) 2015-2016 The fiat-crypto Authors. @@ -1858,6 +1862,7 @@ bool curve25519(uint8_t out[CURVE25519_KEY_SIZE], return timingsafe_bcmp(out, curve25519_null_point, CURVE25519_KEY_SIZE) != 0; } +#endif int crypto_init(void) diff --git a/src/crypto.h b/src/crypto.h index 2b741fc..87c759f 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -18,6 +18,10 @@ #define KERNEL_CHACHA20_POLY1305 #endif +#if __FreeBSD_version >= 1400049 +#define KERNEL_CURVE25519 +#endif + enum chacha20poly1305_lengths { XCHACHA20POLY1305_NONCE_SIZE = 24, CHACHA20POLY1305_KEY_SIZE = 32, @@ -141,6 +145,9 @@ void blake2s(uint8_t *out, const uint8_t *in, const uint8_t *key, void blake2s_hmac(uint8_t *out, const uint8_t *in, const uint8_t *key, const size_t outlen, const size_t inlen, const size_t keylen); +#ifdef KERNEL_CURVE25519 +#include <crypto/curve25519.h> +#else enum curve25519_lengths { CURVE25519_KEY_SIZE = 32 }; @@ -169,6 +176,7 @@ static inline void curve25519_generate_secret(uint8_t secret[CURVE25519_KEY_SIZE arc4random_buf(secret, CURVE25519_KEY_SIZE); curve25519_clamp_secret(secret); } +#endif int crypto_init(void); void crypto_deinit(void); |