status update, probably last commit
[rofl0r-kripto.git] / test / block / noekeon.c
blob112a555db8b9f687c06f156c3fce67c147aac288
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.h>
18 #include <kripto/block/noekeon.h>
20 #if defined(_TEST) || defined(_PERF)
22 #ifdef _PERF
24 #ifndef _CPU
25 #define _CPU 2000
26 #endif
28 #ifndef ITERATIONS
29 #define ITERATIONS 10000000
30 #endif
32 #include <time.h>
34 #endif
36 #include <stdio.h>
38 int main(void)
40 kripto_block_noekeon_t s;
41 unsigned int i;
42 uint8_t t[16] = {
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
46 const uint8_t kc[16] = {
47 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
48 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C
50 #ifdef _TEST
51 #ifdef NOEKEON_DIRECT
52 const uint8_t p[16] = {
53 0x61, 0x39, 0x6C, 0x93, 0x63, 0x74, 0x34, 0xB8,
54 0xFC, 0x65, 0x59, 0xA9, 0x5B, 0x64, 0x3F, 0x2C
56 #else
57 const uint8_t p[16] = {
58 0x7A, 0xFE, 0x55, 0x8A, 0x46, 0xFE, 0x07, 0x6E,
59 0x35, 0x62, 0x35, 0xF5, 0x9F, 0x32, 0xE7, 0xCC
61 #endif
62 #endif
63 #ifdef _PERF
64 clock_t c;
65 #endif
67 puts("Noekeon");
69 s.r = NOEKEON_DEFAULT_ROUNDS;
70 kripto_block_noekeon_setup(&s, kc, 16);
72 #ifdef _TEST
73 kripto_block_noekeon_encrypt(&s, p, t);
74 for(i = 0; i < 16; i++) if(t[i] != kc[i])
76 puts("128-bit key encrypt: FAIL");
77 break;
79 if(i == 16) puts("128-bit key encrypt: OK");
80 kripto_block_noekeon_decrypt(&s, kc, t);
81 for(i = 0; i < 16; i++) if(t[i] != p[i])
83 puts("128-bit key decrypt: FAIL");
84 break;
86 if(i == 16) puts("128-bit key decrypt: OK");
87 #endif
89 #ifdef _PERF
90 c = clock();
91 for(i = 0; i < ITERATIONS; i++) kripto_block_noekeon_encrypt(&s, t, t);
92 c = clock() - c;
94 printf("128 bit key encrypt: %.1f cycles/byte, %.1f MB/s\n",
95 (float)c / (float)(ITERATIONS * 16) * _CPU,
96 (float)(ITERATIONS * 16) / ((float)c / (float)CLOCKS_PER_SEC) / 1000000.0);
98 c = clock();
99 for(i = 0; i < ITERATIONS; i++) kripto_block_noekeon_decrypt(&s, t, t);
100 c = clock() - c;
102 printf("128 bit key decrypt: %.1f cycles/byte, %.1f MB/s\n",
103 (float)c / (float)(ITERATIONS * 16) * _CPU,
104 (float)(ITERATIONS * 16) / ((float)c / (float)CLOCKS_PER_SEC) / 1000000.0);
105 #endif
107 return(0);
110 #endif