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