diff options
Diffstat (limited to 'lib/lib2.c')
| -rw-r--r-- | lib/lib2.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -1,4 +1,5 @@ #include "lib2.h" +#include "lib.h" /** * appends PKCS#7 padding to string. devide string in blocks of size blocksize @@ -21,3 +22,41 @@ char *pkcs7_padding(char *string, int length_string, int blocksize) return result; } + +/** + * decrypts content which is encrypted in AES CBC mode + * @param in input content + * @param length_in length of parametere in + * @param out place where the decrypted content should be written to + * @param string_key key with which the content in in has been decrypted + * @param iv initalization vector + */ +int aes_cbc(char *in, int length_in, char *out, unsigned char *string_key, char *init_vector) +{ + char iv[16]; + AES_KEY key; + int number_blocks = length_in / 16; + int i, j; + unsigned char ciphertext[128+1]; + unsigned char tmp_after_aes[128+1]; + unsigned char cleartext[128+1]; + // set the key and bits + AES_set_decrypt_key(string_key, 128, &key); + + memcpy(init_vector, iv, 16); + + // implement cbc mode + for(i=0;i<number_blocks;i++) { + //do aes decryption + AES_decrypt(&in[i*16], tmp_after_aes, &key); + // xor + xor_string(iv, tmp_after_aes, &out[i*16], 16, 16); + // this ciphertext block is the next iv + for(j=0;j<16;j++) { + iv[j] = in[i*16+j]; + } + } + + return 0; + +} |
