status update, probably last commit
[rofl0r-kripto.git] / test / block / gost.c
blob8e40e8956995f7bf70ee42e5f196528f97934e4c
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/gost.h>
19 int main(void)
21 kripto_block *s;
22 unsigned int i;
23 unsigned int n;
24 uint8_t t[8];
25 const uint8_t k[32] =
27 0xBE, 0x5E, 0xC2, 0x00, 0x6C, 0xFF, 0x9D, 0xCF,
28 0x52, 0x35, 0x49, 0x59, 0xF1, 0xFF, 0x0C, 0xBF,
29 0xE9, 0x50, 0x61, 0xB5, 0xA6, 0x48, 0xC1, 0x03,
30 0x87, 0x06, 0x9C, 0x25, 0x99, 0x7C, 0x06, 0x72
32 const uint8_t pt[8] =
34 0x0D, 0xF8, 0x28, 0x02, 0xB7, 0x41, 0xA2, 0x92
36 const uint8_t ct[32][8] =
38 {0x32, 0x53, 0xF9, 0x3F, 0xF0, 0x93, 0xA0, 0xF9},
39 {0xA7, 0xC0, 0xCD, 0x42, 0x89, 0xE0, 0xEB, 0x60},
40 {0xDC, 0x02, 0xA5, 0x00, 0x4E, 0xA0, 0x23, 0xC1},
41 {0xDC, 0x02, 0xA5, 0x00, 0x4E, 0xA0, 0x23, 0xC1},
42 {0x15, 0xFA, 0xF7, 0x1E, 0xBE, 0xD2, 0x56, 0x55},
43 {0x97, 0x2D, 0xF0, 0xF0, 0x18, 0xD3, 0x3A, 0xDC},
44 {0x0C, 0x3A, 0x26, 0x12, 0x55, 0x4E, 0xC6, 0xF3},
45 {0x31, 0xBF, 0xCA, 0xA8, 0x08, 0x6A, 0x5F, 0xFD},
46 {0x78, 0x5F, 0x62, 0x69, 0xE7, 0x65, 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68 {0x82, 0xAE, 0x01, 0x79, 0x7D, 0x28, 0xDA, 0xD8},
69 {0x07, 0xF9, 0x02, 0x7D, 0xF7, 0xF7, 0xDF, 0x89}
72 puts("kripto_block_gost");
74 for(n = 1; n <= 32; n++)
76 s = kripto_block_create(kripto_block_gost, 0, k, n);
77 if(!s) puts("error");
79 kripto_block_encrypt(s, pt, t);
80 for(i = 0; i < 8; i++) if(t[i] != ct[n - 1][i])
82 printf("%u-bit key encrypt: FAIL\n", n * 8);
83 break;
85 if(i == 8) printf("%u-bit key encrypt: OK\n", n * 8);
87 kripto_block_decrypt(s, ct[n - 1], t);
88 for(i = 0; i < 8; i++) if(t[i] != pt[i])
90 printf("%u-bit key decrypt: FAIL\n", n * 8);
91 break;
93 if(i == 8) printf("%u-bit key decrypt: OK\n", n * 8);
95 kripto_block_destroy(s);
98 return 0;