mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-31 06:53:58 +08:00
Fix SPHINCS+
Size of tree nodes and root is decided by security parameter n, currently GmSSL only support SPHINCS+-128s, SPHINCS+-128f, so the size is 128 bits and type is sphincs_hash128_t.
This commit is contained in:
@@ -31,7 +31,7 @@ extern "C" {
|
|||||||
# define SPHINCS_HYPERTREE_LAYERS 7
|
# define SPHINCS_HYPERTREE_LAYERS 7
|
||||||
# define SPHINCS_FORS_TREE_HEIGHT 12
|
# define SPHINCS_FORS_TREE_HEIGHT 12
|
||||||
# define SPHINCS_FORS_NUM_TREES 14
|
# define SPHINCS_FORS_NUM_TREES 14
|
||||||
#else
|
#else // SPHINCS+_128f
|
||||||
# define SPHINCS_HYPERTREE_HEIGHT 66
|
# define SPHINCS_HYPERTREE_HEIGHT 66
|
||||||
# define SPHINCS_HYPERTREE_LAYERS 22
|
# define SPHINCS_HYPERTREE_LAYERS 22
|
||||||
# define SPHINCS_FORS_TREE_HEIGHT 6
|
# define SPHINCS_FORS_TREE_HEIGHT 6
|
||||||
@@ -224,13 +224,14 @@ void sphincs_wots_pk_to_root(const sphincs_wots_key_t pk,
|
|||||||
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs,
|
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs,
|
||||||
sphincs_hash128_t root);
|
sphincs_hash128_t root);
|
||||||
|
|
||||||
|
// for both XMSS and FORS
|
||||||
|
void sphincs_tree_hash(const sphincs_hash128_t left_child, const sphincs_hash128_t right_child,
|
||||||
|
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
||||||
|
sphincs_hash128_t parent);
|
||||||
|
|
||||||
// XMSS
|
// XMSS
|
||||||
|
|
||||||
void sphincs_xmss_tree_hash(
|
#define sphincs_xmss_tree_hash sphincs_tree_hash
|
||||||
const sphincs_hash128_t left_child, const sphincs_hash128_t right_child,
|
|
||||||
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
|
||||||
sphincs_hash256_t parent);
|
|
||||||
void sphincs_xmss_build_tree(const sphincs_hash128_t secret,
|
void sphincs_xmss_build_tree(const sphincs_hash128_t secret,
|
||||||
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
||||||
sphincs_hash128_t tree[SPHINCS_XMSS_NUM_NODES]);
|
sphincs_hash128_t tree[SPHINCS_XMSS_NUM_NODES]);
|
||||||
@@ -239,7 +240,7 @@ void sphincs_xmss_build_auth_path(const sphincs_hash128_t tree[SPHINCS_XMSS_NUM_
|
|||||||
void sphincs_xmss_build_root(const sphincs_hash128_t wots_root, uint32_t tree_index,
|
void sphincs_xmss_build_root(const sphincs_hash128_t wots_root, uint32_t tree_index,
|
||||||
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
||||||
const sphincs_hash128_t auth_path[SPHINCS_XMSS_HEIGHT],
|
const sphincs_hash128_t auth_path[SPHINCS_XMSS_HEIGHT],
|
||||||
sphincs_hash256_t root);
|
sphincs_hash128_t root);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
sphincs_wots_sig_t wots_sig;
|
sphincs_wots_sig_t wots_sig;
|
||||||
@@ -282,6 +283,7 @@ int sphincs_hypertree_verify(const sphincs_hash128_t top_xmss_root,
|
|||||||
void sphincs_fors_derive_sk(const sphincs_hash128_t secret,
|
void sphincs_fors_derive_sk(const sphincs_hash128_t secret,
|
||||||
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs,
|
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs,
|
||||||
uint32_t fors_index, sphincs_hash128_t sk);
|
uint32_t fors_index, sphincs_hash128_t sk);
|
||||||
|
#define sphincs_fors_tree_hash sphincs_tree_hash
|
||||||
void sphincs_fors_build_tree(const sphincs_hash128_t secret,
|
void sphincs_fors_build_tree(const sphincs_hash128_t secret,
|
||||||
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs, int tree_addr,
|
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs, int tree_addr,
|
||||||
sphincs_hash128_t tree[SPHINCS_FORS_TREE_NUM_NODES]);;
|
sphincs_hash128_t tree[SPHINCS_FORS_TREE_NUM_NODES]);;
|
||||||
|
|||||||
@@ -463,10 +463,9 @@ void sphincs_wots_pk_to_root(const sphincs_wots_key_t pk,
|
|||||||
memcpy(root, dgst, sizeof(sphincs_hash128_t));
|
memcpy(root, dgst, sizeof(sphincs_hash128_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
// for both xmss and fors
|
|
||||||
void sphincs_tree_hash(const sphincs_hash128_t left_child, const sphincs_hash128_t right_child,
|
void sphincs_tree_hash(const sphincs_hash128_t left_child, const sphincs_hash128_t right_child,
|
||||||
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
const sphincs_hash128_t seed, const sphincs_adrs_t adrs,
|
||||||
sphincs_hash256_t parent)
|
sphincs_hash128_t parent)
|
||||||
{
|
{
|
||||||
SPHINCS_HASH256_CTX ctx;
|
SPHINCS_HASH256_CTX ctx;
|
||||||
sphincs_hash256_t dgst;
|
sphincs_hash256_t dgst;
|
||||||
@@ -544,7 +543,7 @@ void sphincs_xmss_build_auth_path(const sphincs_hash128_t tree[SPHINCS_XMSS_NUM_
|
|||||||
void sphincs_xmss_build_root(const sphincs_hash128_t wots_root, uint32_t tree_index,
|
void sphincs_xmss_build_root(const sphincs_hash128_t wots_root, uint32_t tree_index,
|
||||||
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs,
|
const sphincs_hash128_t seed, const sphincs_adrs_t in_adrs,
|
||||||
const sphincs_hash128_t auth_path[SPHINCS_XMSS_HEIGHT],
|
const sphincs_hash128_t auth_path[SPHINCS_XMSS_HEIGHT],
|
||||||
sphincs_hash256_t root)
|
sphincs_hash128_t root)
|
||||||
{
|
{
|
||||||
sphincs_adrs_t adrs = {0};
|
sphincs_adrs_t adrs = {0};
|
||||||
uint32_t h;
|
uint32_t h;
|
||||||
|
|||||||
Reference in New Issue
Block a user