Home | History | Annotate | Line # | Download | only in internal
      1      1.1  christos /*
      2      1.1  christos  * Copyright 2019-2024 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.1.2  christos #define OSSL_INTERNAL_SHA3_H
     13  1.1.1.2  christos #pragma once
     14      1.1  christos 
     15  1.1.1.2  christos #include <openssl/e_os2.h>
     16  1.1.1.2  christos #include <stddef.h>
     17      1.1  christos 
     18  1.1.1.2  christos #define KECCAK1600_WIDTH 1600
     19  1.1.1.2  christos #define SHA3_MDSIZE(bitlen) (bitlen / 8)
     20  1.1.1.2  christos #define KMAC_MDSIZE(bitlen) 2 * (bitlen / 8)
     21  1.1.1.2  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.1.2  christos typedef size_t(sha3_absorb_fn)(void *vctx, const void *in, size_t inlen);
     26  1.1.1.2  christos typedef int(sha3_final_fn)(void *vctx, unsigned char *out, size_t outlen);
     27  1.1.1.2  christos typedef int(sha3_squeeze_fn)(void *vctx, unsigned char *out, size_t outlen);
     28      1.1  christos 
     29      1.1  christos typedef struct prov_sha3_meth_st {
     30      1.1  christos     sha3_absorb_fn *absorb;
     31      1.1  christos     sha3_final_fn *final;
     32      1.1  christos     sha3_squeeze_fn *squeeze;
     33      1.1  christos } PROV_SHA3_METHOD;
     34      1.1  christos 
     35  1.1.1.2  christos #define XOF_STATE_INIT 0
     36  1.1.1.2  christos #define XOF_STATE_ABSORB 1
     37  1.1.1.2  christos #define XOF_STATE_FINAL 2
     38      1.1  christos #define XOF_STATE_SQUEEZE 3
     39      1.1  christos 
     40      1.1  christos struct keccak_st {
     41      1.1  christos     uint64_t A[5][5];
     42      1.1  christos     unsigned char buf[KECCAK1600_WIDTH / 8 - 32];
     43  1.1.1.2  christos     size_t block_size; /* cached ctx->digest->block_size */
     44  1.1.1.2  christos     size_t md_size; /* output length, variable in XOF */
     45  1.1.1.2  christos     size_t bufsz; /* used bytes in below buffer */
     46      1.1  christos     unsigned char pad;
     47      1.1  christos     PROV_SHA3_METHOD meth;
     48      1.1  christos     int xof_state;
     49      1.1  christos };
     50      1.1  christos 
     51      1.1  christos void ossl_sha3_reset(KECCAK1600_CTX *ctx);
     52      1.1  christos int ossl_sha3_init(KECCAK1600_CTX *ctx, unsigned char pad, size_t bitlen);
     53      1.1  christos int ossl_keccak_init(KECCAK1600_CTX *ctx, unsigned char pad,
     54  1.1.1.2  christos     size_t typelen, size_t mdlen);
     55      1.1  christos int ossl_sha3_update(KECCAK1600_CTX *ctx, const void *_inp, size_t len);
     56      1.1  christos int ossl_sha3_final(KECCAK1600_CTX *ctx, unsigned char *out, size_t outlen);
     57      1.1  christos int ossl_sha3_squeeze(KECCAK1600_CTX *ctx, unsigned char *out, size_t outlen);
     58      1.1  christos 
     59      1.1  christos size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len,
     60  1.1.1.2  christos     size_t r);
     61      1.1  christos 
     62      1.1  christos #endif /* OSSL_INTERNAL_SHA3_H */
     63