@@ -85,10 +85,11 @@ apr_status_t SEAL_KEY_CREATE(apr_pool_t *p, struct seal_key **skey,
8585apr_status_t SEAL_BUFFER (apr_pool_t * p , struct seal_key * skey ,
8686 struct databuf * plain , struct databuf * cipher )
8787{
88+ int blksz = skey -> cipher -> block_size ;
8889 apr_status_t err = EFAULT ;
8990 EVP_CIPHER_CTX ctx = { 0 };
9091 HMAC_CTX hmac_ctx = { 0 };
91- uint8_t rbuf [16 ];
92+ uint8_t rbuf [blksz ];
9293 unsigned int len ;
9394 int outlen , totlen ;
9495 int ret ;
@@ -97,12 +98,12 @@ apr_status_t SEAL_BUFFER(apr_pool_t *p, struct seal_key *skey,
9798
9899 /* confounder to avoid exposing random numbers directly to clients
99100 * as IVs */
100- ret = RAND_bytes (rbuf , 16 );
101+ ret = RAND_bytes (rbuf , sizeof ( rbuf ) );
101102 if (ret == 0 ) goto done ;
102103
103104 if (cipher -> length == 0 ) {
104105 /* add space for confounder and padding and MAC */
105- cipher -> length = (plain -> length / 16 + 2 ) * 16 ;
106+ cipher -> length = (plain -> length / blksz + 2 ) * blksz ;
106107 cipher -> value = apr_palloc (p , cipher -> length + skey -> md -> md_size );
107108 if (!cipher -> value ) {
108109 err = ENOMEM ;
@@ -115,7 +116,7 @@ apr_status_t SEAL_BUFFER(apr_pool_t *p, struct seal_key *skey,
115116 totlen = 0 ;
116117
117118 outlen = cipher -> length ;
118- ret = EVP_EncryptUpdate (& ctx , cipher -> value , & outlen , rbuf , 16 );
119+ ret = EVP_EncryptUpdate (& ctx , cipher -> value , & outlen , rbuf , sizeof ( rbuf ) );
119120 if (ret == 0 ) goto done ;
120121 totlen += outlen ;
121122
@@ -214,8 +215,8 @@ apr_status_t UNSEAL_BUFFER(apr_pool_t *p, struct seal_key *skey,
214215
215216 totlen += outlen ;
216217 /* now remove the confounder */
217- totlen -= 16 ;
218- memmove (plain -> value , plain -> value + 16 , totlen );
218+ totlen -= skey -> cipher -> block_size ;
219+ memmove (plain -> value , plain -> value + skey -> cipher -> block_size , totlen );
219220
220221 plain -> length = totlen ;
221222 err = 0 ;
0 commit comments