-
Notifications
You must be signed in to change notification settings - Fork 0
/
tftest.c
55 lines (43 loc) · 1.25 KB
/
tftest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "tfdef.h"
#include "tfsupport.h"
static uint64_t encbytes, decbytes;
static char sdata[DATASIZE], udata[DATASIZE];
static char key[TF_KEY_SIZE] = "\a\x76syR_\x98?";
static unsigned do_break;
static void do_stop_sig(int unused)
{
do_break = 1;
}
int main(void)
{
memset(sdata, 'X', sizeof(sdata));
tf_convkey(key);
printf("Doing encryption loop for next %u seconds...\n", TESTTIME);
signal(SIGALRM, do_stop_sig);
alarm(TESTTIME);
tf_ecb_encrypt(key, udata, sdata, sizeof(sdata));
while (1) {
if (do_break) break;
tf_ecb_encrypt(key, udata, udata, sizeof(udata));
encbytes += sizeof(udata);
}
puts("Encrypted ECB blocks:");
mhexdump(udata, TF_BLOCK_SIZE * 2, HD_WIDTH);
puts("...");
puts("Done. Doing decryption of encrypted cell...");
while (1) {
tf_ecb_decrypt(key, udata, udata, sizeof(udata));
decbytes += sizeof(udata);
if (decbytes >= encbytes) break;
}
tf_ecb_decrypt(key, udata, udata, sizeof(udata));
if (!memcmp(udata, sdata, sizeof(sdata)))
puts("\n*** Cells are identical, cipher succeeded! ***\n");
printf("Stats: encrypted: %llu, byps: %llu\n", encbytes, decbytes / TESTTIME);
puts("Threefish cipher testing program done.");
return 0;
}