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