aboutsummaryrefslogtreecommitdiff
path: root/crypto/cipher-builtin.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2020-08-28 10:05:08 -0700
committerDaniel P. Berrangé <berrange@redhat.com>2020-09-10 11:02:23 +0100
commiteba29771c006d6a689e946fa57334a2ce370c45c (patch)
treeb2a2a6559e18f89dabbea68cc124875956b7a37d /crypto/cipher-builtin.c
parentca04c3cf15961e4a01c729a24b00bf804f59ac23 (diff)
crypto: Assume blocksize is a power of 2
The check in the encode/decode path using full division has a noticeable amount of overhead. By asserting the blocksize is a power of 2, we can reduce this check to a mask. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'crypto/cipher-builtin.c')
-rw-r--r--crypto/cipher-builtin.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/crypto/cipher-builtin.c b/crypto/cipher-builtin.c
index 35cf7820d9..6eafd39da0 100644
--- a/crypto/cipher-builtin.c
+++ b/crypto/cipher-builtin.c
@@ -484,7 +484,7 @@ qcrypto_builtin_cipher_encrypt(QCryptoCipher *cipher,
{
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;
@@ -503,7 +503,7 @@ qcrypto_builtin_cipher_decrypt(QCryptoCipher *cipher,
{
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;