LAMMP 4.1.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
secret.h
浏览该文件的文档.
1/*
2 * ==============================================================================
3 * SECURITY & LIABILITY DISCLAIMER
4 * 安全与责任免责声明
5 * ==============================================================================
6 *
7 * This library provides implementations of cryptographic and hash functions
8 * as the underlying computation library for Lamina.
9 * 本库实现加密算法与哈希函数,作为Lamina的底层计算库。
10 *
11 * 1. NO SECURITY WARRANTY 无安全担保
12 * While the developer strives to implement algorithms correctly,
13 * this library is provided "AS IS" without any explicit or implied
14 * warranty of correctness, security, robustness, or fitness for any purpose.
15 * Undiscovered vulnerabilities, implementation flaws, or side-channel risks may exist.
16 *
17 * 开发者力求算法实现正确,但不对代码的绝对安全性、正确性、完整性
18 * 或适用于特定用途作出任何明示或暗示保证。
19 * 本库可能存在未发现的安全漏洞、实现缺陷或侧信道风险。
20 *
21 * 2. COMMITMENT AGAINST MALICIOUS VULNERABILITIES
22 * 不主动植入恶意漏洞承诺
23 * The developer solemnly undertakes that the Library will NOT
24 * intentionally contain, reserve, or add any known or foreseeable
25 * security vulnerabilities, backdoors, or flaws that could be maliciously exploited.
26 *
27 * 开发者郑重承诺:不会在本库中故意保留、隐藏或添加
28 * 任何明确存在、可预见、或可被恶意利用的安全漏洞、后门或缺陷。
29 *
30 * 3. PRODUCTION USE AT YOUR OWN RISK
31 * 生产环境使用,风险自担
32 * Users may integrate this library into production environments at their own risk.
33 * It is the user's responsibility to conduct security audits, testing, validation,
34 * and comply with applicable laws and regulations before deployment.
35 *
36 * 使用者可将本库用于生产环境,但一切风险自行承担。
37 * 使用者有义务自行完成安全审计、充分测试与合规验证,并承担相关责任。
38 *
39 * 4. NO LIABILITY FOR SECURITY ISSUES
40 * 安全问题责任豁免
41 * The developer shall NOT be liable for any damages, losses, or incidents
42 * arising from security vulnerabilities, including but not limited to
43 * data breaches, system compromise, financial loss, or business interruption.
44 *
45 * 因本库安全问题所引发的一切损失、数据泄露、系统入侵、财产损害或业务中断,
46 * 开发者均不承担任何法律责任。
47 *
48 * 5. WELCOME SECURITY DISCLOSURES
49 * 欢迎安全漏洞反馈
50 * The developer welcomes responsible security disclosures, code reviews,
51 * and reports of potential vulnerabilities.
52 * Feedback helps improve the library, but does not impose any obligation
53 * of immediate fix or guaranteed maintenance.
54 *
55 * 开发者欢迎负责任的安全披露、代码审查与漏洞报告。
56 * 社区反馈将用于改进本库,但开发者不承诺立即修复或持续维护。
57 *
58 * 6. GENERAL DISCLAIMER 通用免责
59 * The developer is not liable for any direct, indirect, incidental,
60 * or consequential damages resulting from the use of this library,
61 * including modified versions and redistributions.
62 *
63 * 开发者不对使用本库(含修改版本、二次分发)所产生的任何直接、间接损失承担责任。
64 *
65 * By using, compiling, modifying, or redistributing this library,
66 * you acknowledge that you have read and agreed to this disclaimer.
67 *
68 * 使用、编译、修改或分发本库即表示你已阅读并同意本声明。
69 *
70 * Developer: HJimmyK (https://github.com/HJimmyK)
71 * Date: 2026-02-11
72 * This disclaimer applies permanently to this and future versions.
73 * 本免责声明永久适用于当前版本及未来版本。
74 * ==============================================================================
75 *
76 * [LAMMP]
77 * Copyright (C) [2025-2026] [HJimmyK(Jericho Knox)]
78 *
79 * This program is free software: you can redistribute it and/or modify
80 * it under the terms of the GNU Lesser General Public License as published by
81 * the Free Software Foundation, either version 3 of the License, or
82 * (at your option) any later version.
83 *
84 * This program is distributed in the hope that it will be useful,
85 * but WITHOUT ANY WARRANTY; without even the implied warranty of
86 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87 * GNU Lesser General Public License for more details.
88 *
89 * You should have received a copy of the GNU Lesser General Public License
90 * along with this program. If not, see <https://www.gnu.org/licenses/>.
91 */
92
93#ifndef LAMMP_SECRET_H
94#define LAMMP_SECRET_H
95
96/*
97 LAMMP中实现了两种hash函数:SipHash-2-4 和 xxhash。其中前者通常被认为安全性更好,被认为可以抵挡hash洪水攻击,而后者
98 提供更快的速度,测量发现:两者生成的 hash 值均具有非常良好的统计性能,同时生成速度 xxhash 比 SipHash-2-4 快四倍左右。
99
100 需要注意的是,两种hash函数都不是标准处理任意字节流的 hash 函数,因此在 LAMMP 中,它们仅用于对整数数据进行 hash 计算,
101 尽管这可能带来未知的安全风险,但如果仅作为hash表的键值,则影响不大。但对于字节流数据,应使用标准的 hash 函数,我们建议
102 使用其他更强的加密算法或协议来处理。
103 */
104
105#include "lmmp.h"
106
107#ifdef __cplusplus
108extern "C" {
109#endif
110
111typedef const uint64_t srckey64_t[1];
112typedef const uint64_t srckey128_t[2];
113typedef const uint64_t srckey256_t[4];
114
115typedef uint64_t key64_t[1];
116typedef uint64_t key128_t[2];
117typedef uint64_t key256_t[4];
118
119
120/**
121 * @brief SipHash-2-4 函数(非标准处理任意字节流的 SipHash-2-4)
122 * @param in 输入数据,可以为 NULL
123 * @param inlen 输入数据长度
124 * @param key 128-bit 秘钥,可以为 NULL
125 * @warning 若 key 为 NULL,则使用全零秘钥
126 * @return 64-bit hash 值
127 */
129
130/**
131 * @brief xxhash 函数(非标准处理任意字节流的 xxhash)
132 * @param in 输入数据,可以为 NULL
133 * @param inlen 输入数据长度
134 * @param key 64-bit 秘钥,可以为 NULL
135 * @warning 若 key 为 NULL,则使用全零秘钥
136 * @return 64-bit hash 值
137 */
138LAMMP_API uint64_t lmmp_xxhash_(mp_srcptr in, mp_size_t inlen, srckey64_t key);
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif // LAMMP_SECRET_H
145
uint64_t mp_size_t
Definition lmmp.h:212
const mp_limb_t * mp_srcptr
Definition lmmp.h:216
#define LAMMP_API
Definition lmmp.h:64
uint64_t lmmp_siphash24_(mp_srcptr in, mp_size_t inlen, srckey128_t key)
SipHash-2-4 函数(非标准处理任意字节流的 SipHash-2-4)
Definition siphash.c:14
uint64_t lmmp_xxhash_(mp_srcptr in, mp_size_t inlen, srckey64_t key)
xxhash 函数(非标准处理任意字节流的 xxhash)
Definition xxhash.c:20
const uint64_t srckey256_t[4]
Definition secret.h:113
const uint64_t srckey128_t[2]
Definition secret.h:112
const uint64_t srckey64_t[1]
Definition secret.h:111
uint64_t key256_t[4]
Definition secret.h:117
uint64_t key128_t[2]
Definition secret.h:116
uint64_t key64_t[1]
Definition secret.h:115