1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-30 03:11:43 +00:00
pqcrypto/crypto_sign/sphincs-sha256-128s-simple/avx2/hash_sha256x8.c
Thom Wiggers facb527c7c SPHINCS+ optimized implementations (#253)
* Add state destroy to SHA2 API

* Include optimized SPHINCS+ implementations

I've generated new implementations from the sphincsplus repository.

* Don't destroy sha256ctx after finalize

* Attempt to shut up MSVC

* Make sure to drop errors in rmtree
2021-03-24 21:02:45 +00:00

62 lines
4.1 KiB
C

#include <stdint.h>
#include <string.h>
#include "address.h"
#include "hashx8.h"
#include "params.h"
#include "sha256.h"
#include "sha256avx.h"
#include "sha256x8.h"
#include "utils.h"
/*
* 8-way parallel version of prf_addr; takes 8x as much input and output
*/
void PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_prf_addrx8(unsigned char *out0,
unsigned char *out1,
unsigned char *out2,
unsigned char *out3,
unsigned char *out4,
unsigned char *out5,
unsigned char *out6,
unsigned char *out7,
const unsigned char *key,
const uint32_t addrx8[8 * 8]) {
unsigned char bufx8[8 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES)];
unsigned char outbufx8[8 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES];
unsigned int j;
for (j = 0; j < 8; j++) {
memcpy(bufx8 + j * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES), key, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_compress_address(bufx8 + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + j * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
addrx8 + j * 8);
}
PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_sha256x8(outbufx8 + 0 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
outbufx8 + 1 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
outbufx8 + 2 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
outbufx8 + 3 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
outbufx8 + 4 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
outbufx8 + 5 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
outbufx8 + 6 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
outbufx8 + 7 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES,
bufx8 + 0 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
bufx8 + 1 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
bufx8 + 2 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
bufx8 + 3 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
bufx8 + 4 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
bufx8 + 5 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
bufx8 + 6 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
bufx8 + 7 * (PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES),
PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_ADDR_BYTES);
memcpy(out0, outbufx8 + 0 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
memcpy(out1, outbufx8 + 1 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
memcpy(out2, outbufx8 + 2 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
memcpy(out3, outbufx8 + 3 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
memcpy(out4, outbufx8 + 4 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
memcpy(out5, outbufx8 + 5 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
memcpy(out6, outbufx8 + 6 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
memcpy(out7, outbufx8 + 7 * PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_SHA256_OUTPUT_BYTES, PQCLEAN_SPHINCSSHA256128SSIMPLE_AVX2_N);
}