status update, probably last commit
[rofl0r-kripto.git] / test / block / safer.c
blobd090d1dc28b6f544e85fea562eb9deb68d8c32ef
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/safer.h>
18 #include <kripto/block/safer_sk.h>
20 int main(void)
22 kripto_block *s;
23 unsigned int i;
24 uint8_t t[8];
25 const uint8_t k64[8] =
27 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01
29 const uint8_t pt[16] =
31 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34 const uint8_t ct64[8] =
36 0xC8, 0xF2, 0x9C, 0xDD, 0x87, 0x78, 0x3E, 0xD9
38 const uint8_t ct64sk[8] =
40 0x5F, 0xCE, 0x9B, 0xA2, 0x05, 0x84, 0x38, 0xC7
42 const uint8_t ct128sk[8] =
44 0xFF, 0x78, 0x11, 0xE4, 0xB3, 0xA7, 0x2E, 0x71
47 puts("kripto_block_safer");
49 /* 64-bit key */
50 s = kripto_block_create(kripto_block_safer, 0, k64, 8);
51 if(!s) puts("error");
53 kripto_block_encrypt(s, pt, t);
54 for(i = 0; i < 8; i++) if(t[i] != ct64[i])
56 puts("64-bit key encrypt: FAIL");
57 break;
59 if(i == 8) puts("64-bit key encrypt: OK");
61 kripto_block_decrypt(s, ct64, t);
62 for(i = 0; i < 8; i++) if(t[i] != pt[i])
64 puts("64-bit key decrypt: FAIL");
65 break;
67 if(i == 8) puts("64-bit key decrypt: OK");
69 kripto_block_destroy(s);
71 /* SK */
72 puts("\nkripto_block_safer_sk");
74 /* 64-bit key */
75 s = kripto_block_create(kripto_block_safer_sk, 6, pt, 8);
76 if(!s) puts("error");
78 kripto_block_encrypt(s, pt, t);
79 for(i = 0; i < 8; i++) if(t[i] != ct64sk[i])
81 puts("64-bit key encrypt: FAIL");
82 break;
84 if(i == 8) puts("64-bit key encrypt: OK");
86 kripto_block_decrypt(s, ct64sk, t);
87 for(i = 0; i < 8; i++) if(t[i] != pt[i])
89 puts("64-bit key decrypt: FAIL");
90 break;
92 if(i == 8) puts("64-bit key decrypt: OK");
94 /* 128-bit key */
95 s = kripto_block_recreate(s, 0, pt, 16);
96 if(!s) puts("error");
98 kripto_block_encrypt(s, pt, t);
99 for(i = 0; i < 8; i++) if(t[i] != ct128sk[i])
101 puts("128-bit key encrypt: FAIL");
102 break;
104 if(i == 8) puts("128-bit key encrypt: OK");
106 kripto_block_decrypt(s, ct128sk, t);
107 for(i = 0; i < 8; i++) if(t[i] != pt[i])
109 puts("128-bit key decrypt: FAIL");
110 break;
112 if(i == 8) puts("128-bit key decrypt: OK");
114 kripto_block_destroy(s);
116 return 0;