Annotation of libaitio/example/aes.c, revision 1.3
1.2 misho 1: #include <stdio.h>
2: #include <string.h>
3: #include <aitio.h>
4:
5:
6: int
7: main(int argc, char **argv)
8: {
9: char *str2 = NULL, *str = NULL;
10: int i, n;
1.3 ! misho 11: u_char ivec[16];
1.2 misho 12:
13: if (argc < 4)
14: return 1;
15:
16: printf("String=%s\nKey=%s IV=%s\n\n", argv[1], argv[2], argv[3]);
17: /* encode */
18: memset(ivec, 0, sizeof ivec);
1.3 ! misho 19: strlcpy((char*) ivec, argv[3], sizeof ivec);
! 20: printf("io_ctr_AES() -> %d\n", (n = io_ctr_AES((u_char*) argv[1], strlen(argv[1]),
! 21: (u_char**) &str, (u_char*) argv[2], ivec)));
1.2 misho 22: printf("Cipher: ");
23: for (i = 0; i < n; i++)
24: printf("%02hhx", str[i]);
25: printf("\n");
26:
27: /* decode */
28: memset(ivec, 0, sizeof ivec);
1.3 ! misho 29: strlcpy((char*) ivec, argv[3], sizeof ivec);
! 30: printf("io_ctr_AES() -> %d\n", (n = io_ctr_AES((u_char*) str, n,
! 31: (u_char**) &str2, (u_char*) argv[2], ivec)));
1.2 misho 32: printf("Plain: ");
33: for (i = 0; i < n; i++)
34: printf("%c", str2[i]);
35: printf("\n");
36:
37: printf("\n\n");
38: if (!strcmp(argv[1], str2))
39: printf("%s == %s ... Test passed\n", argv[1], str2);
40: else
41: printf("%s != %s ... Test FAILED\n", argv[1], str2);
42:
43: if (str)
44: free(str);
45: if (str2)
46: free(str2);
47:
48: return 0;
49: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>