OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / 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 static int pretty_print(const unsigned char *buf, int count) {
15         int i=0;
16         for (;i<count;i++) printf ("%02hhx ", buf[i]);
17         putchar('\n');
18         return i;
19 }
20 //#define SIZE STRSZ/2
21 #define SIZE STRSZ
22 int main() {
23         int ret;
24         char buf0[SIZE+1], buf1[SIZE+1];
25         char IV[AES_BLOCK_SIZE];
26         aes_context ac; 
27         AES_set_key(&ac, KEY, KEY_SIZE);
28         memset(buf0, 0, sizeof (buf0));
29         memset(buf1, 0, sizeof (buf1));
30         pretty_print(STR, SIZE);
31         ret=AES_cbc_encrypt(&ac, STR, buf0, SIZE, IV, 1);
32         pretty_print(buf0, SIZE);
33         printf("size=%d ret=%d\n%s\n", SIZE, ret, buf0);
34         ret=AES_cbc_encrypt(&ac, buf0, buf1, SIZE, IV, 0);
35         printf("size=%d ret=%d\n%s\n", SIZE, ret, buf1);
36         return 0;
37 }