summaryrefslogtreecommitdiff
path: root/cesar/cp2/secu/test/src/test-aes.c
blob: ad84bb4bcd62c57d0f67367eaab97dbbfc7559e0 (plain)
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
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/test-aes.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include "common/std.h"
#include "lib/test.h"
#include "lib/bitstream.h"
#include "string.h"

#include "cp2/secu/aes.h"

void
test_case_aes (test_t test)
{
    aes_context aes;

    u8 key[16] = {0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08, 0x0A,
        0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x12};

    u8 input [16] = {0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89, 0xB9,
        0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59};

    u8 result [16] = {0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D, 0x06,
        0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9};

    u8 output [16];

    aes_set_key (&aes, key);
    aes_encrypt (&aes, input, output);

    test_case_begin (test, "AES");

    test_begin (test, "Verify")
    {
        test_fail_if (bitstream_memcmp(output, result, 16) != true,
                      "Wrong encryption");

        aes_decrypt (&aes, output, output);
        test_fail_if (bitstream_memcmp(output, input, 16) != true,
                      "Wrong encryption");
    }
    test_end;
}

int
main (void)
{
    test_t test;

    test_init (test, 0, NULL);

    test_case_aes (test);

    test_result (test);
    return test_nb_failed (test) == 0 ? 0 : 1;
}