From patchwork Thu Aug 13 03:25:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 247657 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp927195ilo; Wed, 12 Aug 2020 20:30:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDLQV+lCaJ2B6t6fi6z5ZGIUt2IxJ/K0p6OjBy8qkIAmYqJpB7vEtpBvkfiOGY4FIUyFpX X-Received: by 2002:a25:7401:: with SMTP id p1mr3577209ybc.10.1597289453323; Wed, 12 Aug 2020 20:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597289453; cv=none; d=google.com; s=arc-20160816; b=bfV3Rw4DDO/vcIbgdDd1lirlcf1Pjsd7M8z7HXUQZDgc9jiVWgbL66AJh0tt40Fr7Y gXhewv1ipz2Fy0de6Mc9Z4RXr+LukwW/XjhIiIWPaAxiVduB+R0db9oULOs0lAJ//jyT UA9Ti/J7nf4XsT6oH7k6mS/lrl5uG3W6UStUmQFEIhSpFK0ym+GFNC1vTsJkiOewbR9c j8gHJtCP32jD4eL/k1FVvBDquQYjWrS6vlmEKFIBTVhPaaBLclpAlpM7RmUu6DGlMQIe XAT6tvQ3XNtr3kWDS5/WqaXCGS1F8GTXrnllwUrnjKqYT2uxwBPCztap+pdqAzju/yk3 1Zhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=TcYIyipPkI2d2aP17J0suGRqHmTuPSrIckZvWVvyskc=; b=JZqHp1Fz1ROuzw5ZHF15gkd65RSH6yCfuBC84nEczPusn5zYTYQk+WO6p8jUGbMUAW uSy/ZE8mONACvcbd0SJJrtEehItH3WqxaJSyMHPEE70sFEK00ZXFTClMlkbkwcOdAUF8 yX4IVWyjJVC0zmKxDs1Yqj8HYH0lJUxgONM8/b8/b2j1LOXylvA9EbroIZqdBdGlMFqk EQhn6+yM0Hg1EXemMgIO9TNiSvsQXX4pMrCHl+nO+PHrAu1DRY9vvUE9kekiwSD7vT8A btC8+eCROvXRtAVFY3z14ZSdHFm9l3TpMzVPK5B+43vwaXVIjyN9S4cbRJdpZt5BqwyC rKvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MGTeMRER; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d186si4414017ybd.129.2020.08.12.20.30.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Aug 2020 20:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MGTeMRER; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k63x6-0003g2-NY for patch@linaro.org; Wed, 12 Aug 2020 23:30:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k63sM-00058r-89 for qemu-devel@nongnu.org; Wed, 12 Aug 2020 23:25:58 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:33948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k63sK-00009k-4j for qemu-devel@nongnu.org; Wed, 12 Aug 2020 23:25:57 -0400 Received: by mail-pf1-x443.google.com with SMTP id m71so2107851pfd.1 for ; Wed, 12 Aug 2020 20:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TcYIyipPkI2d2aP17J0suGRqHmTuPSrIckZvWVvyskc=; b=MGTeMRERtIQu9/aSHMjQ9sttR+a5b/lKB9WXQLADMrjS6iq6xqMNdKLKpc3J8VOQ+m xueKzzFSn4K8sKnqvez2Fw4b1yo5NqPO77SDeUdtrRQSvHeLDyxiBblEb4CAk8usWPnW Xil7Tv/7X5qJgnTkR0RxPRE4qXQALVp3VHXdEUHTGOthy4qdfKjVx2Tsa40Dt5Z1nAjJ ODx1H28xy44x0VeP6odFCMYLjQwU9lzB1qJFwa0Zu2FMPZZDAHGdTTPRwlIc/qwzmYir bB0DekBSJ2XMfbDodxAJCnpzZcVNTV3eunIVREKlB+H6AXDmYW8kHIbUwddr/ZIs2oiM KE3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TcYIyipPkI2d2aP17J0suGRqHmTuPSrIckZvWVvyskc=; b=qQlQ6BDURlXKlThAcXDeQqzJG8CU/3QenKTE/WpNswUruxbYAo44VFajI+Akf42nTM OJ8V2JtNNjMxaNUKofJ2D7xi/4/ZieOKPRzNXX+9jdzu/jsiOvkg1Ejq9nnXT/OKlllA YiAMfAxoYcQ9QlSIDxxvEDjwp0P91uu2qzdWxdfATmUeT/lk978A2zhoD2PYfiPYQlj6 qi5b9r0rvOiTr3i0JJ3SRt00oeZwiP8uKGhP8H+vocRRznzXcT6qsDGj86IfL9huNCNV +i0/9fhR5yxEY5h5ehyizwzzHzew6UmUvHvCrQ6O/xUHSxkwdV8vQT73C1Q3Okh9E6yB /WsQ== X-Gm-Message-State: AOAM533nb7ap6rMzFA8JHscBHqu3/3Q1DnvLimnqP25Wm1zDgliCTLmh x4rjkYBDNKmVr2F5spIyH+pt0kTraKU= X-Received: by 2002:aa7:9904:: with SMTP id z4mr2435215pff.32.1597289154407; Wed, 12 Aug 2020 20:25:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id m19sm3633164pgd.21.2020.08.12.20.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 20:25:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 11/17] crypto/builtin: Remove odd-sized AES block handling Date: Wed, 12 Aug 2020 20:25:31 -0700 Message-Id: <20200813032537.2888593-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200813032537.2888593-1-richard.henderson@linaro.org> References: <20200813032537.2888593-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We verified that the data block is properly sized modulo AES_BLOCK_SIZE within qcrypto_builtin_cipher_{en,de}crypt. Therefore we will never have to handle odd sized blocks. Signed-off-by: Richard Henderson --- crypto/cipher-builtin.inc.c | 40 +++++++++++-------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) -- 2.25.1 Reviewed-by: Daniel P. Berrangé diff --git a/crypto/cipher-builtin.inc.c b/crypto/cipher-builtin.inc.c index 1444139f36..e2ae5d090c 100644 --- a/crypto/cipher-builtin.inc.c +++ b/crypto/cipher-builtin.inc.c @@ -80,21 +80,13 @@ static void qcrypto_cipher_aes_ecb_encrypt(const AES_KEY *key, { const uint8_t *inptr = in; uint8_t *outptr = out; + + /* We have already verified that len % AES_BLOCK_SIZE == 0. */ while (len) { - if (len > AES_BLOCK_SIZE) { - AES_encrypt(inptr, outptr, key); - inptr += AES_BLOCK_SIZE; - outptr += AES_BLOCK_SIZE; - len -= AES_BLOCK_SIZE; - } else { - uint8_t tmp1[AES_BLOCK_SIZE], tmp2[AES_BLOCK_SIZE]; - memcpy(tmp1, inptr, len); - /* Fill with 0 to avoid valgrind uninitialized reads */ - memset(tmp1 + len, 0, sizeof(tmp1) - len); - AES_encrypt(tmp1, tmp2, key); - memcpy(outptr, tmp2, len); - len = 0; - } + AES_encrypt(inptr, outptr, key); + inptr += AES_BLOCK_SIZE; + outptr += AES_BLOCK_SIZE; + len -= AES_BLOCK_SIZE; } } @@ -106,21 +98,13 @@ static void qcrypto_cipher_aes_ecb_decrypt(const AES_KEY *key, { const uint8_t *inptr = in; uint8_t *outptr = out; + + /* We have already verified that len % AES_BLOCK_SIZE == 0. */ while (len) { - if (len > AES_BLOCK_SIZE) { - AES_decrypt(inptr, outptr, key); - inptr += AES_BLOCK_SIZE; - outptr += AES_BLOCK_SIZE; - len -= AES_BLOCK_SIZE; - } else { - uint8_t tmp1[AES_BLOCK_SIZE], tmp2[AES_BLOCK_SIZE]; - memcpy(tmp1, inptr, len); - /* Fill with 0 to avoid valgrind uninitialized reads */ - memset(tmp1 + len, 0, sizeof(tmp1) - len); - AES_decrypt(tmp1, tmp2, key); - memcpy(outptr, tmp2, len); - len = 0; - } + AES_decrypt(inptr, outptr, key); + inptr += AES_BLOCK_SIZE; + outptr += AES_BLOCK_SIZE; + len -= AES_BLOCK_SIZE; } }