status update, probably last commit
[rofl0r-kripto.git] / test / block / mars.c
blob6e865ff254d763ccf046d5334f34d1dafaa5c3c3
1 /*
2 * Written in 2014 by Gregor Pintar <grpintar@gmail.com>
4 * To the extent possible under law, the author(s) have dedicated
5 * all copyright and related and neighboring rights to this software
6 * to the public domain worldwide.
7 *
8 * This software is distributed without any warranty.
10 * You should have received a copy of the CC0 Public Domain Dedication.
11 * If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
14 #include <stdint.h>
15 #include <stdio.h>
16 #include <string.h>
18 #include <kripto/block.h>
19 #include <kripto/block/mars.h>
21 int main(void)
23 kripto_block *s;
24 uint8_t t[16];
25 const uint8_t k128[16] =
27 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
30 const uint8_t pt128[16] =
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
35 const uint8_t ct128[16] =
37 0x4B, 0xBB, 0x91, 0x9E, 0x52, 0xC2, 0x58, 0x96,
38 0x05, 0x49, 0xFA, 0xE9, 0xDD, 0x5F, 0xF5, 0x24
40 const uint8_t k192[24] =
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
46 const uint8_t pt192[16] =
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
51 const uint8_t ct192[16] =
53 0x1A, 0x4D, 0x5C, 0x52, 0xFD, 0xDE, 0xE8, 0x13,
54 0x74, 0x29, 0x53, 0x41, 0xF9, 0x50, 0x05, 0x5D
56 const uint8_t k256[32] =
58 0xFB, 0xA1, 0x67, 0x98, 0x3E, 0x7A, 0xEF, 0x22,
59 0x31, 0x7C, 0xE2, 0x8C, 0x02, 0xAA, 0xE1, 0xA3,
60 0xE8, 0xE5, 0xCC, 0x3C, 0xED, 0xBE, 0xA8, 0x2A,
61 0x99, 0xDB, 0xC3, 0x9A, 0xD6, 0x5E, 0x72, 0x27
63 const uint8_t pt256[16] =
65 0x13, 0x44, 0xAB, 0xA4, 0xD3, 0xC4, 0x47, 0x08,
66 0xA8, 0xA7, 0x21, 0x16, 0xD4, 0xF4, 0x93, 0x84
68 const uint8_t ct256[16] =
70 0x45, 0x83, 0x35, 0xD9, 0x5E, 0xA4, 0x2A, 0x9F,
71 0x4D, 0xCC, 0xD4, 0x1A, 0xEC, 0xC2, 0x39, 0x0D
74 puts("kripto_block_mars");
76 /* 128-bit key */
77 s = kripto_block_create(kripto_block_mars, 0, k128, 16);
78 if(!s) puts("error");
80 kripto_block_encrypt(s, pt128, t);
81 if(memcmp(t, ct128, 16)) puts("128-bit key encrypt: FAIL");
82 else puts("128-bit key encrypt: OK");
84 kripto_block_decrypt(s, ct128, t);
85 if(memcmp(t, pt128, 16)) puts("128-bit key decrypt: FAIL");
86 else puts("128-bit key decrypt: OK");
88 /* 192-bit key */
89 s = kripto_block_recreate(s, 0, k192, 24);
90 if(!s) puts("error");
92 kripto_block_encrypt(s, pt192, t);
93 if(memcmp(t, ct192, 16)) puts("192-bit key encrypt: FAIL");
94 else puts("192-bit key encrypt: OK");
96 kripto_block_decrypt(s, ct192, t);
97 if(memcmp(t, pt192, 16)) puts("192-bit key decrypt: FAIL");
98 else puts("192-bit key decrypt: OK");
100 /* 256-bit key */
101 s = kripto_block_recreate(s, 0, k256, 32);
102 if(!s) puts("error");
104 kripto_block_encrypt(s, pt256, t);
105 if(memcmp(t, ct256, 16)) puts("256-bit key encrypt: FAIL");
106 else puts("256-bit key encrypt: OK");
108 kripto_block_decrypt(s, ct256, t);
109 if(memcmp(t, pt256, 16)) puts("256-bit key decrypt: FAIL");
110 else puts("256-bit key decrypt: OK");
112 kripto_block_destroy(s);
114 return 0;