#include <stdlib.h>
#include <stdio.h>
#include <include/ecctk-prototype.h>
#include <include/ecctk-hash.h>
s2byte mac_file()
{
s2byte ret = -1;
s2byte algo = ECCTK_HASH_MAC_ALGO_RMD128;
s1byte file[] = "file_to_hash";
u1byte hash[ECCTK_HASH_SIZE_SHA160];
u1byte key[] = {0x34, 0x12, 0x45, 0xa3, 0x1b, 0x59, 0x4f, 0x9d, 0xfc, 0x45,
0xa3, 0x1b, 0x67, 0x35, 0x34, 0x12, 0xde, 0xa8, 0xf9, 0x5c};
u2byte hashsize,
i;
switch (algo)
{
case ECCTK_HASH_MAC_ALGO_RMD128:
hashsize = ECCTK_HASH_SIZE_RMD128;
ret = RIPEMD128_FileMAC(file, key, sizeof(key), hash, hashsize);
break;
#ifndef ECCTK_EVALUATION
case ECCTK_HASH_MAC_ALGO_RMD160:
hashsize = ECCTK_HASH_SIZE_RMD160;
ret = RIPEMD160_FileMAC(file, key, sizeof(key), hash, hashsize);
break;
#endif
default:
fprintf(stderr, "Unknown MAC algorithm\n");
return EXIT_FAILURE;
break;
}
if (ret != ECCTK_HASH_NO_ERROR)
{
fprintf(stderr, "MAC %s failed (Error : %d)\n", file, ret);
return EXIT_FAILURE;
}
printf("MAC (%s) = ", file);
for (i = 0; i < hashsize; i++)
printf("%02x", hash[i]);
printf("\n");
return EXIT_SUCCESS;
}