Add test vectors (from NIST) for SHA-3.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
diff --git a/tests/suites/test_suite_shax.function b/tests/suites/test_suite_shax.function
index 95d45ba..28474b7 100644
--- a/tests/suites/test_suite_shax.function
+++ b/tests/suites/test_suite_shax.function
@@ -2,6 +2,7 @@
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include "mbedtls/sha512.h"
+#include "mbedtls/sha3.h"
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
@@ -136,3 +137,43 @@
TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
}
/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SHA3_C */
+void mbedtls_sha3( int family, data_t *in, data_t *hash )
+{
+ unsigned char *output = NULL;
+
+ ASSERT_ALLOC( output, hash->len );
+
+ TEST_ASSERT( mbedtls_sha3( family, in->x, in->len, output, hash->len ) == 0 );
+
+ ASSERT_COMPARE( output, hash->len, hash->x, hash->len );
+
+exit:
+ mbedtls_free( output );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SHA3_C */
+void mbedtls_sha3_multi( int family, data_t *in, data_t *hash )
+{
+ unsigned char *output = NULL;
+ mbedtls_sha3_context ctx;
+ const unsigned int block_size = 256;
+
+ ASSERT_ALLOC( output, hash->len );
+
+ mbedtls_sha3_init( &ctx );
+ mbedtls_sha3_starts( &ctx, family );
+
+ for( size_t l = 0; l < in->len; l += block_size )
+ TEST_ASSERT( mbedtls_sha3_update( &ctx, in->x + l, MIN( in->len - l, block_size ) ) == 0 );
+
+ TEST_ASSERT( mbedtls_sha3_finish( &ctx, output, hash->len ) == 0 );
+
+ ASSERT_COMPARE( output, hash->len, hash->x, hash->len );
+
+exit:
+ mbedtls_free( output );
+}
+/* END_CASE */