Do not use hardcoded cipher block length when padding.

This commit is contained in:
Guus Sliepen 2009-12-19 23:23:25 +01:00
parent f542ef8f9e
commit 3626165002

View file

@ -196,7 +196,13 @@ bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou
if(!oneshot) if(!oneshot)
return false; return false;
size_t reqlen = ((inlen + 8) / cipher->blklen) * cipher->blklen; size_t reqlen = ((inlen + cipher->blklen) / cipher->blklen) * cipher->blklen;
if(*outlen < reqlen) {
logger(LOG_ERR, "Error while encrypting: not enough room for padding");
return false;
}
uint8_t padbyte = reqlen - inlen; uint8_t padbyte = reqlen - inlen;
inlen = reqlen - cipher->blklen; inlen = reqlen - cipher->blklen;
@ -259,7 +265,8 @@ bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou
} }
*outlen = origlen; *outlen = origlen;
} } else
*outlen = inlen;
return true; return true;
} }