]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/libfreeswan/libcrypto/libaes/test_main.c
- fixed stroke error output to starter
[people/ms/strongswan.git] / src / libfreeswan / libcrypto / libaes / test_main.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include "aes_cbc.h"
5 #define AES_BLOCK_SIZE 16
6 #define KEY_SIZE 128 /* bits */
7 #define KEY "1234567890123456"
8 #define STR "hola guaso como estaisss ... 012"
9 #define STRSZ (sizeof(STR)-1)
10
11 #define EMT_AESCBC_BLKLEN AES_BLOCK_SIZE
12 #define AES_CONTEXT_T aes_context
13 #define EMT_ESPAES_KEY_SZ 16
14 int pretty_print(const unsigned char *buf, int count) {
15 int i=0;
16 for (;i<count;i++) {
17 if (i%8==0) putchar(' ');
18 if (i%16==0) putchar('\n');
19 printf ("%02hhx ", buf[i]);
20 }
21 putchar('\n');
22 return i;
23 }
24 //#define SIZE STRSZ/2
25 #define SIZE STRSZ
26 int main() {
27 int ret;
28 char buf0[SIZE+1], buf1[SIZE+1];
29 char IV[AES_BLOCK_SIZE]="\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0";
30 aes_context ac;
31 AES_set_key(&ac, KEY, KEY_SIZE);
32 //pretty_print((char *)&ac.aes_e_key, sizeof(ac.aes_e_key));
33 memset(buf0, 0, sizeof (buf0));
34 memset(buf1, 0, sizeof (buf1));
35 ret=AES_cbc_encrypt(&ac, STR, buf0, SIZE, IV, 1);
36 pretty_print(buf0, SIZE);
37 printf("size=%d ret=%d\n%s\n", SIZE, ret, buf0);
38 ret=AES_cbc_encrypt(&ac, buf0, buf1, SIZE, IV, 0);
39 printf("size=%d ret=%d\n%s\n", SIZE, ret, buf1);
40 return 0;
41 }