#include <stdlib.h>
#include <stdio.h>
#include <include/ecctk-prototype.h>
#include <include/ecctk-hash.h>
#include <include/ecctk-ecc.h>
s2byte encrypt_file_asym()
{
s4byte ret = -1;
s2byte algo = ECCTK_ECC_ALGO_PSEC3;
#ifndef ECCTK_EVALUATION
s2byte hash_algo = ECCTK_HASH_ALGO_SHA384,
#else
s2byte hash_algo = ECCTK_HASH_ALGO_SHA160,
#endif
hmac_algo = ECCTK_HASH_HMAC_ALGO_SHA160;
s1byte infile[] = "protected_file",
outfile[] = "unprotected_file",
kpubfile[] = "public_key_file",
cipherfile[]= "cipher_file";
KPUB_CTX *kpub;
ECC_CIPHER_CTX *cipher;
kpub = ReadFileKpubCtx(kpubfile);
if (kpub == NULL)
{
fprintf(stderr, "Read public key on %s failed\n", kpubfile);
return EXIT_FAILURE;
}
cipher = ReadFileEccCipherCtx(cipherfile);
if (cipher == NULL)
{
fprintf(stderr, "Read cipher on %s failed\n", cipherfile);
KpubCtxFree(kpub);
return EXIT_FAILURE;
}
ret = InitializeEcctkAll();
if (ret != ECCTK_ECC_NO_ERROR)
{
fprintf(stderr, "InitializeEcctkAll failed (%d)\n", ret);
return EXIT_FAILURE;
}
switch (algo)
{
case ECCTK_ECC_ALGO_ECIES:
ret = EncryptFileEcies(infile, outfile, hmac_algo, kpub, cipher);
break;
case ECCTK_ECC_ALGO_PSEC3:
ret = EncryptFilePsec3(infile, outfile, hash_algo, kpub, cipher);
break;
default:
ret = -1;
break;
}
if (ret != ECCTK_ECC_NO_ERROR)
fprintf(stderr, "Encrypt %s failed (Error : %ld)\n", infile, ret);
else
fprintf(stdout, "Encrypt %s success, %s generated\n", infile, outfile);
KpubCtxFree(kpub);
EccCipherCtxFree(cipher);
FreeEcctkAll();
return EXIT_SUCCESS;
}