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.h>
18 #include <kripto/block/noekeon.h>
20 #if defined(_TEST) || defined(_PERF)
29 #define ITERATIONS 10000000
40 kripto_block_noekeon_t s
;
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
52 const uint8_t p
[16] = {
53 0x61, 0x39, 0x6C, 0x93, 0x63, 0x74, 0x34, 0xB8,
54 0xFC, 0x65, 0x59, 0xA9, 0x5B, 0x64, 0x3F, 0x2C
57 const uint8_t p
[16] = {
58 0x7A, 0xFE, 0x55, 0x8A, 0x46, 0xFE, 0x07, 0x6E,
59 0x35, 0x62, 0x35, 0xF5, 0x9F, 0x32, 0xE7, 0xCC
69 s
.r
= NOEKEON_DEFAULT_ROUNDS
;
70 kripto_block_noekeon_setup(&s
, kc
, 16);
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");
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");
86 if(i
== 16) puts("128-bit key decrypt: OK");
91 for(i
= 0; i
< ITERATIONS
; i
++) kripto_block_noekeon_encrypt(&s
, t
, t
);
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);
99 for(i
= 0; i
< ITERATIONS
; i
++) kripto_block_noekeon_decrypt(&s
, t
, t
);
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);