Implement MBEDTLS_SHA256_NO_SHA224
diff --git a/include/mbedtls/sha256.h b/include/mbedtls/sha256.h
index d647398..2b98bee 100644
--- a/include/mbedtls/sha256.h
+++ b/include/mbedtls/sha256.h
@@ -60,8 +60,10 @@
uint32_t total[2]; /*!< The number of Bytes processed. */
uint32_t state[8]; /*!< The intermediate digest state. */
unsigned char buffer[64]; /*!< The data block being processed. */
+#if !defined(MBEDTLS_SHA256_NO_SHA224)
int is224; /*!< Determines which function to use:
0: Use SHA-256, or 1: Use SHA-224. */
+#endif
}
mbedtls_sha256_context;
diff --git a/library/sha256.c b/library/sha256.c
index 91d461c..0873023 100644
--- a/library/sha256.c
+++ b/library/sha256.c
@@ -132,6 +132,9 @@
}
else
{
+#if defined(MBEDTLS_SHA256_NO_SHA224)
+ return( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA );
+#else
/* SHA-224 */
ctx->state[0] = 0xC1059ED8;
ctx->state[1] = 0x367CD507;
@@ -141,9 +144,12 @@
ctx->state[5] = 0x68581511;
ctx->state[6] = 0x64F98FA7;
ctx->state[7] = 0xBEFA4FA4;
+#endif
}
+#if !defined(MBEDTLS_SHA256_NO_SHA224)
ctx->is224 = is224;
+#endif
return( 0 );
}
@@ -395,7 +401,9 @@
sha256_put_uint32_be( ctx->state[5], output, 20 );
sha256_put_uint32_be( ctx->state[6], output, 24 );
+#if !defined(MBEDTLS_SHA256_NO_SHA224)
if( ctx->is224 == 0 )
+#endif
sha256_put_uint32_be( ctx->state[7], output, 28 );
return( 0 );