Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 81a0bf97e2012c369f800f26e2e3d3651cde7a35 authored by Matthias J. Kannwischer on 29 July 2021, 07:22:18 UTC, committed by Matthias J. Kannwischer on 02 August 2021, 03:06:46 UTC
Update NTRU Prime; add new round 3 parameter sets
1 parent 819f906
  • Files
  • Changes
  • b53fadd
  • /
  • crypto_sign
  • /
  • sphincs-shake256-256s-simple
  • /
  • avx2
  • /
  • hash_shake256.c
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:81a0bf97e2012c369f800f26e2e3d3651cde7a35
directory badge Iframe embedding
swh:1:dir:228f9241d780f7e1061c8459aa4c0d9a28d87f7e
content badge Iframe embedding
swh:1:cnt:23f34d941c31fc037ec45e7c362b14e1ef85d533
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
hash_shake256.c
#include <stdint.h>
#include <string.h>

#include "address.h"
#include "hash.h"
#include "params.h"
#include "utils.h"

#include "fips202.h"

/* For SHAKE256, there is no immediate reason to initialize at the start,
   so this function is an empty operation. */
void PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_initialize_hash_function(
    hash_state *hash_state_seeded, // NOLINT(readability-non-const-parameter)
    const unsigned char *pub_seed, const unsigned char *sk_seed) {
    (void)hash_state_seeded; /* Suppress an 'unused parameter' warning. */
    (void)pub_seed; /* Suppress an 'unused parameter' warning. */
    (void)sk_seed; /* Suppress an 'unused parameter' warning. */
}

/* This is not necessary for SHAKE256, so we don't do anything */
void PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_destroy_hash_function(
    hash_state *hash_state_seeded) { // NOLINT(readability-non-const-parameter)
    (void)hash_state_seeded;
}

/*
 * Computes PRF(key, addr), given a secret key of PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N bytes and an address
 */
void PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_prf_addr(
    unsigned char *out, const unsigned char *key, const uint32_t addr[8],
    const hash_state *hash_state_seeded) {
    unsigned char buf[PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_ADDR_BYTES];

    memcpy(buf, key, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N);
    PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_addr_to_bytes(buf + PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N, addr);

    shake256(out, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N, buf, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N + PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_ADDR_BYTES);

    (void)hash_state_seeded; /* Prevent unused parameter warning. */
}

/**
 * Computes the message-dependent randomness R, using a secret seed and an
 * optional randomization value as well as the message.
 */
void PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_gen_message_random(
    unsigned char *R,
    const unsigned char *sk_prf, const unsigned char *optrand,
    const unsigned char *m, size_t mlen,
    const hash_state *hash_state_seeded) {
    shake256incctx state;

    shake256_inc_init(&state);
    shake256_inc_absorb(&state, sk_prf, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N);
    shake256_inc_absorb(&state, optrand, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N);
    shake256_inc_absorb(&state, m, mlen);
    shake256_inc_finalize(&state);
    shake256_inc_squeeze(R, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N, &state);
    shake256_inc_ctx_release(&state);

    (void)hash_state_seeded; /* Prevent unused parameter warning. */
}

/**
 * Computes the message hash using R, the public key, and the message.
 * Outputs the message digest and the index of the leaf. The index is split in
 * the tree index and the leaf index, for convenient copying to an address.
 */
void PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_hash_message(
    unsigned char *digest, uint64_t *tree, uint32_t *leaf_idx,
    const unsigned char *R, const unsigned char *pk,
    const unsigned char *m, size_t mlen,
    const hash_state *hash_state_seeded) {
#define PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_BITS (PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_HEIGHT * (PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_D - 1))
#define PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_BYTES ((PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_BITS + 7) / 8)
#define PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_LEAF_BITS PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_HEIGHT
#define PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_LEAF_BYTES ((PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_LEAF_BITS + 7) / 8)
#define PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_DGST_BYTES (PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_FORS_MSG_BYTES + PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_BYTES + PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_LEAF_BYTES)

    unsigned char buf[PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_DGST_BYTES];
    unsigned char *bufp = buf;
    shake256incctx state;

    shake256_inc_init(&state);
    shake256_inc_absorb(&state, R, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_N);
    shake256_inc_absorb(&state, pk, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_PK_BYTES);
    shake256_inc_absorb(&state, m, mlen);
    shake256_inc_finalize(&state);
    shake256_inc_squeeze(buf, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_DGST_BYTES, &state);
    shake256_inc_ctx_release(&state);

    memcpy(digest, bufp, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_FORS_MSG_BYTES);
    bufp += PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_FORS_MSG_BYTES;

    *tree = PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_bytes_to_ull(
                bufp, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_BYTES);
    *tree &= (~(uint64_t)0) >> (64 - PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_BITS);
    bufp += PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_TREE_BYTES;

    *leaf_idx = (uint32_t)PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_bytes_to_ull(
                    bufp, PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_LEAF_BYTES);
    *leaf_idx &= (~(uint32_t)0) >> (32 - PQCLEAN_SPHINCSSHAKE256256SSIMPLE_AVX2_LEAF_BITS);

    (void)hash_state_seeded; /* Prevent unused parameter warning. */
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API