From: Arne Schwabe <[email protected]> AWS-LC has a siphash implementation that is just a simple function call that also performs the same/better than the reference implementation that it looks to be based on. AWS-lc variant seems to have come from boringssl according to the Google copyright.
The return type of the siphash related function has been also removed as neither the reference nor the aws-lc implementation can fail. Only the OpenSSL based implementation needed a return type. Change-Id: I05e20f8c82494e4abf96fe1e3a73e1c7b9101af6 Signed-off-by: Arne Schwabe <[email protected]> Acked-by: Frank Lichtenheld <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1572 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1572 This mail reflects revision 24 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld <[email protected]> diff --git a/src/openvpn/siphash.h b/src/openvpn/siphash.h index bddddc3..ade7762 100644 --- a/src/openvpn/siphash.h +++ b/src/openvpn/siphash.h @@ -18,26 +18,63 @@ #ifndef SIPHASH_H #define SIPHASH_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdint.h> #include <stdio.h> #include <stdbool.h> +/* We need to include this to check for the OPENSSL_IS_AWSLC macro */ +#ifdef ENABLE_CRYPTO_OPENSSL +#include <openssl/opensslv.h> +#endif + /* siphash always uses 128-bit keys */ #define SIPHASH_KEY_SIZE 16 /** * Calculates SIPHASH using the reference implementation */ -int +void siphash_reference(const void *in, size_t inlen, const void *k, uint8_t *out, size_t outlen); -static inline int +#if defined(OPENSSL_IS_AWSLC) +#define USE_CRYPOTOLIB_SIPHASH +#include <openssl/siphash.h> +#include <string.h> +#include "error.h" +/** + * Computes a SipHash value + * @param in pointer to input data (read-only) + * @param inlen input data length in bytes (any size_t value) + * @param k pointer to the key data (read-only), must be 16 bytes + * @param out pointer to output data (write-only), outlen bytes must be allocated + * @param outlen length of the output in bytes, must be 8 + */ +static inline void +siphash_cryptolib(const void *in, const size_t inlen, + const void *k, uint8_t *out, const size_t outlen) +{ + ASSERT(outlen == sizeof(uint64_t)); + uint64_t sipout = SIPHASH_24(k, in, inlen); + + memcpy(out, &sipout, sizeof(uint64_t)); +} +#endif + +static inline void siphash(const void *in, size_t inlen, const void *k, uint8_t *out, size_t outlen) { - return siphash_reference(in, inlen, k, out, outlen); +#if defined(USE_CRYPOTOLIB_SIPHASH) + siphash_cryptolib(in, inlen, k, out, outlen); +#else + siphash_reference(in, inlen, k, out, outlen); +#endif } -#endif /* ifndef SIPHASH_H */ \ No newline at end of file +#endif /* ifndef SIPHASH_H */ diff --git a/src/openvpn/siphash_reference.c b/src/openvpn/siphash_reference.c index ad19a51..5f0adb9 100644 --- a/src/openvpn/siphash_reference.c +++ b/src/openvpn/siphash_reference.c @@ -99,7 +99,7 @@ * out: pointer to output data (write-only), outlen bytes must be allocated * outlen: length of the output in bytes, must be 8 or 16 */ -int +void siphash_reference(const void *in, const size_t inlen, const void *k, uint8_t *out, const size_t outlen) { @@ -206,7 +206,7 @@ if (outlen == 8) { - return 0; + return; } v1 ^= 0xdd; @@ -219,6 +219,4 @@ b = v0 ^ v1 ^ v2 ^ v3; U64TO8_LE(out + 8, b); - - return 0; } _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
