LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
test_hash.c 文件参考
#include "lmmp/lmmpn.h"
#include "lmmp/mprand.h"
#include "lmmp/secret.h"
#include "lmmp/version.h"
#include "cases.h"
#include "support/lmmp_test_utils.h"
#include <string.h>
test_hash.c 的引用(Include)关系图:

浏览该文件的源代码.

函数

 TEST_CASE ("hash/sanity", siphash_xxhash)
 Copyright (C) 2026 HJimmyK (Jericho Knox)
void test_hash (void)
 Copyright (C) 2026 HJimmyK (Jericho Knox)

函数说明

◆ TEST_CASE()

TEST_CASE ( "hash/sanity" ,
siphash_xxhash  )

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

在文件 test_hash.c 第 32 行定义.

32 {
33 mp_limb_t in[8];
34 u64 seed = 0x1234567890abcdefull;
35 for (size_t x_index = 0; x_index < ARRAY_SIZE(in); ++x_index) {
36 in[x_index] = xorshift64(&seed);
37 }
38
39 u64 key2[2] = {0x1111111111111111ull, 0x2222222222222222ull};
40 u64 key1[1] = {0x3333333333333333ull};
41
42 u64 h1 = lmmp_siphash24_(in, 8, key2);
43 u64 h2 = lmmp_siphash24_(in, 8, key2);
44 TEST_CHECK_EQ(h1, h2);
45
46 u64 h3 = lmmp_siphash24_(in, 8, NULL);
47 TEST_CHECK_MSG(h3 != h1, "siphash key changes hash");
48
49 u64 x1 = lmmp_xxhash_(in, 8, key1);
50 u64 x2 = lmmp_xxhash_(in, 8, key1);
51 TEST_CHECK_EQ(x1, x2);
52
53 u64 x3 = lmmp_xxhash_(in, 8, NULL);
54 TEST_CHECK_MSG(x3 != x1, "xxhash key changes hash");
55
56 // 空输入与 NULL key
57 TEST_CHECK_MSG(lmmp_siphash24_(NULL, 0, NULL) != 0, "siphash empty nonzero");
58 TEST_CHECK_MSG(lmmp_xxhash_(NULL, 0, NULL) != 0, "xxhash empty nonzero");
59
60 // 变更输入应改变哈希
61 in[0] ^= 1;
62 TEST_CHECK_MSG(lmmp_xxhash_(in, 8, key1) != x1, "xxhash input change");
63}
uint64_t mp_limb_t
定义 lmmp.h:92
mp_limb_t u64
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define ARRAY_SIZE(a)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 perf.h:40
uint64_t lmmp_siphash24_(mp_srcptr in, mp_size_t inlen, srckey128_t key)
SipHash-2-4 函数(非标准处理任意字节流的 SipHash-2-4)
uint64_t lmmp_xxhash_(mp_srcptr in, mp_size_t inlen, srckey64_t key)
xxhash 函数(非标准处理任意字节流的 xxhash)
#define TEST_CHECK_MSG(cond, msg)
定义 test.h:38
#define TEST_CHECK_EQ(a, b)
定义 test.h:39

引用了 ARRAY_SIZE, lmmp_siphash24_(), lmmp_xxhash_(), TEST_CASE, TEST_CHECK_EQ , 以及 TEST_CHECK_MSG.

函数调用图:

◆ test_hash()

void test_hash ( void )

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

在文件 test_hash.c 第 65 行定义.

65 {
66 TEST_RUN("hash/sanity", siphash_xxhash);
67}
#define TEST_RUN(category, name)
定义 test.h:36

引用了 test_hash() , 以及 TEST_RUN.

被这些函数引用 main() , 以及 test_hash().

函数调用图:
这是这个函数的调用关系图: