blob: 6b3ee9c54c5d4a76a8fb99f9516bf1e54a5038b5 [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 */
8void mbedtls_sha1( char *hex_src_string, char *hex_hash_string )
Paul Bakker367dae42009-06-28 21:50:27 +00009{
10 unsigned char src_str[10000];
11 unsigned char hash_str[10000];
12 unsigned char output[41];
Paul Bakker69998dd2009-07-11 19:15:20 +000013 int src_len;
Paul Bakker367dae42009-06-28 21:50:27 +000014
15 memset(src_str, 0x00, 10000);
16 memset(hash_str, 0x00, 10000);
17 memset(output, 0x00, 41);
18
Paul Bakker33b43f12013-08-20 11:48:36 +020019 src_len = unhexify( src_str, hex_src_string );
Paul Bakker367dae42009-06-28 21:50:27 +000020
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020021 mbedtls_sha1( src_str, src_len, output );
Paul Bakker367dae42009-06-28 21:50:27 +000022 hexify( hash_str, output, 20 );
23
Paul Bakker33b43f12013-08-20 11:48:36 +020024 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000025}
Paul Bakker33b43f12013-08-20 11:48:36 +020026/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
Paul Bakker33b43f12013-08-20 11:48:36 +020029void sha224(char *hex_src_string, char *hex_hash_string )
Paul Bakker367dae42009-06-28 21:50:27 +000030{
31 unsigned char src_str[10000];
32 unsigned char hash_str[10000];
33 unsigned char output[57];
Paul Bakker69998dd2009-07-11 19:15:20 +000034 int src_len;
Paul Bakker367dae42009-06-28 21:50:27 +000035
36 memset(src_str, 0x00, 10000);
37 memset(hash_str, 0x00, 10000);
38 memset(output, 0x00, 57);
39
Paul Bakker33b43f12013-08-20 11:48:36 +020040 src_len = unhexify( src_str, hex_src_string );
Paul Bakker367dae42009-06-28 21:50:27 +000041
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042 mbedtls_sha256( src_str, src_len, output, 1 );
Paul Bakker367dae42009-06-28 21:50:27 +000043 hexify( hash_str, output, 28 );
44
Paul Bakker33b43f12013-08-20 11:48:36 +020045 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000046}
Paul Bakker33b43f12013-08-20 11:48:36 +020047/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000048
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
50void mbedtls_sha256(char *hex_src_string, char *hex_hash_string )
Paul Bakker367dae42009-06-28 21:50:27 +000051{
52 unsigned char src_str[10000];
53 unsigned char hash_str[10000];
54 unsigned char output[65];
Paul Bakker69998dd2009-07-11 19:15:20 +000055 int src_len;
Paul Bakker367dae42009-06-28 21:50:27 +000056
57 memset(src_str, 0x00, 10000);
58 memset(hash_str, 0x00, 10000);
59 memset(output, 0x00, 65);
60
Paul Bakker33b43f12013-08-20 11:48:36 +020061 src_len = unhexify( src_str, hex_src_string );
Paul Bakker367dae42009-06-28 21:50:27 +000062
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063 mbedtls_sha256( src_str, src_len, output, 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000064 hexify( hash_str, output, 32 );
65
Paul Bakker33b43f12013-08-20 11:48:36 +020066 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000067}
Paul Bakker33b43f12013-08-20 11:48:36 +020068/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000069
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
Paul Bakker33b43f12013-08-20 11:48:36 +020071void sha384(char *hex_src_string, char *hex_hash_string )
Paul Bakker367dae42009-06-28 21:50:27 +000072{
73 unsigned char src_str[10000];
74 unsigned char hash_str[10000];
75 unsigned char output[97];
Paul Bakker69998dd2009-07-11 19:15:20 +000076 int src_len;
Paul Bakker367dae42009-06-28 21:50:27 +000077
78 memset(src_str, 0x00, 10000);
79 memset(hash_str, 0x00, 10000);
80 memset(output, 0x00, 97);
81
Paul Bakker33b43f12013-08-20 11:48:36 +020082 src_len = unhexify( src_str, hex_src_string );
Paul Bakker367dae42009-06-28 21:50:27 +000083
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084 mbedtls_sha512( src_str, src_len, output, 1 );
Paul Bakker367dae42009-06-28 21:50:27 +000085 hexify( hash_str, output, 48 );
86
Paul Bakker33b43f12013-08-20 11:48:36 +020087 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000088}
Paul Bakker33b43f12013-08-20 11:48:36 +020089/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000090
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
92void mbedtls_sha512(char *hex_src_string, char *hex_hash_string )
Paul Bakker367dae42009-06-28 21:50:27 +000093{
94 unsigned char src_str[10000];
95 unsigned char hash_str[10000];
96 unsigned char output[129];
Paul Bakker69998dd2009-07-11 19:15:20 +000097 int src_len;
Paul Bakker367dae42009-06-28 21:50:27 +000098
99 memset(src_str, 0x00, 10000);
100 memset(hash_str, 0x00, 10000);
101 memset(output, 0x00, 129);
102
Paul Bakker33b43f12013-08-20 11:48:36 +0200103 src_len = unhexify( src_str, hex_src_string );
Paul Bakker367dae42009-06-28 21:50:27 +0000104
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105 mbedtls_sha512( src_str, src_len, output, 0);
Paul Bakker367dae42009-06-28 21:50:27 +0000106 hexify( hash_str, output, 64 );
107
Paul Bakker33b43f12013-08-20 11:48:36 +0200108 TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +0000109}
Paul Bakker33b43f12013-08-20 11:48:36 +0200110/* END_CASE */
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +0200113void sha1_selftest()
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000114{
Andres AG93012e82016-09-09 09:10:28 +0100115 TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000116}
Paul Bakker33b43f12013-08-20 11:48:36 +0200117/* END_CASE */
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000118
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +0200120void sha256_selftest()
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000121{
Andres AG93012e82016-09-09 09:10:28 +0100122 TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000123}
Paul Bakker33b43f12013-08-20 11:48:36 +0200124/* END_CASE */
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +0200127void sha512_selftest()
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000128{
Andres AG93012e82016-09-09 09:10:28 +0100129 TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000130}
Paul Bakker33b43f12013-08-20 11:48:36 +0200131/* END_CASE */