| /** |
| * \file mbedtls_sha256.h |
| * |
| * \brief SHA-224 and SHA-256 cryptographic hash function |
| * |
| * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
| * |
| * This file is part of mbed TLS (https://tls.mbed.org) |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License as published by |
| * the Free Software Foundation; either version 2 of the License, or |
| * (at your option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along |
| * with this program; if not, write to the Free Software Foundation, Inc., |
| * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| */ |
| #ifndef MBEDTLS_SHA256_ALT_H |
| #define MBEDTLS_SHA256_ALT_H |
| |
| #if !defined(MBEDTLS_CONFIG_FILE) |
| #include "config.h" |
| #else |
| #include MBEDTLS_CONFIG_FILE |
| #endif |
| |
| #include <stddef.h> |
| #include <stdint.h> |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| |
| /** |
| * \brief SHA-256 context structure |
| */ |
| typedef struct |
| { |
| uint32_t total[2]; /*!< number of bytes processed */ |
| uint32_t state[8]; /*!< intermediate digest state */ |
| unsigned char buffer[64]; /*!< data block being processed */ |
| int is224; /*!< 0 => SHA-256, else SHA-224 */ |
| } mbedtls_sha256_context; |
| |
| /** |
| * \brief This function initializes a SHA-256 context. |
| * |
| * \param ctx The SHA-256 context to initialize. |
| */ |
| void mbedtls_sha256_init(mbedtls_sha256_context *ctx); |
| |
| /** |
| * \brief This function clears a SHA-256 context. |
| * |
| * \param ctx The SHA-256 context to clear. |
| */ |
| void mbedtls_sha256_free(mbedtls_sha256_context *ctx); |
| |
| /** |
| * \brief This function clones the state of a SHA-256 context. |
| * |
| * \param dst The destination context. |
| * \param src The context to clone. |
| */ |
| void mbedtls_sha256_clone(mbedtls_sha256_context *dst, const mbedtls_sha256_context *src); |
| |
| /** |
| * \brief This function starts a SHA-224 or SHA-256 checksum |
| * calculation. |
| * |
| * \param ctx The context to initialize. |
| * \param is224 Determines which function to use. |
| * <ul><li>0: Use SHA-256.</li> |
| * <li>1: Use SHA-224.</li></ul> |
| * |
| * \return \c 0 on success. |
| */ |
| int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224); |
| |
| /** |
| * \brief This function feeds an input buffer into an ongoing |
| * SHA-256 checksum calculation. |
| * |
| * \param ctx SHA-256 context |
| * \param input buffer holding the data |
| * \param ilen length of the input data |
| * |
| * \return \c 0 on success. |
| */ |
| int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen); |
| |
| /** |
| * \brief This function finishes the SHA-256 operation, and writes |
| * the result to the output buffer. |
| * |
| * \param ctx The SHA-256 context. |
| * \param output The SHA-224 or SHA-256 checksum result. |
| * |
| * \return \c 0 on success. |
| */ |
| int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32]); |
| |
| /** |
| * \brief This function processes a single data block within |
| * the ongoing SHA-256 computation. This function is for |
| * internal use only. |
| * |
| * \param ctx The SHA-256 context. |
| * \param data The buffer holding one block of data. |
| * |
| * \return \c 0 on success. |
| */ |
| int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64]); |
| |
| #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| #if defined(MBEDTLS_DEPRECATED_WARNING) |
| #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| #else |
| #define MBEDTLS_DEPRECATED |
| #endif |
| /** |
| * \brief This function starts a SHA-256 checksum calculation. |
| * |
| * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0. |
| * |
| * \param ctx The SHA-256 context to initialize. |
| * \param is224 Determines which function to use. |
| * <ul><li>0: Use SHA-256.</li> |
| * <li>1: Use SHA-224.</li></ul> |
| */ |
| MBEDTLS_DEPRECATED static inline void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) |
| { |
| mbedtls_sha256_starts_ret(ctx, is224); |
| } |
| |
| /** |
| * \brief This function feeds an input buffer into an ongoing |
| * SHA-256 checksum calculation. |
| * |
| * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0. |
| * |
| * \param ctx The SHA-256 context to initialize. |
| * \param input The buffer holding the data. |
| * \param ilen The length of the input data. |
| */ |
| MBEDTLS_DEPRECATED static inline void mbedtls_sha256_update(mbedtls_sha256_context *ctx, |
| const unsigned char * input, |
| size_t ilen) |
| { |
| mbedtls_sha256_update_ret(ctx, input, ilen); |
| } |
| |
| /** |
| * \brief This function finishes the SHA-256 operation, and writes |
| * the result to the output buffer. |
| * |
| * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0. |
| * |
| * \param ctx The SHA-256 context. |
| * \param output The SHA-224or SHA-256 checksum result. |
| */ |
| MBEDTLS_DEPRECATED static inline void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32]) |
| { |
| mbedtls_sha256_finish_ret(ctx, output); |
| } |
| |
| /** |
| * \brief This function processes a single data block within |
| * the ongoing SHA-256 computation. This function is for |
| * internal use only. |
| * |
| * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0. |
| * |
| * \param ctx The SHA-256 context. |
| * \param data The buffer holding one block of data. |
| */ |
| MBEDTLS_DEPRECATED static inline void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64]) |
| { |
| mbedtls_internal_sha256_process(ctx, data); |
| } |
| |
| #undef MBEDTLS_DEPRECATED |
| #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| #ifdef __cplusplus |
| } |
| #endif |
| |
| #endif |