From nobody Mon Feb 9 05:40:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599732844; cv=none; d=zohomail.com; s=zohoarc; b=ZOvGWt/aqI6B+l5DTWq26rAxqHEOIBNF+n9eIhjpbhpjvqU9NxC0ZZaHzlGXw6vw5qFjsyZnWUuuZ8/k6pHCzu6VMOECYlb3795rbj7CCw8u9DYeykuISRhLPFTt1sTALZ/QaDy0EEfNp/4Hd2I2qYYl7Cz/4bHi/LBzFccwvLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599732844; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z5kz+dl4NiZGR3DyQwvuH4nV2SaU5K6TRvwu9idGUNw=; b=e2uvwR639HML2qTCFBZSzdZxm3vAmz9XxgdvYZR3TliVbwb4wcTNtmbWN2c5gVbecKhC3VDef2wZBPZbcR39keJBotp3laVgxDok3pEiSzYKz03R67IDgqL2Rey4FPbQ9opzbhUEYjC01miivrpWWEgViis1dAzMlwqR6d7QrZ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599732844074182.7726299703504; Thu, 10 Sep 2020 03:14:04 -0700 (PDT) Received: from localhost ([::1]:49274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGJac-0006KM-Lh for importer@patchew.org; Thu, 10 Sep 2020 06:14:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGJTf-0000Wi-PZ for qemu-devel@nongnu.org; Thu, 10 Sep 2020 06:06:51 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:21140 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kGJTd-0007j0-5L for qemu-devel@nongnu.org; Thu, 10 Sep 2020 06:06:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-icB0_c8eMwesHJwalp4Ajg-1; Thu, 10 Sep 2020 06:06:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C96E6801AB8; Thu, 10 Sep 2020 10:06:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BC1F1002D5C; Thu, 10 Sep 2020 10:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599732408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z5kz+dl4NiZGR3DyQwvuH4nV2SaU5K6TRvwu9idGUNw=; b=fd4wcEASKQ4MI22OK3oNTIrEHi2rsLYOmcOMAEA5iQZWHlr+MVRZcNsLw7hrDefttw9YfY qsDQpkeXeYUKyxFwsjiXmr+aJ8nMvxJXyvIwPJvPqjs8FeVuhl3ACCm6vrfi92B3gV6xNZ cjRwEQeIKQdUK5e2N4ddCtZBLNTjl7w= X-MC-Unique: icB0_c8eMwesHJwalp4Ajg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 13/17] crypto/builtin: Move AES_cbc_encrypt into cipher-builtin.inc.c Date: Thu, 10 Sep 2020 11:06:19 +0100 Message-Id: <20200910100623.1088965-14-berrange@redhat.com> In-Reply-To: <20200910100623.1088965-1-berrange@redhat.com> References: <20200910100623.1088965-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/10 00:49:43 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: Richard Henderson , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Richard Henderson By making the function private, we will be able to make further simplifications. Re-indent the migrated code and fix the missing braces for CODING_STYLE. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/aes.c | 51 --------------------------------- crypto/cipher-builtin.c.inc | 56 +++++++++++++++++++++++++++++++++++++ include/crypto/aes.h | 4 --- 3 files changed, 56 insertions(+), 55 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 0f6a195af8..159800df65 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1599,54 +1599,3 @@ void AES_decrypt(const unsigned char *in, unsigned c= har *out, } =20 #endif /* AES_ASM */ - -void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, - unsigned char *ivec, const int enc) -{ - - unsigned long n; - unsigned long len =3D length; - unsigned char tmp[AES_BLOCK_SIZE]; - - assert(in && out && key && ivec); - - if (enc) { - while (len >=3D AES_BLOCK_SIZE) { - for(n=3D0; n < AES_BLOCK_SIZE; ++n) - tmp[n] =3D in[n] ^ ivec[n]; - AES_encrypt(tmp, out, key); - memcpy(ivec, out, AES_BLOCK_SIZE); - len -=3D AES_BLOCK_SIZE; - in +=3D AES_BLOCK_SIZE; - out +=3D AES_BLOCK_SIZE; - } - if (len) { - for(n=3D0; n < len; ++n) - tmp[n] =3D in[n] ^ ivec[n]; - for(n=3Dlen; n < AES_BLOCK_SIZE; ++n) - tmp[n] =3D ivec[n]; - AES_encrypt(tmp, tmp, key); - memcpy(out, tmp, AES_BLOCK_SIZE); - memcpy(ivec, tmp, AES_BLOCK_SIZE); - } - } else { - while (len >=3D AES_BLOCK_SIZE) { - memcpy(tmp, in, AES_BLOCK_SIZE); - AES_decrypt(in, out, key); - for(n=3D0; n < AES_BLOCK_SIZE; ++n) - out[n] ^=3D ivec[n]; - memcpy(ivec, tmp, AES_BLOCK_SIZE); - len -=3D AES_BLOCK_SIZE; - in +=3D AES_BLOCK_SIZE; - out +=3D AES_BLOCK_SIZE; - } - if (len) { - memcpy(tmp, in, AES_BLOCK_SIZE); - AES_decrypt(tmp, tmp, key); - for(n=3D0; n < len; ++n) - out[n] =3D tmp[n] ^ ivec[n]; - memcpy(ivec, tmp, AES_BLOCK_SIZE); - } - } -} diff --git a/crypto/cipher-builtin.c.inc b/crypto/cipher-builtin.c.inc index 8e21f2673f..61baad265a 100644 --- a/crypto/cipher-builtin.c.inc +++ b/crypto/cipher-builtin.c.inc @@ -104,6 +104,62 @@ static void do_aes_decrypt_ecb(const void *vctx, } } =20 +static void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, + const unsigned long length, const AES_KEY *key, + unsigned char *ivec, const int enc) +{ + unsigned long n; + unsigned long len =3D length; + unsigned char tmp[AES_BLOCK_SIZE]; + + assert(in && out && key && ivec); + + if (enc) { + while (len >=3D AES_BLOCK_SIZE) { + for (n =3D 0; n < AES_BLOCK_SIZE; ++n) { + tmp[n] =3D in[n] ^ ivec[n]; + } + AES_encrypt(tmp, out, key); + memcpy(ivec, out, AES_BLOCK_SIZE); + len -=3D AES_BLOCK_SIZE; + in +=3D AES_BLOCK_SIZE; + out +=3D AES_BLOCK_SIZE; + } + if (len) { + for (n =3D 0; n < len; ++n) { + tmp[n] =3D in[n] ^ ivec[n]; + } + for (n =3D len; n < AES_BLOCK_SIZE; ++n) { + tmp[n] =3D ivec[n]; + } + AES_encrypt(tmp, tmp, key); + memcpy(out, tmp, AES_BLOCK_SIZE); + memcpy(ivec, tmp, AES_BLOCK_SIZE); + } + } else { + while (len >=3D AES_BLOCK_SIZE) { + memcpy(tmp, in, AES_BLOCK_SIZE); + AES_decrypt(in, out, key); + for (n =3D 0; n < AES_BLOCK_SIZE; ++n) { + out[n] ^=3D ivec[n]; + } + memcpy(ivec, tmp, AES_BLOCK_SIZE); + len -=3D AES_BLOCK_SIZE; + in +=3D AES_BLOCK_SIZE; + out +=3D AES_BLOCK_SIZE; + } + if (len) { + memcpy(tmp, in, AES_BLOCK_SIZE); + AES_decrypt(tmp, tmp, key); + for (n =3D 0; n < len; ++n) { + out[n] =3D tmp[n] ^ ivec[n]; + } + memcpy(ivec, tmp, AES_BLOCK_SIZE); + } + } +} + + static int qcrypto_cipher_encrypt_aes(QCryptoCipher *cipher, const void *in, void *out, diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 12fb321b89..ba297d6a73 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -16,7 +16,6 @@ typedef struct aes_key_st AES_KEY; #define AES_set_decrypt_key QEMU_AES_set_decrypt_key #define AES_encrypt QEMU_AES_encrypt #define AES_decrypt QEMU_AES_decrypt -#define AES_cbc_encrypt QEMU_AES_cbc_encrypt =20 int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); @@ -27,9 +26,6 @@ void AES_encrypt(const unsigned char *in, unsigned char *= out, const AES_KEY *key); void AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key); -void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, - unsigned char *ivec, const int enc); =20 extern const uint8_t AES_sbox[256]; extern const uint8_t AES_isbox[256]; --=20 2.26.2