From ddce9b2d44ab48fc566870c5155b39c8fc06f24d Mon Sep 17 00:00:00 2001 From: Benedict Date: Tue, 21 Feb 2017 12:52:02 +0100 Subject: moved files of set1 into subdir --- task7.c | 86 ----------------------------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 task7.c (limited to 'task7.c') diff --git a/task7.c b/task7.c deleted file mode 100644 index d71da7a..0000000 --- a/task7.c +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include -#include -#include - -int handleErrors() -{ - ERR_print_errors_fp(stderr); - abort(); -} - -int do_crypt(FILE *in, FILE *out, int do_encrypt) -{ - unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; - int inlen, outlen; - EVP_CIPHER_CTX *ctx; - - unsigned char key[] = "YELLOW SUBMARINE"; - - ctx = EVP_CIPHER_CTX_new(); - - EVP_CipherInit_ex(ctx, EVP_aes_128_ecb(), NULL, NULL, NULL, do_encrypt); - - EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, do_encrypt); - - for(;;) { - inlen = fread(inbuf, 1, 1024, in); - if (inlen <= 0) - break; - - if(!EVP_CipherUpdate(ctx, outbuf, &outlen, inbuf, inlen)) { - EVP_CIPHER_CTX_free(ctx); - return 0; - } - - fwrite(outbuf, 1, outlen, out); - } - - if(!EVP_CipherFinal_ex(ctx, outbuf, &outlen)) { - EVP_CIPHER_CTX_free(ctx); - return 0; - } - - fwrite(outbuf, 1, outlen, out); - - EVP_CIPHER_CTX_free(ctx); - return 1; -} - -int main(int argc, char **argv) -{ - ERR_load_crypto_strings(); - - OpenSSL_add_all_algorithms(); - - OPENSSL_config(NULL); - - - FILE *in; - FILE *out; - - in = fopen("7unbased.txt", "r"); - out = fopen ("7cleartext.txt", "w"); - - if ( in == NULL) { - printf("error in\n"); - return 1; - } - - if (out == NULL) { - printf("error out\n"); - return 1; - } - - do_crypt(in, out, 0); - - - EVP_cleanup(); - - CRYPTO_cleanup_all_ex_data(); - - ERR_free_strings(); - - return 0; -} - -- cgit v1.2.3-70-g09d2