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.
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/>.
17 #include <kripto/block/safer.h>
18 #include <kripto/block/safer_sk.h>
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");
50 s
= kripto_block_create(kripto_block_safer
, 0, k64
, 8);
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");
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");
67 if(i
== 8) puts("64-bit key decrypt: OK");
69 kripto_block_destroy(s
);
72 puts("\nkripto_block_safer_sk");
75 s
= kripto_block_create(kripto_block_safer_sk
, 6, pt
, 8);
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");
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");
92 if(i
== 8) puts("64-bit key decrypt: OK");
95 s
= kripto_block_recreate(s
, 0, pt
, 16);
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");
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");
112 if(i
== 8) puts("128-bit key decrypt: OK");
114 kripto_block_destroy(s
);