File: test_suite_shax.function

package info (click to toggle)
edk2 2025.02-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 271,704 kB
  • sloc: ansic: 2,109,987; asm: 263,832; perl: 227,730; python: 149,919; sh: 34,967; cpp: 21,813; makefile: 3,282; xml: 806; pascal: 721; lisp: 35; ruby: 16; sed: 6; tcl: 4
file content (136 lines) | stat: -rw-r--r-- 3,398 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* BEGIN_HEADER */
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include "mbedtls/sha512.h"
/* END_HEADER */

/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
void mbedtls_sha1( data_t * src_str, data_t * hash )
{
    unsigned char output[41];

    memset(output, 0x00, 41);


    TEST_ASSERT( mbedtls_sha1( src_str->x, src_str->len, output ) == 0 );

    TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 20, hash->len ) == 0 );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
void sha256_invalid_param( )
{
    mbedtls_sha256_context ctx;
    unsigned char buf[64] = { 0 };
    size_t const buflen = sizeof( buf );
    int invalid_type = 42;

    TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
                            mbedtls_sha256_starts( &ctx, invalid_type ) );

    TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
                            mbedtls_sha256( buf, buflen,
                                                buf, invalid_type ) );

exit:
    return;
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA224_C */
void sha224( data_t * src_str, data_t * hash )
{
    unsigned char output[57];

    memset(output, 0x00, 57);


    TEST_ASSERT( mbedtls_sha256( src_str->x, src_str->len, output, 1 ) == 0 );

    TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 28, hash->len ) == 0 );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
void mbedtls_sha256( data_t * src_str, data_t * hash )
{
    unsigned char output[65];

    memset(output, 0x00, 65);


    TEST_ASSERT( mbedtls_sha256( src_str->x, src_str->len, output, 0 ) == 0 );

    TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 32, hash->len ) == 0 );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
void sha512_invalid_param( )
{
    mbedtls_sha512_context ctx;
    unsigned char buf[64] = { 0 };
    size_t const buflen = sizeof( buf );
    int invalid_type = 42;

    TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
                            mbedtls_sha512_starts( &ctx, invalid_type ) );

    TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
                            mbedtls_sha512( buf, buflen,
                                                buf, invalid_type ) );

exit:
    return;
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA384_C */
void sha384( data_t * src_str, data_t * hash )
{
    unsigned char output[97];

    memset(output, 0x00, 97);


    TEST_ASSERT( mbedtls_sha512( src_str->x, src_str->len, output, 1 ) == 0 );

    TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 48, hash->len ) == 0 );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
void mbedtls_sha512( data_t * src_str, data_t * hash )
{
    unsigned char output[129];

    memset(output, 0x00, 129);


    TEST_ASSERT( mbedtls_sha512( src_str->x, src_str->len, output, 0 ) == 0 );

    TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 64, hash->len ) == 0 );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
void sha1_selftest(  )
{
    TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
void sha256_selftest(  )
{
    TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
void sha512_selftest(  )
{
    TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
}
/* END_CASE */