blob: 02ac47378c2ebc161455a2ffad92011bba2b572a [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include "mbedtls/sha1.h"
3#include "mbedtls/sha256.h"
4#include "mbedtls/sha512.h"
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* END_HEADER */
Paul Bakker367dae42009-06-28 21:50:27 +00006
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02007/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
Azim Khanf1aaec92017-05-30 14:23:15 +01008void mbedtls_sha1( uint8_t * src_str, uint32_t src_len,
9 uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
Paul Bakker367dae42009-06-28 21:50:27 +000010{
Paul Bakker367dae42009-06-28 21:50:27 +000011 unsigned char output[41];
12
Paul Bakker367dae42009-06-28 21:50:27 +000013 memset(output, 0x00, 41);
14
Paul Bakker367dae42009-06-28 21:50:27 +000015
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010016 TEST_ASSERT( mbedtls_sha1_ret( src_str, src_len, output ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000017
Azim Khanf1aaec92017-05-30 14:23:15 +010018 TEST_ASSERT( hexcmp( output, hex_hash_string, 20, hex_hash_string_len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000019}
Paul Bakker33b43f12013-08-20 11:48:36 +020020/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000021
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
Azim Khanf1aaec92017-05-30 14:23:15 +010023void sha224( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string,
24 uint32_t hex_hash_string_len )
Paul Bakker367dae42009-06-28 21:50:27 +000025{
Paul Bakker367dae42009-06-28 21:50:27 +000026 unsigned char output[57];
27
Paul Bakker367dae42009-06-28 21:50:27 +000028 memset(output, 0x00, 57);
29
Paul Bakker367dae42009-06-28 21:50:27 +000030
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010031 TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 1 ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000032
Azim Khanf1aaec92017-05-30 14:23:15 +010033 TEST_ASSERT( hexcmp( output, hex_hash_string, 28, hex_hash_string_len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000034}
Paul Bakker33b43f12013-08-20 11:48:36 +020035/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000036
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
Azim Khanf1aaec92017-05-30 14:23:15 +010038void mbedtls_sha256( uint8_t * src_str, uint32_t src_len,
39 uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
Paul Bakker367dae42009-06-28 21:50:27 +000040{
Paul Bakker367dae42009-06-28 21:50:27 +000041 unsigned char output[65];
42
Paul Bakker367dae42009-06-28 21:50:27 +000043 memset(output, 0x00, 65);
44
Paul Bakker367dae42009-06-28 21:50:27 +000045
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010046 TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 0 ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000047
Azim Khanf1aaec92017-05-30 14:23:15 +010048 TEST_ASSERT( hexcmp( output, hex_hash_string, 32, hex_hash_string_len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000049}
Paul Bakker33b43f12013-08-20 11:48:36 +020050/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
Azim Khanf1aaec92017-05-30 14:23:15 +010053void sha384( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string,
54 uint32_t hex_hash_string_len )
Paul Bakker367dae42009-06-28 21:50:27 +000055{
Paul Bakker367dae42009-06-28 21:50:27 +000056 unsigned char output[97];
57
Paul Bakker367dae42009-06-28 21:50:27 +000058 memset(output, 0x00, 97);
59
Paul Bakker367dae42009-06-28 21:50:27 +000060
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010061 TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 1 ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000062
Azim Khanf1aaec92017-05-30 14:23:15 +010063 TEST_ASSERT( hexcmp( output, hex_hash_string, 48, hex_hash_string_len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000064}
Paul Bakker33b43f12013-08-20 11:48:36 +020065/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000066
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
Azim Khanf1aaec92017-05-30 14:23:15 +010068void mbedtls_sha512( uint8_t * src_str, uint32_t src_len,
69 uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
Paul Bakker367dae42009-06-28 21:50:27 +000070{
Paul Bakker367dae42009-06-28 21:50:27 +000071 unsigned char output[129];
72
Paul Bakker367dae42009-06-28 21:50:27 +000073 memset(output, 0x00, 129);
74
Paul Bakker367dae42009-06-28 21:50:27 +000075
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010076 TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 0 ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000077
Azim Khanf1aaec92017-05-30 14:23:15 +010078 TEST_ASSERT( hexcmp( output, hex_hash_string, 64, hex_hash_string_len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000079}
Paul Bakker33b43f12013-08-20 11:48:36 +020080/* END_CASE */
Paul Bakkerf3eedce2009-07-05 11:30:16 +000081
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010083void sha1_selftest( )
Paul Bakkerf3eedce2009-07-05 11:30:16 +000084{
Andres AG93012e82016-09-09 09:10:28 +010085 TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
Paul Bakkerf3eedce2009-07-05 11:30:16 +000086}
Paul Bakker33b43f12013-08-20 11:48:36 +020087/* END_CASE */
Paul Bakkerf3eedce2009-07-05 11:30:16 +000088
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010090void sha256_selftest( )
Paul Bakkerf3eedce2009-07-05 11:30:16 +000091{
Andres AG93012e82016-09-09 09:10:28 +010092 TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
Paul Bakkerf3eedce2009-07-05 11:30:16 +000093}
Paul Bakker33b43f12013-08-20 11:48:36 +020094/* END_CASE */
Paul Bakkerf3eedce2009-07-05 11:30:16 +000095
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010097void sha512_selftest( )
Paul Bakkerf3eedce2009-07-05 11:30:16 +000098{
Andres AG93012e82016-09-09 09:10:28 +010099 TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000100}
Paul Bakker33b43f12013-08-20 11:48:36 +0200101/* END_CASE */