5 //#include "../ciphers.h"
6 #include "../serpent.h"
8 #define timediff(tv2, tv1) (((tv2)->tv_sec - (tv1)->tv_sec)*1000000 + \
9 ((tv2)->tv_usec - (tv1)->tv_usec))
11 int main(int argc, char **argv)
14 unsigned char key[256];
15 unsigned char plain[512];
16 unsigned char plain2[512];
17 unsigned char cipher[512];
18 unsigned char iv[128];
19 struct timeval tv1,tv2;
21 memset(&key, 0, sizeof(key));
22 memset(&plain, 0, sizeof(plain));
23 memset(&plain2, 0, sizeof(plain2));
24 memset(&cipher, 0, sizeof(cipher));
25 memset(&iv, 0, sizeof(iv));
27 gettimeofday(&tv1, NULL);
28 silc_serpent_init(NULL, key, 128);
29 gettimeofday(&tv2, NULL);
31 fprintf(stderr, "\nPlaintext:\n");
32 for (i = 0; i < sizeof(plain) / 2; i += 2) {
35 fprintf(stderr, "%02x%02x ", plain[i], plain[i+1]);
38 fprintf(stderr, "\n\nEncrypting\n");
39 gettimeofday(&tv1, NULL);
40 silc_serpent_encrypt_cbc(NULL, plain, cipher, sizeof(plain), iv);
41 gettimeofday(&tv2, NULL);
43 fprintf(stderr, "Encrypt %6.3f Mb/s\n",
44 1000000.0*8.0/timediff(&tv2,&tv1));
46 fprintf(stderr, "Ciphertext:\n");
47 for (i = 0; i < (sizeof(cipher)/2); i += 2) {
48 fprintf(stderr, "%02x", cipher[i]);
49 fprintf(stderr, "%02x ", cipher[i+1]);
52 fprintf(stderr, "\n\nDecrypting\n");
53 gettimeofday(&tv1, NULL);
54 silc_serpent_decrypt_cbc(NULL, cipher, plain2, sizeof(cipher), iv);
55 gettimeofday(&tv2, NULL);
57 fprintf(stderr, "Decrypt %6.3f Mb/s\n",
58 1000000.0*8.0/timediff(&tv2,&tv1));
60 fprintf(stderr, "Decrypted text:\n");
61 for (i = 0; i < (sizeof(plain2)/2); i += 2) {
62 fprintf(stderr, "%02x", plain2[i]);
63 fprintf(stderr, "%02x ", plain2[i+1]);
65 fprintf(stderr, "\nDone\n");