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/seed.h>
21 #if defined(_TEST) || defined(_PERF)
30 #define ITERATIONS 10000000
41 kripto_block_seed_t
*s
;
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
47 const uint8_t k
[16] = {
48 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
49 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
53 const uint8_t pt
[16] = {
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
57 const uint8_t ct
[16][16] = {
58 {0x90, 0x69, 0x9d, 0xe4, 0x78, 0x93, 0x70, 0x1e,
59 0x75, 0x11, 0x19, 0x6b, 0xe3, 0x12, 0xaf, 0x92},
60 {0x03, 0x2f, 0xdd, 0x84, 0xd5, 0x36, 0x12, 0x3b,
61 0x35, 0xfa, 0xaa, 0x81, 0x67, 0x45, 0x0e, 0x50},
62 {0x3f, 0x64, 0xcc, 0xf5, 0x04, 0xcc, 0x03, 0xf3,
63 0x59, 0x9f, 0x3d, 0x93, 0x28, 0x0f, 0x9d, 0x20},
64 {0xe1, 0xb2, 0xf0, 0x73, 0x8b, 0xda, 0x98, 0x7c,
65 0xa5, 0x37, 0xdb, 0xc4, 0xfc, 0x88, 0x1e, 0xd7},
66 {0xeb, 0xae, 0x4a, 0x8c, 0x38, 0x53, 0x72, 0x64,
67 0x41, 0x99, 0x96, 0x20, 0x76, 0x05, 0x92, 0x2a},
68 {0xfb, 0x44, 0x38, 0xbf, 0xb1, 0x10, 0x76, 0x9b,
69 0x2d, 0x94, 0xb0, 0x73, 0x61, 0xb5, 0x69, 0x48},
70 {0x5c, 0x43, 0x53, 0xc1, 0xc0, 0xcf, 0x5c, 0xad,
71 0xe7, 0x9a, 0xb2, 0x83, 0x5a, 0x82, 0x8d, 0x6f},
72 {0x10, 0x74, 0xff, 0x4d, 0xa6, 0xcd, 0x3d, 0x22,
73 0xe0, 0x7e, 0x13, 0x71, 0x31, 0x06, 0xef, 0x09},
74 {0x5e, 0xfb, 0x02, 0x9c, 0x84, 0xff, 0x34, 0xa7,
75 0xec, 0xba, 0xa8, 0x06, 0x3a, 0x51, 0x2d, 0xa8},
76 {0x6b, 0x85, 0xd1, 0xc5, 0x32, 0x5c, 0xe2, 0xb8,
77 0xa3, 0x76, 0xc4, 0x5c, 0x81, 0xab, 0xf2, 0x66},
78 {0x4c, 0x57, 0x35, 0xcc, 0xd0, 0x91, 0xdf, 0x92,
79 0xc1, 0x24, 0x7c, 0x59, 0x80, 0x77, 0x84, 0x32},
80 {0x3e, 0x82, 0x9e, 0x93, 0x74, 0xf3, 0x56, 0x8a,
81 0xfe, 0x1f, 0x47, 0xf0, 0x4e, 0x49, 0x24, 0x99},
82 {0xce, 0xb4, 0xe3, 0x84, 0xc9, 0x2b, 0x29, 0xec,
83 0xfe, 0x67, 0xaf, 0x56, 0x70, 0xf8, 0x3d, 0x1e},
84 {0x9a, 0xab, 0xd5, 0x38, 0x07, 0xcf, 0xd1, 0x5a,
85 0x47, 0x9a, 0x5e, 0x59, 0xfc, 0xbe, 0xe9, 0x0a},
86 {0xd6, 0x40, 0xf9, 0xed, 0xec, 0x70, 0xa5, 0xb8,
87 0xb0, 0x6c, 0xb2, 0x0e, 0x01, 0x92, 0x5e, 0x44},
88 {0xc1, 0x1f, 0x22, 0xf2, 0x01, 0x40, 0x50, 0x50,
89 0x84, 0x48, 0x35, 0x97, 0xe4, 0x37, 0x0f, 0x43}
99 for(n
= 1; n
<= 16; n
++)
101 s
= kripto_block_seed_new(k
, n
, SEED_DEFAULT_ROUNDS
);
103 kripto_block_seed_encrypt(s
, pt
, t
);
104 for(i
= 0; i
< 16; i
++) if(t
[i
] != ct
[n
- 1][i
])
106 printf("%u-bit key encrypt: FAIL\n", n
* 8);
109 if(i
== 16) printf("%u-bit key encrypt: OK\n", n
* 8);
110 kripto_block_seed_decrypt(s
, ct
[n
- 1], t
);
111 for(i
= 0; i
< 16; i
++) if(t
[i
] != pt
[i
])
113 printf("%u-bit key decrypt: FAIL\n", n
* 8);
116 if(i
== 16) printf("%u-bit key decrypt: OK\n", n
* 8);
118 kripto_block_seed_delete(s
);
123 s
= kripto_block_seed_new(k
, 16, SEED_DEFAULT_ROUNDS
);
126 for(i
= 0; i
< ITERATIONS
; i
++) kripto_block_seed_encrypt(s
, t
, t
);
129 printf("encrypt: %.1f cycles/byte, %.1f MB/s\n",
130 (float)c
/ (float)(ITERATIONS
* 16) * _CPU
,
131 (float)(ITERATIONS
* 16) / ((float)c
/ (float)CLOCKS_PER_SEC
) / 1000000.0);
134 for(i
= 0; i
< ITERATIONS
; i
++) kripto_block_seed_decrypt(s
, t
, t
);
137 printf("decrypt: %.1f cycles/byte, %.1f MB/s\n",
138 (float)c
/ (float)(ITERATIONS
* 16) * _CPU
,
139 (float)(ITERATIONS
* 16) / ((float)c
/ (float)CLOCKS_PER_SEC
) / 1000000.0);
141 kripto_block_seed_delete(s
);