]> git.ipfire.org Git - people/ms/strongswan.git/blob - lib/libcrypto/libserpent/test_main.c
- import of strongswan-2.7.0
[people/ms/strongswan.git] / lib / libcrypto / libserpent / test_main.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "serpent_cbc.h"
4 #define BLOCK_SIZE 16
5 #define KEY_SIZE 128 /* bits */
6 #define KEY "1234567890123456"
7 #define STR "hola guaso como estaisss ... 012"
8 #define STRSZ (sizeof(STR)-1)
9
10 #define BLKLEN BLOCK_SIZE
11 #define CONTEXT_T serpent_context
12 static int pretty_print(const unsigned char *buf, int count) {
13 int i=0;
14 for (;i<count;i++) printf ("%02hhx ", buf[i]);
15 putchar('\n');
16 return i;
17 }
18 //#define SIZE STRSZ/2
19 #define SIZE STRSZ
20 int main() {
21 int ret;
22 char buf0[SIZE+1], buf1[SIZE+1];
23 char IV[BLOCK_SIZE];
24 CONTEXT_T ac;
25 serpent_set_key(&ac, (void *)KEY, KEY_SIZE);
26 memset(buf0, 0, sizeof (buf0));
27 memset(buf1, 0, sizeof (buf1));
28 serpent_cbc_encrypt(&ac, STR, buf0, SIZE, IV, 1);
29 pretty_print(buf0, SIZE);
30 printf("size=%d ret=%d\n%s\n", SIZE, ret, buf0);
31 ret=serpent_cbc_encrypt(&ac, buf0, buf1, SIZE, IV, 0);
32 printf("size=%d ret=%d\n%s\n", SIZE, ret, buf1);
33 return 0;
34 }