mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-09-24 06:13:43 +08:00
add sphincs
This commit is contained in:
56
crypto/sphincs/primitives/hash.c
Normal file
56
crypto/sphincs/primitives/hash.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Nagravision S.A.
|
||||
*/
|
||||
#include "../hash.h"
|
||||
|
||||
#include "haraka.h"
|
||||
#include <openssl/sha.h>
|
||||
|
||||
void hash_N_to_N(struct hash *dst, const struct hash *src)
|
||||
{
|
||||
haraka256_256(dst->h, src->h);
|
||||
}
|
||||
|
||||
void hash_N_to_N_chain(struct hash *dst, const struct hash *src, int chainlen)
|
||||
{
|
||||
haraka256_256_chain(dst->h, src->h, chainlen);
|
||||
}
|
||||
|
||||
void hash_2N_to_N(struct hash *dst, const struct hash *src)
|
||||
{
|
||||
haraka512_256(dst->h, src->h);
|
||||
}
|
||||
|
||||
void hash_to_N(struct hash *dst, const uint8_t *src, uint64_t srclen)
|
||||
{
|
||||
SHA256(src, srclen, dst->h);
|
||||
}
|
||||
|
||||
void hash_compress_pairs(struct hash *dst, const struct hash *src, int count)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < count; ++i)
|
||||
hash_2N_to_N(&dst[i], &src[2*i]);
|
||||
}
|
||||
|
||||
void hash_compress_all(struct hash *dst, const struct hash *src, int count)
|
||||
{
|
||||
/* Fast implementation with a single call to a large input hash function */
|
||||
hash_to_N(dst, src->h, count * HASH_SIZE);
|
||||
/* TODO: implement a real L-tree with 2N->N compression function */
|
||||
}
|
||||
|
||||
void hash_parallel(struct hash *dst, const struct hash *src, int count)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < count; ++i)
|
||||
hash_N_to_N(&dst[i], &src[i]);
|
||||
}
|
||||
|
||||
void hash_parallel_chains(struct hash *dst, const struct hash *src, int count, int chainlen)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < count; ++i)
|
||||
hash_N_to_N_chain(&dst[i], &src[i], chainlen);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user