File: test_suite_camellia.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 (195 lines) | stat: -rw-r--r-- 5,978 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* BEGIN_HEADER */
#include "mbedtls/camellia.h"
/* END_HEADER */

/* BEGIN_DEPENDENCIES
 * depends_on:MBEDTLS_CAMELLIA_C
 * END_DEPENDENCIES
 */

/* BEGIN_CASE */
void camellia_invalid_param( )
{
    mbedtls_camellia_context ctx;
    unsigned char buf[16] = { 0 };
    const int invalid_mode = 42;
    size_t off;
    ((void) off);

    TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
                            mbedtls_camellia_crypt_ecb( &ctx,
                                                        invalid_mode,
                                                        buf, buf ) );

#if defined(MBEDTLS_CIPHER_MODE_CBC)
    TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
                            mbedtls_camellia_crypt_cbc( &ctx,
                                                        invalid_mode,
                                                        sizeof( buf ),
                                                        buf, buf, buf ) );
#endif /* MBEDTLS_CIPHER_MODE_CBC */

#if defined(MBEDTLS_CIPHER_MODE_CFB)
    TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
                            mbedtls_camellia_crypt_cfb128( &ctx,
                                                           invalid_mode,
                                                           sizeof( buf ),
                                                           &off, buf,
                                                           buf, buf ) );
#endif /* MBEDTLS_CIPHER_MODE_CFB */

exit:
    return;
}
/* END_CASE */

/* BEGIN_CASE */
void camellia_encrypt_ecb( data_t * key_str, data_t * src_str,
                           data_t * dst, int setkey_result )
{
    unsigned char output[100];
    mbedtls_camellia_context ctx;

    memset(output, 0x00, 100);
    mbedtls_camellia_init( &ctx );


    TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
    if( setkey_result == 0 )
    {
        TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 );

        TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
    }

exit:
    mbedtls_camellia_free( &ctx );
}
/* END_CASE */

/* BEGIN_CASE */
void camellia_decrypt_ecb( data_t * key_str, data_t * src_str,
                           data_t * dst, int setkey_result )
{
    unsigned char output[100];
    mbedtls_camellia_context ctx;

    memset(output, 0x00, 100);
    mbedtls_camellia_init( &ctx );


    TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
    if( setkey_result == 0 )
    {
        TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 );

        TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
    }

exit:
    mbedtls_camellia_free( &ctx );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
void camellia_encrypt_cbc( data_t * key_str, data_t * iv_str,
                           data_t * src_str, data_t * dst, int cbc_result )
{
    unsigned char output[100];
    mbedtls_camellia_context ctx;

    memset(output, 0x00, 100);
    mbedtls_camellia_init( &ctx );


    mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
    TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->len, iv_str->x, src_str->x, output) == cbc_result );
    if( cbc_result == 0 )
    {

        TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
                                          dst->len ) == 0 );
    }

exit:
    mbedtls_camellia_free( &ctx );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
void camellia_decrypt_cbc( data_t * key_str, data_t * iv_str,
                           data_t * src_str, data_t * dst,
                           int cbc_result )
{
    unsigned char output[100];
    mbedtls_camellia_context ctx;

    memset(output, 0x00, 100);
    mbedtls_camellia_init( &ctx );


    mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
    TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
    if( cbc_result == 0 )
    {

        TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
                                          dst->len ) == 0 );
    }

exit:
    mbedtls_camellia_free( &ctx );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
void camellia_encrypt_cfb128( data_t * key_str, data_t * iv_str,
                              data_t * src_str, data_t * dst )
{
    unsigned char output[100];
    mbedtls_camellia_context ctx;
    size_t iv_offset = 0;

    memset(output, 0x00, 100);
    mbedtls_camellia_init( &ctx );


    mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
    TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );

    TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );

exit:
    mbedtls_camellia_free( &ctx );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
void camellia_decrypt_cfb128( data_t * key_str, data_t * iv_str,
                              data_t * src_str,
                              data_t * dst )
{
    unsigned char output[100];
    mbedtls_camellia_context ctx;
    size_t iv_offset = 0;

    memset(output, 0x00, 100);
    mbedtls_camellia_init( &ctx );


    mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
    TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );

    TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );

exit:
    mbedtls_camellia_free( &ctx );
}
/* END_CASE */

/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void camellia_selftest(  )
{
    TEST_ASSERT( mbedtls_camellia_self_test( 1 ) == 0 );
}
/* END_CASE */