diff --git a/lib/cipher_funcs.c b/lib/cipher_funcs.c index 560471e5..0a0ce3b5 100644 --- a/lib/cipher_funcs.c +++ b/lib/cipher_funcs.c @@ -249,8 +249,8 @@ rij_decrypt(unsigned char *in, size_t in_len, /* Remove the first block since it contains the salt (it was consumed * by the rijndael_init() function above). */ - in_len -= 16; - memmove(in, in+16, in_len); + in_len -= RIJNDAEL_BLOCKSIZE; + memmove(in, in+RIJNDAEL_BLOCKSIZE, in_len); block_decrypt(&ctx, in, in_len, out, ctx.iv); diff --git a/lib/fko_encryption.c b/lib/fko_encryption.c index 5f1788a0..af43a870 100644 --- a/lib/fko_encryption.c +++ b/lib/fko_encryption.c @@ -139,6 +139,15 @@ _rijndael_decrypt(fko_ctx_t ctx, const char *dec_key, int encryption_mode) cipher_len = b64_decode(ctx->encrypted_msg, cipher); + /* Since we're using AES, make sure the incoming data is a multiple of + * the blocksize + */ + if((cipher_len % RIJNDAEL_BLOCKSIZE) != 0) + { + free(cipher); + return(FKO_ERROR_INVALID_DATA); + } + /* Create a bucket for the plaintext data and decrypt the message * data into it. */