Files
easy7zip/C/hashes/sha3.h
Tino Reichardt e19abb2958 shunf4 cherry-picking hash related commits from zstd. The following commits from 7-zip-zstd repository (https://github.com/mcmilk/7-Zip-zstd) is picked:
commit add56b5aed
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Thu Nov 1 23:08:00 2018 +0100

    Add MD5 hash function

commit 36a17a5184
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Sat Nov 3 00:18:33 2018 +0100

    Add some hash functions
    - new: md2, md4, md5, sha384, sha512, xxhash-32, xxhash-64
    - put Blake2sp hash stuff back to rar code
    - added the hashes to GUI and Explorer Menu code

commit 576c5df947
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Tue Apr 6 19:35:46 2021 +0200

    Add BLAKE3 hash function

commit 6b2a151549
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Tue Apr 6 19:51:01 2021 +0200

    Remove unneeded file HashesReg.cpp

commit dddf507557
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Sun Jun 18 09:13:59 2023 +0200

    Add SHA3 hashing

    - added these variants: SHA3-256, SHA3-384, SHA3-512
    - reordered also the hashing id's
    - added some notes about them in DOC/Hashes.txt

    Signed-off-by: Tino Reichardt <milky-7zip@mcmilk.de>

The cherry-picking was a chaos; they're not applied in order, and some
commits even got cherry-picked twice (1->4->0->2->4->3). So subsequent fixes and
adjustments were applied to make it build.
2024-05-13 22:20:40 +08:00

48 lines
1.3 KiB
C

/**
* Canonical implementation of Init/Update/Finalize for SHA-3 byte input.
* Based on code from https://github.com/brainhub/SHA3IUF/
*
* This work is released into the public domain with CC0 1.0.
*
* Copyright (c) 2015. Andrey Jivsov <crypto@brainhub.org>
* Copyright (c) 2023 Tino Reichardt <milky-7zip@mcmilk.de>
*/
#ifndef SHA3_H
#define SHA3_H
#include <stdint.h>
#pragma warning(disable : 4464)
#pragma warning(disable : 4820)
#pragma warning(disable : 4711)
#define SHA3_256_DIGEST_LENGTH 32
#define SHA3_384_DIGEST_LENGTH 48
#define SHA3_512_DIGEST_LENGTH 64
/* 'Words' here refers to uint64_t */
#define SHA3_KECCAK_SPONGE_WORDS (200 / sizeof(uint64_t))
typedef struct sha3_context_ {
/* the portion of the input message that we didn't consume yet */
uint64_t saved;
uint64_t byteIndex; /* 0..7--the next byte after the set one */
uint64_t wordIndex; /* 0..24--the next word to integrate input */
uint64_t capacityWords; /* the double size of the hash output in words */
/* Keccak's state */
union {
uint64_t s[SHA3_KECCAK_SPONGE_WORDS];
uint8_t sb[SHA3_KECCAK_SPONGE_WORDS * 8];
} u;
unsigned digest_length;
} SHA3_CTX;
void SHA3_Init(SHA3_CTX * ctx, unsigned bitSize);
void SHA3_Update(SHA3_CTX * ctx, void const *bufIn, size_t len);
void SHA3_Final(void *, SHA3_CTX * ctx);
#endif