status update, probably last commit
[rofl0r-kripto.git] / test / block / serpent.c
blob0bf7085861cf04cb7be87914e867e30b2cda8503
1 /*
2 * Written in 2013 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>
17 #include <kripto/block/serpent.h>
19 int main(void)
21 kripto_block *s;
22 unsigned int i;
23 unsigned int n;
24 uint8_t t[16];
25 const uint8_t k[32] =
27 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
28 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
29 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
30 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
32 const uint8_t pt[16] =
34 0x3D, 0xA4, 0x6F, 0xFA, 0x6F, 0x4D, 0x6F, 0x30,
35 0xCD, 0x25, 0x83, 0x33, 0xE5, 0xA6, 0x13, 0x69
37 const uint8_t ct[32][16] =
40 0xA7, 0x78, 0x81, 0x91, 0x27, 0x7A, 0x2D, 0x88,
41 0xF8, 0xFE, 0xC2, 0x59, 0x09, 0x2F, 0x22, 0x1F
44 0x0A, 0x8E, 0xBC, 0xE3, 0x3F, 0x21, 0x24, 0xA6,
45 0x03, 0x08, 0xD2, 0x18, 0xDD, 0x96, 0x53, 0x85
48 0xDB, 0x36, 0xF4, 0x69, 0x01, 0xF4, 0x51, 0x0D,
49 0xFD, 0x19, 0x57, 0x18, 0xC0, 0x39, 0xDA, 0x00
52 0x1E, 0x8D, 0x65, 0xFF, 0xEA, 0xF8, 0xD8, 0xBD,
53 0x21, 0x57, 0x04, 0x93, 0xEE, 0xDE, 0x43, 0x81
56 0x26, 0x33, 0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 0x98, 0xBC, 0x88, 0x5F,
101 0x17, 0x30, 0x71, 0x26, 0x80, 0xCB, 0x65, 0x6E
104 0x18, 0x8C, 0x33, 0x77, 0xF0, 0xDF, 0xE7, 0x72,
105 0x64, 0xD2, 0x59, 0xAB, 0x2F, 0x39, 0x5F, 0x83
108 0x4C, 0xE5, 0xE8, 0x62, 0xEA, 0x11, 0x0E, 0xFC,
109 0xE7, 0x99, 0x9C, 0xB7, 0xC1, 0x7F, 0xBA, 0xBD
112 0x87, 0x6E, 0x6F, 0x5A, 0x5B, 0x04, 0x88, 0xD3,
113 0x82, 0xFC, 0x46, 0xC9, 0x44, 0x17, 0x5B, 0x01
116 0x76, 0x3B, 0xEF, 0xC2, 0x76, 0x3A, 0x0B, 0x5D,
117 0x35, 0x2E, 0x78, 0x13, 0x1B, 0x0B, 0x0C, 0x79
120 0x7E, 0x9C, 0x03, 0xBC, 0x06, 0x17, 0x54, 0x60,
121 0xC9, 0x08, 0x3A, 0xA0, 0xF1, 0x38, 0x56, 0x64
124 0xFE, 0x23, 0xDD, 0x99, 0x9E, 0x2C, 0xE3, 0x6F,
125 0x80, 0x76, 0x5A, 0xCF, 0x53, 0xB0, 0xC0, 0x72
128 0xD7, 0x88, 0xBD, 0x9A, 0xE0, 0xF0, 0xDE, 0x92,
129 0xF6, 0x51, 0xBE, 0xA9, 0x01, 0x22, 0x49, 0x82
132 0xC4, 0x92, 0x02, 0x3C, 0xD1, 0x3B, 0xE2, 0xBD,
133 0x9B, 0xA7, 0x46, 0xEE, 0xF2, 0xC3, 0xD4, 0x32
136 0x6A, 0x84, 0x33, 0xFC, 0x41, 0x04, 0x3E, 0x75,
137 0xE5, 0xE2, 0x66, 0x1C, 0x7B, 0x25, 0x9C, 0x78
140 0x18, 0x16, 0xDE, 0x9D, 0xEC, 0x2D, 0xCC, 0xF1,
141 0x69, 0xF0, 0x07, 0x6D, 0x01, 0xE6, 0xDD, 0x2A
144 0x1E, 0x8A, 0x37, 0xCB, 0x39, 0x8E, 0x30, 0xBB,
145 0x4B, 0x10, 0x62, 0x55, 0x64, 0x73, 0xC1, 0x79
148 0x70, 0xB5, 0x7A, 0x36, 0xA2, 0x9E, 0x43, 0x7F,
149 0xF8, 0x7A, 0x09, 0xAC, 0x1B, 0xF9, 0x82, 0xE9
152 0x59, 0xB3, 0xA4, 0xFA, 0x9C, 0x91, 0xA9, 0xCA,
153 0xC2, 0xB0, 0x8F, 0xF5, 0x97, 0x98, 0xBC, 0x3D
156 0x3A, 0xBA, 0x14, 0x9F, 0x3F, 0x8B, 0xF7, 0xF8,
157 0x79, 0x0C, 0xD8, 0xF5, 0x36, 0x52, 0x55, 0x1A
160 0xF3, 0x8A, 0xE9, 0x5B, 0xD9, 0x41, 0xE1, 0x01,
161 0x1C, 0x89, 0x16, 0xF5, 0x51, 0xC2, 0xE3, 0x62
164 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
165 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
169 puts("kripto_block_serpent");
171 for(n = 1; n <= 32; n++)
173 s = kripto_block_create(kripto_block_serpent, 0, k, n);
174 if(!s) puts("error");
176 kripto_block_encrypt(s, pt, t);
177 for(i = 0; i < 16; i++) if(t[i] != ct[n - 1][i])
179 printf("%u-bit key encrypt: FAIL\n", n * 8);
180 break;
182 if(i == 16) printf("%u-bit key encrypt: OK\n", n * 8);
184 kripto_block_decrypt(s, ct[n - 1], t);
185 for(i = 0; i < 16; i++) if(t[i] != pt[i])
187 printf("%u-bit key decrypt: FAIL\n", n * 8);
188 break;
190 if(i == 16) printf("%u-bit key decrypt: OK\n", n * 8);
192 kripto_block_destroy(s);
195 return 0;