linux/lib/siphash_kunit.c

// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
/* Copyright (C) 2016-2022 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
 *
 * Test cases for siphash.c
 *
 * SipHash: a fast short-input PRF
 * https://131002.net/siphash/
 *
 * This implementation is specifically for SipHash2-4 for a secure PRF
 * and HalfSipHash1-3/SipHash1-3 for an insecure PRF only suitable for
 * hashtables.
 */

#define pr_fmt(fmt)

#include <kunit/test.h>
#include <linux/siphash.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/module.h>

/* Test vectors taken from reference source available at:
 *     https://github.com/veorq/SipHash
 */

static const siphash_key_t test_key_siphash =;

static const u64 test_vectors_siphash[64] =;

#if BITS_PER_LONG == 64
static const hsiphash_key_t test_key_hsiphash =;

static const u32 test_vectors_hsiphash[64] =;
#else
static const hsiphash_key_t test_key_hsiphash =
	{{ 0x03020100U, 0x07060504U }};

static const u32 test_vectors_hsiphash[64] = {
	0x5814c896U, 0xe7e864caU, 0xbc4b0e30U,
	0x01539939U, 0x7e059ea6U, 0x88e3d89bU,
	0xa0080b65U, 0x9d38d9d6U, 0x577999b1U,
	0xc839caedU, 0xe4fa32cfU, 0x959246eeU,
	0x6b28096cU, 0x66dd9cd6U, 0x16658a7cU,
	0xd0257b04U, 0x8b31d501U, 0x2b1cd04bU,
	0x06712339U, 0x522aca67U, 0x911bb605U,
	0x90a65f0eU, 0xf826ef7bU, 0x62512debU,
	0x57150ad7U, 0x5d473507U, 0x1ec47442U,
	0xab64afd3U, 0x0a4100d0U, 0x6d2ce652U,
	0x2331b6a3U, 0x08d8791aU, 0xbc6dda8dU,
	0xe0f6c934U, 0xb0652033U, 0x9b9851ccU,
	0x7c46fb7fU, 0x732ba8cbU, 0xf142997aU,
	0xfcc9aa1bU, 0x05327eb2U, 0xe110131cU,
	0xf9e5e7c0U, 0xa7d708a6U, 0x11795ab1U,
	0x65671619U, 0x9f5fff91U, 0xd89c5267U,
	0x007783ebU, 0x95766243U, 0xab639262U,
	0x9c7e1390U, 0xc368dda6U, 0x38ddc455U,
	0xfa13d379U, 0x979ea4e8U, 0x53ecd77eU,
	0x2ee80657U, 0x33dbb66aU, 0xae3f0577U,
	0x88b4c4ccU, 0x3e7f480bU, 0x74c1ebf8U,
	0x87178304U
};
#endif

#define chk(hash, vector, fmt...)

static void siphash_test(struct kunit *test)
{}

static struct kunit_case siphash_test_cases[] =;

static struct kunit_suite siphash_test_suite =;

kunit_test_suite();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();