Improve SHA-256 documentation on parameter preconditions

This commit is contained in:
Hanno Becker 2018-12-18 14:54:04 +00:00
parent 0152f1e948
commit 77886af63e

View file

@ -72,25 +72,24 @@ mbedtls_sha256_context;
/** /**
* \brief This function initializes a SHA-256 context. * \brief This function initializes a SHA-256 context.
* *
* \param ctx The SHA-256 context to initialize. * \param ctx The SHA-256 context to initialize. This must not be \c NULL.
* Must not be \c NULL.
*/ */
void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
/** /**
* \brief This function clears a SHA-256 context. * \brief This function clears a SHA-256 context.
* *
* \param ctx The SHA-256 context to clear. * \param ctx The SHA-256 context to clear. This may be \c NULL, in which
* case this function returns immediately. If it is not \c NULL,
* it must point to an initialized SHA-256 context.
*/ */
void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
/** /**
* \brief This function clones the state of a SHA-256 context. * \brief This function clones the state of a SHA-256 context.
* *
* \param dst The destination context. * \param dst The destination context. This must be initialized.
* Must not be \c NULL. * \param src The context to clone. This must be initialized.
* \param src The context to clone.
* Must not be \c NULL.
*/ */
void mbedtls_sha256_clone( mbedtls_sha256_context *dst, void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
const mbedtls_sha256_context *src ); const mbedtls_sha256_context *src );
@ -99,12 +98,12 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
* \brief This function starts a SHA-224 or SHA-256 checksum * \brief This function starts a SHA-224 or SHA-256 checksum
* calculation. * calculation.
* *
* \param ctx The context to initialize. * \param ctx The context to use. This must be initialized.
* Must not be \c NULL. * \param is224 This determines which function to use. This must be
* \param is224 Determines which function to use: * either \c 0 for SHA-256, or \c 1 for SHA-224.
* 0: Use SHA-256, or 1: Use SHA-224.
* *
* \return \c 0 on success. * \return \c 0 on success.
* \return A negative error code on failure.
*/ */
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ); int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
@ -112,13 +111,14 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
* \brief This function feeds an input buffer into an ongoing * \brief This function feeds an input buffer into an ongoing
* SHA-256 checksum calculation. * SHA-256 checksum calculation.
* *
* \param ctx The SHA-256 context. * \param ctx The SHA-256 context. This must be initialized
* Must not be \c NULL. * and have a hash operation started.
* \param input The buffer holding the data. * \param input The buffer holding the data. This must be a readable
* Must not be \c NULL if \p ilen is greater than 0. * buffer of length \p ilen Bytes.
* \param ilen The length of the input data. * \param ilen The length of the input data \p input in Bytes.
* *
* \return \c 0 on success. * \return \c 0 on success.
* \return A negative error code on failure.
*/ */
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
const unsigned char *input, const unsigned char *input,
@ -128,12 +128,13 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
* \brief This function finishes the SHA-256 operation, and writes * \brief This function finishes the SHA-256 operation, and writes
* the result to the output buffer. * the result to the output buffer.
* *
* \param ctx The SHA-256 context. * \param ctx The SHA-256 context. This must be initialized
* Must not be \c NULL. * and have a hash operation started.
* \param output The SHA-224 or SHA-256 checksum result. * \param output The SHA-224 or SHA-256 checksum result.
* Must not be \c NULL. * This must be a writable buffer of length \c 32 Bytes.
* *
* \return \c 0 on success. * \return \c 0 on success.
* \return A negative error code on failure.
*/ */
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
unsigned char output[32] ); unsigned char output[32] );
@ -143,12 +144,13 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
* the ongoing SHA-256 computation. This function is for * the ongoing SHA-256 computation. This function is for
* internal use only. * internal use only.
* *
* \param ctx The SHA-256 context. * \param ctx The SHA-256 context. This must be initialized
* Must not be \c NULL. * and have a hash operation started.
* \param data The buffer holding one block of data. * \param data The buffer holding one block of data. This must
* Must not be \c NULL. * be a readable buffer of length \c 64 Bytes.
* *
* \return \c 0 on success. * \return \c 0 on success.
* \return A negative error code on failure.
*/ */
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
const unsigned char data[64] ); const unsigned char data[64] );
@ -163,13 +165,11 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
* \brief This function starts a SHA-224 or SHA-256 checksum * \brief This function starts a SHA-224 or SHA-256 checksum
* calculation. * calculation.
* *
*
* \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0. * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
* *
* \param ctx The context to initialize. * \param ctx The context to use. This must be initialized.
* Must not be \c NULL. * \param is224 Determines which function to use. This must be
* \param is224 Determines which function to use: * either \c 0 for SHA-256, or \c 1 for SHA-224.
* 0: Use SHA-256, or 1: Use SHA-224.
*/ */
MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
int is224 ); int is224 );
@ -180,11 +180,11 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
* *
* \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0. * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
* *
* \param ctx The SHA-256 context to initialize. * \param ctx The SHA-256 context to use. This must be
* Must not be \c NULL. * initialized and have a hash operation started.
* \param input The buffer holding the data. * \param input The buffer holding the data. This must be a readable
* Must not be \c NULL if \p ilen is greater than 0. * buffer of length \p ilen Bytes.
* \param ilen The length of the input data. * \param ilen The length of the input data \p input in Bytes.
*/ */
MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx, MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
const unsigned char *input, const unsigned char *input,
@ -196,10 +196,10 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
* *
* \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0. * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
* *
* \param ctx The SHA-256 context. * \param ctx The SHA-256 context. This must be initialized and
* Must not be \c NULL. * have a has hoperation started.
* \param output The SHA-224 or SHA-256 checksum result. * \param output The SHA-224 or SHA-256 checksum result. This must be
* Must not be \c NULL. * a writable buffer of length \c 32 Bytes.
*/ */
MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
unsigned char output[32] ); unsigned char output[32] );
@ -211,10 +211,10 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
* *
* \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0. * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0.
* *
* \param ctx The SHA-256 context. * \param ctx The SHA-256 context. This must be initialized and
* Must not be \c NULL. * have a hash operation started.
* \param data The buffer holding one block of data. * \param data The buffer holding one block of data. This must be
* Must not be \c NULL. * a readable buffer of size \c 64 Bytes.
*/ */
MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx, MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
const unsigned char data[64] ); const unsigned char data[64] );
@ -232,13 +232,13 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
* The SHA-256 result is calculated as * The SHA-256 result is calculated as
* output = SHA-256(input buffer). * output = SHA-256(input buffer).
* *
* \param input The buffer holding the input data. * \param input The buffer holding the data. This must be a readable
* Must not be \c NULL if \p ilen is greater than 0. * buffer of length \p ilen Bytes.
* \param ilen The length of the input data. * \param ilen The length of the input data \p input in Bytes.
* \param output The SHA-224 or SHA-256 checksum result. * \param output The SHA-224 or SHA-256 checksum result. This must
* Must not be \c NULL. * be a writable buffer of length \c 32 Bytes.
* \param is224 Determines which function to use: * \param is224 Determines which function to use. This must be
* 0: Use SHA-256, or 1: Use SHA-224. * either \c 0 for SHA-256, or \c 1 for SHA-224.
*/ */
int mbedtls_sha256_ret( const unsigned char *input, int mbedtls_sha256_ret( const unsigned char *input,
size_t ilen, size_t ilen,
@ -264,13 +264,13 @@ int mbedtls_sha256_ret( const unsigned char *input,
* *
* \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0. * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0.
* *
* \param input The buffer holding the data. * \param input The buffer holding the data. This must be a readable
* Must not be \c NULL if \p ilen is greater than 0. * buffer of length \p ilen Bytes.
* \param ilen The length of the input data. * \param ilen The length of the input data \p input in Bytes.
* \param output The SHA-224 or SHA-256 checksum result. * \param output The SHA-224 or SHA-256 checksum result. This must be
* Must not be \c NULL. * a writable buffer of length \c 32 Bytes.
* \param is224 Determines which function to use: * \param is224 Determines which function to use. This must be eithern
* 0: Use SHA-256, or 1: Use SHA-224. * \c 0 for SHA-256, or \c 1 for SHA-224.
*/ */
MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input, MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
size_t ilen, size_t ilen,