Added SILC Server library.
[silc.git] / lib / silccrypt / tests / test_twofish.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "silc.h"
4
5 #include "twofish.h"
6
7 int main()
8 {
9         int i;
10         unsigned char key[256];
11         unsigned char plain[256];
12         unsigned char plain2[256];
13         unsigned char cipher[256];
14         unsigned char iv[256];
15         void *context;
16
17         memset(&key, 0, sizeof(key));
18         memset(&plain, 0, sizeof(plain));
19         memset(&plain2, 0, sizeof(plain2));
20         memset(&cipher, 0, sizeof(cipher));
21         memset(&iv, 0, sizeof(iv));
22
23         context = malloc(silc_twofish_context_len());
24
25         fprintf(stderr, "\nKey:\n");
26         for (i = 0; i < (sizeof(key) / 2); i += 2) {
27                 fprintf(stderr, "%02x%02x ", key[i], key[i+1]);
28         }
29
30         fprintf(stderr, "\nSetting key\n");
31         silc_twofish_set_key(context, key, 256);
32
33         fprintf(stderr, "\nPlaintext:\n");
34         for (i = 0; i < (sizeof(plain) / 2); i += 2) {
35                 plain[i] = i;
36                 plain[i+1] = i+1;
37                 fprintf(stderr, "%02x%02x ", plain[i], plain[i+1]);
38         }
39
40         fprintf(stderr, "\n\nEncrypting\n");
41         silc_twofish_encrypt_cbc(context, plain, cipher, 256, iv);
42
43         fprintf(stderr, "Ciphertext:\n");
44         for (i = 0; i < (sizeof(cipher)/2); i += 2) {
45                 fprintf(stderr, "%02x", cipher[i]);
46                 fprintf(stderr, "%02x ", cipher[i+1]);
47         }
48
49         memset(&iv, 0, sizeof(iv));
50
51         fprintf(stderr, "\n\nDecrypting\n");
52         silc_twofish_decrypt_cbc(context, cipher, plain2, 256, iv);
53
54         fprintf(stderr, "Decryptedtext:\n");
55         for (i = 0; i < (sizeof(plain2)/2); i += 2) {
56                 fprintf(stderr, "%02x", plain2[i]);
57                 fprintf(stderr, "%02x ", plain2[i+1]);
58         }
59         fprintf(stderr, "\nDone\n");
60
61         return 0;
62 }