1/* BEGIN_HEADER */
2#include "mbedtls/sha1.h"
3#include "mbedtls/sha256.h"
4#include "mbedtls/sha512.h"
5/* END_HEADER */
6
7/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
8void mbedtls_sha1( char *hex_src_string, char *hex_hash_string )
9{
10    unsigned char src_str[10000];
11    unsigned char hash_str[10000];
12    unsigned char output[41];
13    int src_len;
14
15    memset(src_str, 0x00, 10000);
16    memset(hash_str, 0x00, 10000);
17    memset(output, 0x00, 41);
18
19    src_len = unhexify( src_str, hex_src_string );
20
21    mbedtls_sha1( src_str, src_len, output );
22    hexify( hash_str, output, 20 );
23
24    TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
25}
26/* END_CASE */
27
28/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
29void sha224(char *hex_src_string, char *hex_hash_string )
30{
31    unsigned char src_str[10000];
32    unsigned char hash_str[10000];
33    unsigned char output[57];
34    int src_len;
35
36    memset(src_str, 0x00, 10000);
37    memset(hash_str, 0x00, 10000);
38    memset(output, 0x00, 57);
39
40    src_len = unhexify( src_str, hex_src_string );
41
42    mbedtls_sha256( src_str, src_len, output, 1 );
43    hexify( hash_str, output, 28 );
44
45    TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
46}
47/* END_CASE */
48
49/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
50void mbedtls_sha256(char *hex_src_string, char *hex_hash_string )
51{
52    unsigned char src_str[10000];
53    unsigned char hash_str[10000];
54    unsigned char output[65];
55    int src_len;
56
57    memset(src_str, 0x00, 10000);
58    memset(hash_str, 0x00, 10000);
59    memset(output, 0x00, 65);
60
61    src_len = unhexify( src_str, hex_src_string );
62
63    mbedtls_sha256( src_str, src_len, output, 0 );
64    hexify( hash_str, output, 32 );
65
66    TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
67}
68/* END_CASE */
69
70/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
71void sha384(char *hex_src_string, char *hex_hash_string )
72{
73    unsigned char src_str[10000];
74    unsigned char hash_str[10000];
75    unsigned char output[97];
76    int src_len;
77
78    memset(src_str, 0x00, 10000);
79    memset(hash_str, 0x00, 10000);
80    memset(output, 0x00, 97);
81
82    src_len = unhexify( src_str, hex_src_string );
83
84    mbedtls_sha512( src_str, src_len, output, 1 );
85    hexify( hash_str, output, 48 );
86
87    TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
88}
89/* END_CASE */
90
91/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
92void mbedtls_sha512(char *hex_src_string, char *hex_hash_string )
93{
94    unsigned char src_str[10000];
95    unsigned char hash_str[10000];
96    unsigned char output[129];
97    int src_len;
98
99    memset(src_str, 0x00, 10000);
100    memset(hash_str, 0x00, 10000);
101    memset(output, 0x00, 129);
102
103    src_len = unhexify( src_str, hex_src_string );
104
105    mbedtls_sha512( src_str, src_len, output, 0);
106    hexify( hash_str, output, 64 );
107
108    TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
109}
110/* END_CASE */
111
112/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
113void sha1_selftest()
114{
115    TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
116}
117/* END_CASE */
118
119/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
120void sha256_selftest()
121{
122    TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
123}
124/* END_CASE */
125
126/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
127void sha512_selftest()
128{
129    TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
130}
131/* END_CASE */
132