]> git.ozlabs.org Git - ccan/blob - ccan/crypto/xtea/test/run.c
xtea: new module.
[ccan] / ccan / crypto / xtea / test / run.c
1 #include <ccan/crypto/xtea/xtea.h>
2 /* Include the C files directly. */
3 #include <ccan/crypto/xtea/xtea.c>
4 #include <ccan/tap/tap.h>
5 #include <string.h>
6
7 int main(void)
8 {
9         uint64_t v, e;  
10         struct xtea_secret s;
11
12         /* This is how many tests you plan to run */
13         plan_tests(66);
14
15         memset(&s, 1, sizeof(s));
16
17         for (v = 1; v; v <<= 1) {
18                 e = xtea_encipher(&s, v);
19                 ok1(xtea_decipher(&s, e) == v);
20         }
21
22         /* The only 32-iteration from the "test vectors" at
23          * http://www.cix.co.uk/~klockstone/teavect.htm:
24          * in=af20a390547571aa, N=32, k=27f917b1c1da899360e2acaaa6eb923d, out=d26428af0a202283
25          */
26         v = 0xaf20a390547571aaULL;
27         s.u.u32[0] = 0x27f917b1;
28         s.u.u32[1] = 0xc1da8993;
29         s.u.u32[2] = 0x60e2acaa;
30         s.u.u32[3] = 0xa6eb923d;
31         e = xtea_encipher(&s, v);
32         ok1(e == 0xd26428af0a202283ULL);
33         ok1(xtea_decipher(&s, e) == v);
34
35         /* This exits depending on whether all tests passed */
36         return exit_status();
37 }