summaryrefslogtreecommitdiff
path: root/crypto_aead/lilliputaei128v1/ref/test/test-tbc-decrypt.c
blob: a5bb1e57e857fe8bde88a6ed238519b64fc05054 (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
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
#include <inttypes.h>
#include <stdio.h>
#include <string.h>

#include "cipher.h"

#include "helpers.h"


struct vector
{
    char *name;
    uint8_t key[KEY_BYTES];
    uint8_t tweak[TWEAK_BYTES];
    uint8_t ciphertext[BLOCK_BYTES];
    uint8_t message[BLOCK_BYTES];
};

typedef struct vector vector;


/* [0]: LSB */
const vector VECTORS[] = {
    {
        .name = "order",
        .tweak = {
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
            0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
        },
        .key = {
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
        },
        .ciphertext = {
            0xe2, 0xad, 0x84, 0xca, 0x96, 0xdc, 0x76, 0x34,
            0xcb, 0x8e, 0xd6, 0x90, 0x63, 0xfc, 0x29, 0xa6,
        },
        .message = {
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
        }
    },
    {
        .name = "random",
        .tweak = {
            0xa8, 0x43, 0xf3, 0x10, 0x81, 0x11, 0x1c, 0x84,
            0xdf, 0xf8, 0x2e, 0xfa, 0x90, 0x90, 0x26, 0x21,
            0x7d, 0x8d, 0x43, 0x12, 0x2a, 0xb3, 0xd2, 0x4d
        },
        .key = {
            0xc1, 0x96, 0xc6, 0x0a, 0x02, 0x73, 0x91, 0x68,
            0x7f, 0xf4, 0x23, 0x4d, 0x3d, 0xd5, 0xf9, 0x9b
        },
        .ciphertext = {
            0x00, 0x7a, 0xdd, 0x4c, 0x96, 0x81, 0x96, 0x87,
            0xd3, 0xb2, 0x76, 0xe1, 0xbf, 0x8a, 0x12, 0x6a,
        },
        .message = {
            0xbc, 0xd7, 0xf0, 0x29, 0x84, 0xb6, 0xc8, 0xf9,
            0x9c, 0x9d, 0x1d, 0xbd, 0x0d, 0x30, 0x94, 0x0b
        }
    }
};


int main(int argc, char const * const *argv)
{
    if (argc < 2)
    {
        fprintf(stderr, "usage: %s OUTPUT-FOLDER\n", argv[0]);
        return 1;
    }

    int diff = 0;

    for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++)
    {
        FILE *dump = open_dump_file(argv[1], "tbc-decrypt", v->name);

        uint8_t message[BLOCK_BYTES];
        lilliput_tbc_decrypt(v->key, v->tweak, v->ciphertext, message, dump);

        if (memcmp(message, v->message, sizeof(message)) != 0)
        {
            REPORT_DIFFERENCE(v->name, "decrypted message");
            diff++;
        }

        fclose(dump);
    }

    return diff;
}