godot/thirdparty/mbedtls/library/sha3.c

/*
 *  FIPS-202 compliant SHA3 implementation
 *
 *  Copyright The Mbed TLS Contributors
 *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
 */
/*
 *  The SHA-3 Secure Hash Standard was published by NIST in 2015.
 *
 *  https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf
 */

#include "common.h"

#if defined(MBEDTLS_SHA3_C)

/*
 * These macros select manually unrolled implementations of parts of the main permutation function.
 *
 * Unrolling has a major impact on both performance and code size. gcc performance benefits a lot
 * from manually unrolling at higher optimisation levels.
 *
 * Depending on your size/perf priorities, compiler and target, it may be beneficial to adjust
 * these; the defaults here should give sensible trade-offs for gcc and clang on aarch64 and
 * x86-64.
 */
#if !defined(MBEDTLS_SHA3_THETA_UNROLL)
    #define MBEDTLS_SHA3_THETA_UNROLL
#endif
#if !defined(MBEDTLS_SHA3_CHI_UNROLL)
    #if defined(__OPTIMIZE_SIZE__)
        #define MBEDTLS_SHA3_CHI_UNROLL
    #else
        #define MBEDTLS_SHA3_CHI_UNROLL
    #endif
#endif
#if !defined(MBEDTLS_SHA3_PI_UNROLL)
    #define MBEDTLS_SHA3_PI_UNROLL
#endif
#if !defined(MBEDTLS_SHA3_RHO_UNROLL)
    #define MBEDTLS_SHA3_RHO_UNROLL
#endif

#include "mbedtls/sha3.h"
#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"

#include <string.h>

#if defined(MBEDTLS_SELF_TEST)
#include "mbedtls/platform.h"
#endif /* MBEDTLS_SELF_TEST */

#define XOR_BYTE

/* Precomputed masks for the iota transform.
 *
 * Each round uses a 64-bit mask value. In each mask values, only
 * bits whose position is of the form 2^k-1 can be set, thus only
 * 7 of 64 bits of the mask need to be known for each mask value.
 *
 * We use a compressed encoding of the mask where bits 63, 31 and 15
 * are moved to bits 4-6. This allows us to make each mask value
 * 1 byte rather than 8 bytes, saving 7*24 = 168 bytes of data (with
 * perhaps a little variation due to alignment). Decompressing this
 * requires a little code, but much less than the savings on the table.
 *
 * The impact on performance depends on the platform and compiler.
 * There's a bit more computation, but less memory bandwidth. A quick
 * benchmark on x86_64 shows a 7% speed improvement with GCC and a
 * 5% speed penalty with Clang, compared to the naive uint64_t[24] table.
 * YMMV.
 */
/* Helper macro to set the values of the higher bits in unused low positions */
#define H
static const uint8_t iota_r_packed[24] =;
#undef H

static const uint32_t rho[6] =;

static const uint32_t pi[6] =;

#define ROTR64(x, y)
#define ABSORB(ctx, idx, v)
#define SQUEEZE(ctx, idx)
#define SWAP(x, y)

/* The permutation function.  */
static void keccak_f1600(mbedtls_sha3_context *ctx)
{}

void mbedtls_sha3_init(mbedtls_sha3_context *ctx)
{}

void mbedtls_sha3_free(mbedtls_sha3_context *ctx)
{}

void mbedtls_sha3_clone(mbedtls_sha3_context *dst,
                        const mbedtls_sha3_context *src)
{}

/*
 * SHA-3 context setup
 */
int mbedtls_sha3_starts(mbedtls_sha3_context *ctx, mbedtls_sha3_id id)
{}

/*
 * SHA-3 process buffer
 */
int mbedtls_sha3_update(mbedtls_sha3_context *ctx,
                        const uint8_t *input,
                        size_t ilen)
{}

int mbedtls_sha3_finish(mbedtls_sha3_context *ctx,
                        uint8_t *output, size_t olen)
{}

/*
 * output = SHA-3( input buffer )
 */
int mbedtls_sha3(mbedtls_sha3_id id, const uint8_t *input,
                 size_t ilen, uint8_t *output, size_t olen)
{}

/**************** Self-tests ****************/

#if defined(MBEDTLS_SELF_TEST)

static const unsigned char test_data[2][4] =;

static const size_t test_data_len[2] =;

static const unsigned char test_hash_sha3_224[2][28] =;

static const unsigned char test_hash_sha3_256[2][32] =;

static const unsigned char test_hash_sha3_384[2][48] =;

static const unsigned char test_hash_sha3_512[2][64] =;

static const unsigned char long_kat_hash_sha3_224[28] =;

static const unsigned char long_kat_hash_sha3_256[32] =;

static const unsigned char long_kat_hash_sha3_384[48] =;

static const unsigned char long_kat_hash_sha3_512[64] =;

static int mbedtls_sha3_kat_test(int verbose,
                                 const char *type_name,
                                 mbedtls_sha3_id id,
                                 int test_num)
{}

static int mbedtls_sha3_long_kat_test(int verbose,
                                      const char *type_name,
                                      mbedtls_sha3_id id)
{}

int mbedtls_sha3_self_test(int verbose)
{}
#endif /* MBEDTLS_SELF_TEST */

#endif /* MBEDTLS_SHA3_C */