| 1 | /* |
| 2 | * Copyright (C) 2021 - 2026, Stephan Mueller <[email protected]> |
| 3 | * |
| 4 | * License: see LICENSE file in root directory |
| 5 | * |
| 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF |
| 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE |
| 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
| 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | */ |
| 19 | |
| 20 | #ifndef JITTERENTROPY_SHA3_H |
| 21 | #define JITTERENTROPY_SHA3_Hcxx . . $ `lib/jitterentropy-sha3.h:21:9`! |
| 22 | |
| 23 | #include "jitterentropy-internal.h"cxx . . $ `<file>/lib/jitterentropy-internal.h`/ |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" |
| 27 | { |
| 28 | #endif |
| 29 | |
| 30 | #define JENT_SHA3_SIZE_BLOCKcxx . . $ `lib/jitterentropy-sha3.h:30:9`!(bits) ((1600 - 2 * bits) >> 3) |
| 31 | |
| 32 | #define JENT_SHA3_256_SIZE_BLOCKcxx . . $ `lib/jitterentropy-sha3.h:32:9`! \ |
| 33 | JENT_SHA3_SIZE_BLOCKcxx . . $ `lib/jitterentropy-sha3.h:30:9`!(JENT_SHA3_256_SIZE_DIGEST_BITScxx . . $ `lib/jitterentropy-internal.h:254:9`!) |
| 34 | |
| 35 | #define JENT_XDRBG_SIZE_STATEcxx . . $ `lib/jitterentropy-sha3.h:35:9`! 64 |
| 36 | |
| 37 | struct jent_sha_ctxcxx . . $ jent_sha_ctx# { |
| 38 | uint64_tcxx . . $ uint64_t# statecxx . . $ jent_sha_ctx#state.[25]; |
| 39 | uint8_tcxx . . $ uint8_t# partialcxx . . $ jent_sha_ctx#partial.[JENT_SHA3_256_SIZE_BLOCKcxx . . $ `lib/jitterentropy-sha3.h:32:9`!]; |
| 40 | size_t msg_lencxx . . $ jent_sha_ctx#msg_len.; |
| 41 | uint8_tcxx . . $ uint8_t# rcxx . . $ jent_sha_ctx#r.; |
| 42 | uint8_tcxx . . $ uint8_t# rwordcxx . . $ jent_sha_ctx#rword.; |
| 43 | /* |
| 44 | * This implementation only supports up to rate-size digests for XOFs, |
| 45 | * thus the data type can be appropriately small. |
| 46 | */ |
| 47 | uint8_tcxx . . $ uint8_t# digestsizecxx . . $ jent_sha_ctx#digestsize.; |
| 48 | uint8_tcxx . . $ uint8_t# paddingcxx . . $ jent_sha_ctx#padding.; |
| 49 | uint8_tcxx . . $ uint8_t# initially_seededcxx . . $ jent_sha_ctx#initially_seeded.:1; |
| 50 | }; |
| 51 | |
| 52 | #define JENT_SHA_MAX_CTX_SIZEcxx . . $ `lib/jitterentropy-sha3.h:52:9`! (sizeof(struct jent_sha_ctx)) |
| 53 | #define HASH_CTX_ON_STACKcxx . . $ `lib/jitterentropy-sha3.h:53:9`!(name) \ |
| 54 | struct jent_sha_ctx name |
| 55 | |
| 56 | static inline unsigned int jent_sha3_ratecxx . . $ jent_sha3_rate(6769d0e399bf81e3).(void *hash_state) |
| 57 | { |
| 58 | struct jent_sha_ctxcxx . . $ jent_sha_ctx# *ctx = hash_state; |
| 59 | |
| 60 | return ctx->rcxx . . $ jent_sha_ctx#r.; |
| 61 | } |
| 62 | |
| 63 | void jent_sha3_256_initcxx . . $ jent_sha3_256_init(86d95783d3e80d87).(struct jent_sha_ctxcxx . . $ jent_sha_ctx# *ctx); |
| 64 | void jent_sha3_updatecxx . . $ jent_sha3_update(4f2271f98ec6a915).(struct jent_sha_ctxcxx . . $ jent_sha_ctx# *ctx, const uint8_tcxx . . $ uint8_t# *in, |
| 65 | size_t inlen); |
| 66 | void jent_sha3_finalcxx . . $ jent_sha3_final(e07c871ace1d2160).(struct jent_sha_ctxcxx . . $ jent_sha_ctx# *ctx, uint8_tcxx . . $ uint8_t# *digest); |
| 67 | int jent_sha3_alloccxx . . $ jent_sha3_alloc(22ee7711e4bb6c63).(void **hash_state); |
| 68 | void jent_sha3_dealloccxx . . $ jent_sha3_dealloc(5d22bdacc48458e8).(void *hash_state); |
| 69 | int jent_sha3_testercxx . . $ jent_sha3_tester(b126dc7c1de90089).(void); |
| 70 | |
| 71 | void jent_shake256_initcxx . . $ jent_shake256_init(86d95783d3e80d87).(struct jent_sha_ctxcxx . . $ jent_sha_ctx# *ctx); |
| 72 | static inline void jent_shake256_set_digestsizecxx . . $ jent_shake256_set_digestsize(b8bc560ae22c52e6).(struct jent_sha_ctxcxx . . $ jent_sha_ctx# *ctx, |
| 73 | unsigned int digestsize) |
| 74 | { |
| 75 | ctx->digestsizecxx . . $ jent_sha_ctx#digestsize. = (uint8_tcxx . . $ uint8_t#)digestsize; |
| 76 | } |
| 77 | void jent_drbg_generate_blockcxx . . $ jent_drbg_generate_block(5c0374f9bc02e3a7).(struct jent_sha_ctxcxx . . $ jent_sha_ctx# *ctx, uint8_tcxx . . $ uint8_t# *dst, |
| 78 | size_t dst_len); |
| 79 | |
| 80 | #ifdef __cplusplus |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | #endif /* JITTERENTROPY_SHA3_H */ |