LAMMP 4.2.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
secret.h
浏览该文件的文档.
1/**
2 * Copyright (C) 2026 HJimmyK(Jericho Knox)
3 *
4 * This file is part of LAMMP.
5 *
6 * LAMMP is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License (LGPL) as published
8 * by the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed WITHOUT ANY WARRANTY.
12 *
13 * See <https://www.gnu.org/licenses/>.
14 */
15
16#ifndef LAMMP_SECRET_H
17#define LAMMP_SECRET_H
18
19/*
20 LAMMP中实现了两种hash函数:SipHash-2-4 和 xxhash。其中前者通常被认为安全性更好,被认为可以抵挡hash洪水攻击,而后者
21 提供更快的速度,测量发现:两者生成的 hash 值均具有非常良好的统计性能,同时生成速度 xxhash 比 SipHash-2-4 快四倍左右。
22
23 需要注意的是,两种hash函数都不是标准处理任意字节流的 hash 函数,因此在 LAMMP 中,它们仅用于对整数数据进行 hash 计算,
24 尽管这可能带来未知的安全风险,但如果仅作为hash表的键值,则影响不大。但对于字节流数据,应使用标准的 hash 函数,我们建议
25 使用其他更强的加密算法或协议来处理。
26 */
27
28#include "lmmp.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34typedef const uint64_t srckey64_t[1];
35typedef const uint64_t srckey128_t[2];
36typedef const uint64_t srckey256_t[4];
37
38typedef uint64_t key64_t[1];
39typedef uint64_t key128_t[2];
40typedef uint64_t key256_t[4];
41
42
43/**
44 * @brief SipHash-2-4 函数(非标准处理任意字节流的 SipHash-2-4)
45 * @param in 输入数据,可以为 NULL
46 * @param inlen 输入数据长度
47 * @param key 128-bit 秘钥,可以为 NULL
48 * @warning 若 key 为 NULL,则使用全零秘钥
49 * @return 64-bit hash 值
50 */
52
53/**
54 * @brief xxhash 函数(非标准处理任意字节流的 xxhash)
55 * @param in 输入数据,可以为 NULL
56 * @param inlen 输入数据长度
57 * @param key 64-bit 秘钥,可以为 NULL
58 * @warning 若 key 为 NULL,则使用全零秘钥
59 * @return 64-bit hash 值
60 */
62
63#ifdef __cplusplus
64}
65#endif
66
67#endif // LAMMP_SECRET_H
68
uint64_t mp_size_t
Definition lmmp.h:77
const mp_limb_t * mp_srcptr
Definition lmmp.h:81
#define LAMMP_API
Definition lmmp.h:61
#define n
uint64_t lmmp_siphash24_(mp_srcptr in, mp_size_t inlen, srckey128_t key)
SipHash-2-4 函数(非标准处理任意字节流的 SipHash-2-4)
Definition siphash.c:23
uint64_t lmmp_xxhash_(mp_srcptr in, mp_size_t inlen, srckey64_t key)
xxhash 函数(非标准处理任意字节流的 xxhash)
Definition xxhash.c:29
const uint64_t srckey256_t[4]
Definition secret.h:36
const uint64_t srckey128_t[2]
Definition secret.h:35
const uint64_t srckey64_t[1]
Copyright (C) 2026 HJimmyK(Jericho Knox)
Definition secret.h:34
uint64_t key256_t[4]
Definition secret.h:40
uint64_t key128_t[2]
Definition secret.h:39
uint64_t key64_t[1]
Definition secret.h:38