• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* BEGIN_HEADER */
2#include "mbedtls/xtea.h"
3/* END_HEADER */
4
5/* BEGIN_DEPENDENCIES
6 * depends_on:MBEDTLS_XTEA_C
7 * END_DEPENDENCIES
8 */
9
10/* BEGIN_CASE */
11void xtea_encrypt_ecb(data_t *key_str, data_t *src_str,
12                      data_t *dst)
13{
14    unsigned char output[100];
15    mbedtls_xtea_context ctx;
16
17    memset(output, 0x00, 100);
18
19
20    mbedtls_xtea_setup(&ctx, key_str->x);
21    TEST_ASSERT(mbedtls_xtea_crypt_ecb(&ctx, MBEDTLS_XTEA_ENCRYPT, src_str->x, output) == 0);
22
23    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 8, dst->len) == 0);
24}
25/* END_CASE */
26
27/* BEGIN_CASE */
28void xtea_decrypt_ecb(data_t *key_str, data_t *src_str, data_t *dst)
29{
30    unsigned char output[100];
31    mbedtls_xtea_context ctx;
32
33    memset(output, 0x00, 100);
34
35
36    mbedtls_xtea_setup(&ctx, key_str->x);
37    TEST_ASSERT(mbedtls_xtea_crypt_ecb(&ctx, MBEDTLS_XTEA_DECRYPT, src_str->x, output) == 0);
38
39    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 8, dst->len) == 0);
40}
41/* END_CASE */
42
43/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
44void xtea_encrypt_cbc(data_t *key_str, data_t *iv_str,
45                      data_t *src_str, data_t *dst)
46{
47    unsigned char output[100];
48    mbedtls_xtea_context ctx;
49
50    memset(output, 0x00, 100);
51
52
53    mbedtls_xtea_setup(&ctx, key_str->x);
54    TEST_ASSERT(mbedtls_xtea_crypt_cbc(&ctx, MBEDTLS_XTEA_ENCRYPT, src_str->len, iv_str->x,
55                                       src_str->x, output) == 0);
56
57    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
58                                    src_str->len, dst->len) == 0);
59}
60/* END_CASE */
61
62/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
63void xtea_decrypt_cbc(data_t *key_str, data_t *iv_str,
64                      data_t *src_str, data_t *dst)
65{
66    unsigned char output[100];
67    mbedtls_xtea_context ctx;
68
69    memset(output, 0x00, 100);
70
71
72    mbedtls_xtea_setup(&ctx, key_str->x);
73    TEST_ASSERT(mbedtls_xtea_crypt_cbc(&ctx, MBEDTLS_XTEA_DECRYPT, src_str->len, iv_str->x,
74                                       src_str->x, output) == 0);
75
76    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
77                                    src_str->len, dst->len) == 0);
78}
79/* END_CASE */
80
81/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
82void xtea_selftest()
83{
84    TEST_ASSERT(mbedtls_xtea_self_test(1) == 0);
85}
86/* END_CASE */
87