/*- * Copyright (c) 2008 Damien Bergamini * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include static void print_hex(char *str, unsigned char *buf, int len) { int i; for ( i=0; i\n"); AES_CMAC_SetKey(&ctx, key); AES_CMAC_Init(&ctx); AES_CMAC_Update(&ctx, M, 0); AES_CMAC_Final(T, &ctx); printf("AES_CMAC "); print128(T); printf("\n"); printf("\nExample 2: len = 16\n"); printf("M "); print_hex(" ",M,16); AES_CMAC_SetKey(&ctx, key); AES_CMAC_Init(&ctx); AES_CMAC_Update(&ctx, M, 16); AES_CMAC_Final(T, &ctx); printf("AES_CMAC "); print128(T); printf("\n"); printf("\nExample 3: len = 40\n"); printf("M "); print_hex(" ",M,40); AES_CMAC_SetKey(&ctx, key); AES_CMAC_Init(&ctx); AES_CMAC_Update(&ctx, M, 40); AES_CMAC_Final(T, &ctx); printf("AES_CMAC "); print128(T); printf("\n"); printf("\nExample 4: len = 64\n"); printf("M "); print_hex(" ",M,64); AES_CMAC_SetKey(&ctx, key); AES_CMAC_Init(&ctx); AES_CMAC_Update(&ctx, M, 64); AES_CMAC_Final(T, &ctx); printf("AES_CMAC "); print128(T); printf("\n"); printf("\nExample 4bis: len = 64\n"); printf("M "); print_hex(" ",M,64); AES_CMAC_SetKey(&ctx, key); AES_CMAC_Init(&ctx); AES_CMAC_Update(&ctx, M, 40); AES_CMAC_Update(&ctx, M + 40, 24); AES_CMAC_Final(T, &ctx); printf("AES_CMAC "); print128(T); printf("\n"); printf("\nExample 4ter: len = 64\n"); printf("M "); print_hex(" ",M,64); AES_CMAC_SetKey(&ctx, key); AES_CMAC_Init(&ctx); AES_CMAC_Update(&ctx, M, 16); AES_CMAC_Update(&ctx, M + 16, 16); AES_CMAC_Update(&ctx, M + 32, 10); AES_CMAC_Update(&ctx, M + 42, 0); AES_CMAC_Update(&ctx, M + 42, 14); AES_CMAC_Update(&ctx, M + 56, 8); AES_CMAC_Final(T, &ctx); printf("AES_CMAC "); print128(T); printf("\n"); printf("--------------------------------------------------\n"); return 0; }