Add test vectors (from NIST) for SHA-3.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-05-09 01:04:34 +02:00
parent 0cd1f1c77f
commit f645705976
No known key found for this signature in database
GPG Key ID: C0095B7870A4CCD3
2 changed files with 2205 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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 @@ void sha512_selftest( )
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 */