{
QCryptoCipherBuiltin *ctxt = cipher->opaque;
- if (len % ctxt->blocksize) {
+ if (len & (ctxt->blocksize - 1)) {
error_setg(errp, "Length %zu must be a multiple of block size %zu",
len, ctxt->blocksize);
return -1;
{
QCryptoCipherBuiltin *ctxt = cipher->opaque;
- if (len % ctxt->blocksize) {
+ if (len & (ctxt->blocksize - 1)) {
error_setg(errp, "Length %zu must be a multiple of block size %zu",
len, ctxt->blocksize);
return -1;
g_assert_not_reached();
}
}
+ g_assert(is_power_of_2(ctx->blocksize));
#ifdef CONFIG_QEMU_PRIVATE_XTS
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
QCryptoCipherGcrypt *ctx = cipher->opaque;
gcry_error_t err;
- if (len % ctx->blocksize) {
+ if (len & (ctx->blocksize - 1)) {
error_setg(errp, "Length %zu must be a multiple of block size %zu",
len, ctx->blocksize);
return -1;
QCryptoCipherGcrypt *ctx = cipher->opaque;
gcry_error_t err;
- if (len % ctx->blocksize) {
+ if (len & (ctx->blocksize - 1)) {
error_setg(errp, "Length %zu must be a multiple of block size %zu",
len, ctx->blocksize);
return -1;
QCryptoCipherAlgorithm_str(alg));
goto error;
}
+ g_assert(is_power_of_2(ctx->blocksize));
if (mode == QCRYPTO_CIPHER_MODE_XTS &&
ctx->blocksize != XTS_BLOCK_SIZE) {
{
QCryptoCipherNettle *ctx = cipher->opaque;
- if (len % ctx->blocksize) {
+ if (len & (ctx->blocksize - 1)) {
error_setg(errp, "Length %zu must be a multiple of block size %zu",
len, ctx->blocksize);
return -1;
{
QCryptoCipherNettle *ctx = cipher->opaque;
- if (len % ctx->blocksize) {
+ if (len & (ctx->blocksize - 1)) {
error_setg(errp, "Length %zu must be a multiple of block size %zu",
len, ctx->blocksize);
return -1;
*/
#include "qemu/osdep.h"
+#include "qemu/host-utils.h"
#include "qapi/error.h"
#include "crypto/cipher.h"
#include "cipherpriv.h"