File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / example / aes.c
Revision 1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Fri Oct 7 09:14:40 2011 UTC (12 years, 8 months ago) by misho
Branches: io2_1
added aes unit test
add AES ctr cipher feature

    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;
   11: 
   12: 	if (argc < 3)
   13: 		return 1;
   14: 
   15: 	printf("String=%s\nKey=%s\n\n", argv[1], argv[2]);
   16: 	/* encode */
   17: 	printf("io_ctr_AES() -> %d\n", (n = io_ctr_AES(argv[1], strlen(argv[1]), (u_char**) &str, argv[2])));
   18: 	printf("Cipher: ");
   19: 	for (i = 0; i < n; i++)
   20: 		printf("%02hhx", str[i]);
   21: 	printf("\n");
   22: 
   23: 	/* decode */
   24: 	printf("io_ctr_AES() -> %d\n", (n = io_ctr_AES(str, n, (u_char**) &str2, argv[2])));
   25: 	printf("Plain: ");
   26: 	for (i = 0; i < n; i++)
   27: 		printf("%c", str2[i]);
   28: 	printf("\n");
   29: 
   30: 	printf("\n\n");
   31: 	if (!strcmp(argv[1], str2))
   32: 		printf("%s == %s ... Test passed\n", argv[1], str2);
   33: 	else
   34: 		printf("%s != %s ... Test FAILED\n", argv[1], str2);
   35: 
   36: 	if (str)
   37: 		free(str);
   38: 	if (str2)
   39: 		free(str2);
   40: 
   41: 	return 0;
   42: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>