rv1126-uboot/include/u-boot/sha512.h

99 lines
3.1 KiB
C
Raw Normal View History

// SPDX-License-Identifier: Apache-2.0
/*
* FIPS-180-2 compliant SHA-384/512 implementation
*
* Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
/*
* The SHA-512 Secure Hash Standard was published by NIST in 2002.
*
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/
#ifndef _SHA512_H
#define _SHA512_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief The SHA-512 context structure.
*
* The structure is used both for SHA-384 and for SHA-512
* checksum calculations. The choice between these two is
* made in the call to sha512_starts().
*/
typedef struct sha512_context {
uint64_t total[2]; /*!< The number of Bytes processed. */
uint64_t state[8]; /*!< The intermediate digest state. */
unsigned char buffer[128]; /*!< The data block being processed. */
int is384; /*!< Determines which function to use:
0: Use SHA-512, or 1: Use SHA-384. */
} sha512_context;
/**
* \brief This function starts a SHA-384 or SHA-512 checksum
* calculation.
*
* \param ctx The SHA-512 context to initialize.
* \param is384 Determines which function to use:
* 0: Use SHA-512, or 1: Use SHA-384.
*
* \return \c 0 on success.
*/
int sha512_starts(sha512_context *ctx);
/**
* \brief This function feeds an input buffer into an ongoing
* SHA-512 checksum calculation.
*
* \param ctx The SHA-512 context.
* \param input The buffer holding the input data.
* \param ilen The length of the input data.
*
* \return \c 0 on success.
*/
int sha512_update(sha512_context *ctx, const unsigned char *input, size_t ilen);
/**
* \brief This function finishes the SHA-512 operation, and writes
* the result to the output buffer.
*
* \param ctx The SHA-512 context.
* \param output The SHA-384 or SHA-512 checksum result.
*
* \return \c 0 on success.
*/
int sha512_finish(sha512_context *ctx, unsigned char output[64]);
/**
* \brief This function starts SHA-512 checksum for the input data.
*
* \param input The buffer holding the input data.
* \param ilen The length of the input data.
* \param output The SHA-384 or SHA-512 checksum result.
*/
void sha512_csum(const unsigned char *input, unsigned int ilen,
unsigned char output[64]);
#ifdef __cplusplus
}
#endif
#endif /* sha512.h */