mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-31 10:20:45 +00:00
Add test vectors (from NIST) for SHA-3.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
0cd1f1c77f
commit
f645705976
File diff suppressed because it is too large
Load Diff
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user