1 1.1 christos /* 2 1.1 christos * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos 10 1.1 christos /* This header can move into provider when legacy support is removed */ 11 1.1 christos #ifndef OSSL_INTERNAL_SHA3_H 12 1.1 christos # define OSSL_INTERNAL_SHA3_H 13 1.1 christos # pragma once 14 1.1 christos 15 1.1 christos # include <openssl/e_os2.h> 16 1.1 christos # include <stddef.h> 17 1.1 christos 18 1.1 christos # define KECCAK1600_WIDTH 1600 19 1.1 christos # define SHA3_MDSIZE(bitlen) (bitlen / 8) 20 1.1 christos # define KMAC_MDSIZE(bitlen) 2 * (bitlen / 8) 21 1.1 christos # define SHA3_BLOCKSIZE(bitlen) (KECCAK1600_WIDTH - bitlen * 2) / 8 22 1.1 christos 23 1.1 christos typedef struct keccak_st KECCAK1600_CTX; 24 1.1 christos 25 1.1 christos typedef size_t (sha3_absorb_fn)(void *vctx, const void *inp, size_t len); 26 1.1 christos typedef int (sha3_final_fn)(unsigned char *md, void *vctx); 27 1.1 christos 28 1.1 christos typedef struct prov_sha3_meth_st 29 1.1 christos { 30 1.1 christos sha3_absorb_fn *absorb; 31 1.1 christos sha3_final_fn *final; 32 1.1 christos } PROV_SHA3_METHOD; 33 1.1 christos 34 1.1 christos struct keccak_st { 35 1.1 christos uint64_t A[5][5]; 36 1.1 christos size_t block_size; /* cached ctx->digest->block_size */ 37 1.1 christos size_t md_size; /* output length, variable in XOF */ 38 1.1 christos size_t bufsz; /* used bytes in below buffer */ 39 1.1 christos unsigned char buf[KECCAK1600_WIDTH / 8 - 32]; 40 1.1 christos unsigned char pad; 41 1.1 christos PROV_SHA3_METHOD meth; 42 1.1 christos }; 43 1.1 christos 44 1.1 christos void ossl_sha3_reset(KECCAK1600_CTX *ctx); 45 1.1 christos int ossl_sha3_init(KECCAK1600_CTX *ctx, unsigned char pad, size_t bitlen); 46 1.1 christos int ossl_keccak_kmac_init(KECCAK1600_CTX *ctx, unsigned char pad, 47 1.1 christos size_t bitlen); 48 1.1 christos int ossl_sha3_update(KECCAK1600_CTX *ctx, const void *_inp, size_t len); 49 1.1 christos int ossl_sha3_final(unsigned char *md, KECCAK1600_CTX *ctx); 50 1.1 christos 51 1.1 christos size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len, 52 1.1 christos size_t r); 53 1.1 christos 54 1.1 christos #endif /* OSSL_INTERNAL_SHA3_H */ 55