From 5fe37073665f5b31dc3a89bbcb21a6e2587b09a4 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 10 Jun 2015 05:03:10 +0300 Subject: rename source files --- src/buffer.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/file.c | 81 ------------------------------------------------------------ 2 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 src/buffer.c delete mode 100644 src/file.c (limited to 'src') diff --git a/src/buffer.c b/src/buffer.c new file mode 100644 index 0000000..d8ff9c7 --- /dev/null +++ b/src/buffer.c @@ -0,0 +1,81 @@ +/** + * \file + * \author Egor Tensin + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#include + +#include +#include + +size_t aes128ecb_encrypt_buffer( + const unsigned char* src, + size_t src_size, + unsigned char* dest, + Aes128KeySchedule* key_schedule) +{ + size_t rem_size = src_size % 16; + size_t padding_size = 16 - rem_size; + size_t dest_size = src_size + padding_size; + + if (dest == NULL) + return dest_size; + + size_t src_len = src_size / 16; + + for (size_t i = 0; i < src_len; ++i, src += 16, dest += 16) + { + AesBlock128 plaintext = load_aes_block128(src); + AesBlock128 ciphertext = aes128ecb_encrypt_block(plaintext, key_schedule); + store_aes_block128(ciphertext, dest); + } + + unsigned char padding[16] = { 0x10 }; + + if (rem_size != 0) + { + memcpy(padding, src, rem_size); + memset(padding + rem_size, padding_size, padding_size); + } + + AesBlock128 plaintext = load_aes_block128(padding); + AesBlock128 ciphertext = aes128ecb_encrypt_block(plaintext, key_schedule); + store_aes_block128(ciphertext, dest); + + return dest_size; +} + +size_t aes128ecb_decrypt_buffer( + const unsigned char* src, + size_t src_size, + unsigned char* dest, + Aes128KeySchedule* inverted_schedule) +{ + size_t dest_size = src_size; + + if (dest == NULL) + return dest_size; + + size_t src_len = src_size / 16; + + for (size_t i = 0; i < src_len - 1; ++i, src += 16, dest += 16) + { + AesBlock128 ciphertext = load_aes_block128(src); + AesBlock128 plaintext = aes128ecb_decrypt_block(ciphertext, inverted_schedule); + store_aes_block128(plaintext, dest); + } + + AesBlock128 ciphertext = load_aes_block128(src); + AesBlock128 plaintext = aes128ecb_decrypt_block(ciphertext, inverted_schedule); + unsigned char padding[16]; + store_aes_block128(plaintext, padding); + + if (padding[0] == 0x10) + return dest_size - 16; + + memcpy(dest, padding, 16 - padding[15]); + return dest_size - padding[15]; +} diff --git a/src/file.c b/src/file.c deleted file mode 100644 index d8ff9c7..0000000 --- a/src/file.c +++ /dev/null @@ -1,81 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include - -size_t aes128ecb_encrypt_buffer( - const unsigned char* src, - size_t src_size, - unsigned char* dest, - Aes128KeySchedule* key_schedule) -{ - size_t rem_size = src_size % 16; - size_t padding_size = 16 - rem_size; - size_t dest_size = src_size + padding_size; - - if (dest == NULL) - return dest_size; - - size_t src_len = src_size / 16; - - for (size_t i = 0; i < src_len; ++i, src += 16, dest += 16) - { - AesBlock128 plaintext = load_aes_block128(src); - AesBlock128 ciphertext = aes128ecb_encrypt_block(plaintext, key_schedule); - store_aes_block128(ciphertext, dest); - } - - unsigned char padding[16] = { 0x10 }; - - if (rem_size != 0) - { - memcpy(padding, src, rem_size); - memset(padding + rem_size, padding_size, padding_size); - } - - AesBlock128 plaintext = load_aes_block128(padding); - AesBlock128 ciphertext = aes128ecb_encrypt_block(plaintext, key_schedule); - store_aes_block128(ciphertext, dest); - - return dest_size; -} - -size_t aes128ecb_decrypt_buffer( - const unsigned char* src, - size_t src_size, - unsigned char* dest, - Aes128KeySchedule* inverted_schedule) -{ - size_t dest_size = src_size; - - if (dest == NULL) - return dest_size; - - size_t src_len = src_size / 16; - - for (size_t i = 0; i < src_len - 1; ++i, src += 16, dest += 16) - { - AesBlock128 ciphertext = load_aes_block128(src); - AesBlock128 plaintext = aes128ecb_decrypt_block(ciphertext, inverted_schedule); - store_aes_block128(plaintext, dest); - } - - AesBlock128 ciphertext = load_aes_block128(src); - AesBlock128 plaintext = aes128ecb_decrypt_block(ciphertext, inverted_schedule); - unsigned char padding[16]; - store_aes_block128(plaintext, padding); - - if (padding[0] == 0x10) - return dest_size - 16; - - memcpy(dest, padding, 16 - padding[15]); - return dest_size - padding[15]; -} -- cgit v1.2.3