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