Simplify padding and update comments
@@ -100,8 +100,9 @@ impl AesCounterModeService {
.map_err(|_| ErrNo::Canceled)?;
let block_size = cypher.block_size();
- // Mbed TLS requires the output buffer to be at least `ilen + block_size` long
- let padded_size = (input.len() + 2 * block_size - 1) / block_size * block_size;
+ // Mbed TLS requires the output buffer to be at least `ilen + block_size` long.
+ // Cf. the documentation of `mbedtls_cipher_update()`
+ let padded_size = input.len() + block_size;
output.resize(padded_size, 0);
cypher
@@ -118,8 +119,9 @@ impl AesCounterModeService {
.map_err(|_| ErrNo::Canceled)?;
let block_size = cypher.block_size();
- // Mbed TLS requires the output buffer to be at least `ilen + block_size` long
- let padded_size = (input.len() + 2 * block_size - 1) / block_size * block_size;
+ // Mbed TLS requires the output buffer to be at least `ilen + block_size` long.
+ // Cf. the documentation of `mbedtls_cipher_update()`
+ let padded_size = input.len() + block_size;
output.resize(padded_size, 0);
cypher
