#include <config.h>
#include <roken.h>
#include <krb5-types.h>
#include <hcrypto/evp.h>
#include <hcrypto/evp-pkcs11.h>
#ifdef __APPLE__
#include <hcrypto/evp-cc.h>
#endif
#ifdef _WIN32
#include <hcrypto/evp-w32.h>
#endif
#include <err.h>
#include <assert.h>
static char key[16] =
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4"
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4";
static char ivec[16] =
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4"
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4";
static void
usage(int exit_code) __attribute__((noreturn));
static void
usage(int exit_code)
{
printf("usage: %s in out [pkcs11 | cc | w32]\n", getprogname());
exit(exit_code);
}
int
main(int argc, char **argv)
{
int encryptp = 1;
const char *ifn = NULL, *ofn = NULL;
FILE *in, *out;
void *ibuf, *obuf;
int ilen, olen;
size_t block_size = 0;
EVP_CIPHER_CTX ctx;
int ret;
setprogname(argv[0]);
if (argc == 2) {
if (strcmp(argv[1], "--version") == 0) {
printf("version");
exit(0);
}
if (strcmp(argv[1], "--help") == 0)
usage(0);
usage(1);
} else if (argc == 4 || argc == 5) {
block_size = atoi(argv[1]);
if (block_size == 0)
errx(1, "invalid blocksize %s", argv[1]);
ifn = argv[2];
ofn = argv[3];
if (argc == 5) {
if (strcmp(argv[4], "pkcs11") == 0)
c = hc_EVP_pkcs11_aes_128_cbc();
#ifdef __APPLE__
else if (strcmp(argv[4], "cc") == 0)
c = hc_EVP_cc_aes_128_cbc();
#endif
#ifdef _WIN32
else if (strcmp(argv[4], "w32") == 0)
c = hc_EVP_w32crypto_aes_128_cbc();
#endif
else
usage(1);
}
} else
usage(1);
in = fopen(ifn, "r");
if (in == NULL)
errx(1, "failed to open input file");
out = fopen(ofn, "w+");
if (out == NULL)
errx(1, "failed to open output file");
ibuf = malloc(block_size);
while ((ilen = fread(ibuf, 1, block_size, in)) > 0) {
if (ret != 1) {
errx(1, "EVP_CipherUpdate failed");
}
fwrite(obuf, 1, olen, out);
}
fclose(in);
if (ret != 1)
errx(1, "EVP_CipherFinal_ex failed");
fwrite(obuf, 1, olen, out);
fclose(out);
return 0;
}
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *c)
Definition: evp.c:570
const EVP_CIPHER * EVP_aes_128_cbc(void)
Definition: evp.c:1153
size_t EVP_CIPHER_block_size(const EVP_CIPHER *c)
Definition: evp.c:523
size_t EVP_CIPHER_key_length(const EVP_CIPHER *c)
Definition: evp.c:539
int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, void *out, int *outlen)
Definition: evp.c:939
size_t EVP_CIPHER_iv_length(const EVP_CIPHER *c)
Definition: evp.c:555
int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, void *out, int *outlen, void *in, size_t inlen)
Definition: evp.c:853
int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *c, ENGINE *engine, const void *key, const void *iv, int encp)
Definition: evp.c:775
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
Definition: evp.c:586