get padding size right

This commit is contained in:
Love Hornquist Astrand
2010-09-30 00:20:52 -07:00
parent 42727fc891
commit 6699b5e59a

View File

@@ -2488,7 +2488,7 @@ hx509_crypto_encrypt(hx509_crypto crypto,
heim_octet_string **ciphertext) heim_octet_string **ciphertext)
{ {
EVP_CIPHER_CTX evp; EVP_CIPHER_CTX evp;
size_t padsize; size_t padsize, bsize;
int ret; int ret;
*ciphertext = NULL; *ciphertext = NULL;
@@ -2516,15 +2516,17 @@ hx509_crypto_encrypt(hx509_crypto crypto,
} }
assert(crypto->flags & PADDING_FLAGS); assert(crypto->flags & PADDING_FLAGS);
if (crypto->flags & PADDING_NONE) {
bsize = EVP_CIPHER_block_size(crypto->c);
padsize = 0; padsize = 0;
if (crypto->flags & PADDING_NONE) {
if (bsize != 1 && (length % bsize) != 0)
return HX509_CMS_PADDING_ERROR;
} else if (crypto->flags & PADDING_PKCS7) { } else if (crypto->flags & PADDING_PKCS7) {
if (EVP_CIPHER_block_size(crypto->c) == 1) { if (bsize != 1)
} else {
int bsize = EVP_CIPHER_block_size(crypto->c);
padsize = bsize - (length % bsize); padsize = bsize - (length % bsize);
} }
}
(*ciphertext)->length = length + padsize; (*ciphertext)->length = length + padsize;
(*ciphertext)->data = malloc(length + padsize); (*ciphertext)->data = malloc(length + padsize);