linux/include/crypto/sha2.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Common values for SHA-2 algorithms
 */

#ifndef _CRYPTO_SHA2_H
#define _CRYPTO_SHA2_H

#include <linux/types.h>

#define SHA224_DIGEST_SIZE
#define SHA224_BLOCK_SIZE

#define SHA256_DIGEST_SIZE
#define SHA256_BLOCK_SIZE

#define SHA384_DIGEST_SIZE
#define SHA384_BLOCK_SIZE

#define SHA512_DIGEST_SIZE
#define SHA512_BLOCK_SIZE

#define SHA224_H0
#define SHA224_H1
#define SHA224_H2
#define SHA224_H3
#define SHA224_H4
#define SHA224_H5
#define SHA224_H6
#define SHA224_H7

#define SHA256_H0
#define SHA256_H1
#define SHA256_H2
#define SHA256_H3
#define SHA256_H4
#define SHA256_H5
#define SHA256_H6
#define SHA256_H7

#define SHA384_H0
#define SHA384_H1
#define SHA384_H2
#define SHA384_H3
#define SHA384_H4
#define SHA384_H5
#define SHA384_H6
#define SHA384_H7

#define SHA512_H0
#define SHA512_H1
#define SHA512_H2
#define SHA512_H3
#define SHA512_H4
#define SHA512_H5
#define SHA512_H6
#define SHA512_H7

extern const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE];

extern const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE];

extern const u8 sha384_zero_message_hash[SHA384_DIGEST_SIZE];

extern const u8 sha512_zero_message_hash[SHA512_DIGEST_SIZE];

struct sha256_state {};

struct sha512_state {};

struct shash_desc;

extern int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
			      unsigned int len);

extern int crypto_sha256_finup(struct shash_desc *desc, const u8 *data,
			       unsigned int len, u8 *hash);

extern int crypto_sha512_update(struct shash_desc *desc, const u8 *data,
			      unsigned int len);

extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data,
			       unsigned int len, u8 *hash);

/*
 * Stand-alone implementation of the SHA256 algorithm. It is designed to
 * have as little dependencies as possible so it can be used in the
 * kexec_file purgatory. In other cases you should generally use the
 * hash APIs from include/crypto/hash.h. Especially when hashing large
 * amounts of data as those APIs may be hw-accelerated.
 *
 * For details see lib/crypto/sha256.c
 */

static inline void sha256_init(struct sha256_state *sctx)
{}
void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len);
void sha256_final(struct sha256_state *sctx, u8 *out);
void sha256(const u8 *data, unsigned int len, u8 *out);

static inline void sha224_init(struct sha256_state *sctx)
{}
/* Simply use sha256_update as it is equivalent to sha224_update. */
void sha224_final(struct sha256_state *sctx, u8 *out);

#endif /* _CRYPTO_SHA2_H */