Add int return values to SHA-256 function calls
The following function calls are being deprecated to introduce int
return values.
* mbedtls_sha256()
* mbedtls_sha256_starts()
* mbedtls_sha256_update()
* mbedtls_sha256_finish()
* mbedtls_sha256_process()
The return codes can be used to return error values. This is important
when using hardware accelerators.
diff --git a/include/mbedtls/sha256.h b/include/mbedtls/sha256.h
index f8041ad..3667e8c 100644
--- a/include/mbedtls/sha256.h
+++ b/include/mbedtls/sha256.h
@@ -32,6 +32,11 @@
#include <stddef.h>
#include <stdint.h>
+#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
+ !defined(inline) && !defined(__cplusplus)
+#define inline __inline
+#endif
+
#if !defined(MBEDTLS_SHA256_ALT)
// Regular implementation
//
@@ -80,8 +85,10 @@
*
* \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224
+ *
+ * \return 0 if successful
*/
-void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
+int mbedtls_sha256_starts_ext( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@@ -89,20 +96,105 @@
* \param ctx SHA-256 context
* \param input buffer holding the data
* \param ilen length of the input data
+ *
+ * \return 0 if successful
*/
-void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
- size_t ilen );
+int mbedtls_sha256_update_ext( mbedtls_sha256_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
/**
* \brief SHA-256 final digest
*
* \param ctx SHA-256 context
* \param output SHA-224/256 checksum result
+ *
+ * \return 0 if successful
*/
-void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
+int mbedtls_sha256_finish_ext( mbedtls_sha256_context *ctx,
+ unsigned char output[32] );
-/* Internal use */
-void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );
+/**
+ * \brief SHA-256 process data block (internal use only)
+ *
+ * \param ctx SHA-256 context
+ * \param data buffer holding one block of data
+ *
+ * \return 0 if successful
+ */
+int mbedtls_sha256_process_ext( 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 SHA-256 context setup
+ *
+ * \deprecated Superseded by mbedtls_sha256_starts_ext() in 2.5.0
+ *
+ * \param ctx context to be initialized
+ * \param is224 0 = use SHA256, 1 = use SHA224
+ */
+MBEDTLS_DEPRECATED static inline void mbedtls_sha256_starts(
+ mbedtls_sha256_context *ctx,
+ int is224 )
+{
+ mbedtls_sha256_starts_ext( ctx, is224 );
+}
+
+/**
+ * \brief SHA-256 process buffer
+ *
+ * \deprecated Superseded by mbedtls_sha256_update_ext() in 2.5.0
+ *
+ * \param ctx SHA-256 context
+ * \param input buffer holding the data
+ * \param ilen 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_ext( ctx, input, ilen );
+}
+
+/**
+ * \brief SHA-256 final digest
+ *
+ * \deprecated Superseded by mbedtls_sha256_finish_ext() in 2.5.0
+ *
+ * \param ctx SHA-256 context
+ * \param output SHA-224/256 checksum result
+ */
+MBEDTLS_DEPRECATED static inline void mbedtls_sha256_finish(
+ mbedtls_sha256_context *ctx,
+ unsigned char output[32] )
+{
+ mbedtls_sha256_finish_ext( ctx, output );
+}
+
+/**
+ * \brief SHA-256 process data block (internal use only)
+ *
+ * \deprecated Superseded by mbedtls_sha256_process_ext() in 2.5.0
+ *
+ * \param ctx SHA-256 context
+ * \param data buffer holding one block of data
+ */
+MBEDTLS_DEPRECATED static inline void mbedtls_sha256_process(
+ mbedtls_sha256_context *ctx,
+ const unsigned char data[64] )
+{
+ mbedtls_sha256_process_ext( ctx, data );
+}
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
#ifdef __cplusplus
}
@@ -123,9 +215,41 @@
* \param ilen length of the input data
* \param output SHA-224/256 checksum result
* \param is224 0 = use SHA256, 1 = use SHA224
+ *
+ * \return 0 if successful
*/
-void mbedtls_sha256( const unsigned char *input, size_t ilen,
- unsigned char output[32], int is224 );
+int mbedtls_sha256_ext( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[32],
+ int is224 );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief Output = SHA-256( input buffer )
+ *
+ * \deprecated Superseded by mbedtls_sha256_ext() in 2.5.0
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output SHA-224/256 checksum result
+ * \param is224 0 = use SHA256, 1 = use SHA224
+ */
+MBEDTLS_DEPRECATED static inline void mbedtls_sha256(
+ const unsigned char *input,
+ size_t ilen,
+ unsigned char output[32],
+ int is224 )
+{
+ mbedtls_sha256_ext( input, ilen, output, is224 );
+}
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
/**
* \brief Checkup routine