From patchwork Thu Sep 10 10:06:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 249587 Delivered-To: patch@linaro.org Received: by 2002:a17:906:6011:0:0:0:0 with SMTP id o17csp1240028ejj; Thu, 10 Sep 2020 03:09:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNOgtDoFyzMF9Tzhx797VA6fbwWgJUV53KPsLq+qSSTjHgJ1JzDyHKlBZ0JR4xBUq7G5A2 X-Received: by 2002:a25:1f44:: with SMTP id f65mr12133996ybf.438.1599732578657; Thu, 10 Sep 2020 03:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599732578; cv=none; d=google.com; s=arc-20160816; b=yLcWXCu8jnDupsaaAATOoGZxPuhR06pJSyijIxajtkr9Ug0x6+oFUxy/z3lU72sAiM BS2PDH53Nm8U5AP6+y149Kb0iLCSu3dS0695jWAZ67QEVeuIH5/W7K3jho4pxgqTtKTD 6qwzp+xt7HVnAdQ3PsmN6FfqfwDA9S66Wk0EiqN1nHMAsf5IvCRFLv7EvdRMCeKZr9Ma Bi+rToqeT2HMEhjBGCWCVnA1nQ+o6mVl0OpW6C/lhtdgEeDTyqzW71EZ1+2xi5g6F5/G fyyP+TEVEzWdoqorkSoTsTo+R76bsJkDrpTvncUFwKaNVi27P5kBBvooJwrLJI62io5N l4TA== 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=JOk10kb0mszjBp1j55p7ooi4MUv5zXNABmQ7poAPUnQ=; b=Qi8hq36T8YjTUjoGAyo56Y30GXfLWmjFJMc4zu3O4smv83eIl+IZEcaHSN/HTf9Doo WVkKgNx5YgYAoHrkNEjjjmfy2IPoCNi0wXE57vqZo4/ISSvjc5FPVZdgY3tZN+FVEv84 7trmytHcnH0sP8QTUm81TQM8wBguomlgb/qBGIVNPCyTz48knfOZVBniHGHG2jYf22CG x5PMkXbWMU1u34sk+48y9++A/i27ANh9CbRMpaqm6FKe3TuKtPHOthFORllHqQx2ESzJ PZANqBExQvixH3ZZvKhXrRexeu3IVyvAR296TF9hU27hVxpMVi/fOK6vdZz7FWYZsqth oKCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=GI4iMYKU; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k14si5622380ybk.363.2020.09.10.03.09.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Sep 2020 03:09:38 -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=fail header.i=@redhat.com header.s=mimecast20190719 header.b=GI4iMYKU; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:58816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGJWM-0006wp-12 for patch@linaro.org; Thu, 10 Sep 2020 06:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGJTZ-0000QF-BH for qemu-devel@nongnu.org; Thu, 10 Sep 2020 06:06:46 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44663 helo=us-smtp-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 1kGJTX-0007i0-4J for qemu-devel@nongnu.org; Thu, 10 Sep 2020 06:06:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599732402; 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=JOk10kb0mszjBp1j55p7ooi4MUv5zXNABmQ7poAPUnQ=; b=GI4iMYKUIZrSvVA5iO75F17cTkMqT8GDZk0kS8VfEh1TvVH5IWCSPtPpCqBLDJ2MfJP9bW tLB7gKRnPp3B3Ikdykv+Vw8AGT0FxirBQ84/s1RFQYLOUsGZsknr97X8u0ZH7Jqk+YN6HW kzmZN+XJhyBAs6kexQZr58ys8dDOFS8= 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-35-SoqMgi60N1WDPZXCipCFEg-1; Thu, 10 Sep 2020 06:06:39 -0400 X-MC-Unique: SoqMgi60N1WDPZXCipCFEg-1 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 969D11009443; Thu, 10 Sep 2020 10:06:38 +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 8AB271002D41; Thu, 10 Sep 2020 10:06:37 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 09/17] crypto: Move cipher->driver init to qcrypto_*_cipher_ctx_new Date: Thu, 10 Sep 2020 11:06:15 +0100 Message-Id: <20200910100623.1088965-10-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 Received-SPF: pass client-ip=207.211.31.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/10 03:02:23 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_P?= =?utf-8?b?LiBCZXJyYW5nw6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The class vtable should be set by the class initializer. This will also allow additional subclassing, reducing the amount of indirection in the hierarchy. Signed-off-by: Richard Henderson Signed-off-by: Daniel P. Berrangé --- crypto/cipher-afalg.c | 5 ++++- crypto/cipher-builtin.c.inc | 4 ++++ crypto/cipher-gcrypt.c.inc | 2 ++ crypto/cipher-nettle.c.inc | 3 +++ crypto/cipher.c | 7 ------- crypto/cipherpriv.h | 2 -- 6 files changed, 13 insertions(+), 10 deletions(-) -- 2.26.2 diff --git a/crypto/cipher-afalg.c b/crypto/cipher-afalg.c index 86e5249bd6..052355a8a9 100644 --- a/crypto/cipher-afalg.c +++ b/crypto/cipher-afalg.c @@ -58,6 +58,8 @@ qcrypto_afalg_cipher_format_name(QCryptoCipherAlgorithm alg, return name; } +static const struct QCryptoCipherDriver qcrypto_cipher_afalg_driver; + QCryptoCipher * qcrypto_afalg_cipher_ctx_new(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode, @@ -109,6 +111,7 @@ qcrypto_afalg_cipher_ctx_new(QCryptoCipherAlgorithm alg, } afalg->cmsg = CMSG_FIRSTHDR(afalg->msg); + afalg->base.driver = &qcrypto_cipher_afalg_driver; return &afalg->base; } @@ -222,7 +225,7 @@ static void qcrypto_afalg_comm_ctx_free(QCryptoCipher *cipher) qcrypto_afalg_comm_free(afalg); } -const struct QCryptoCipherDriver qcrypto_cipher_afalg_driver = { +static const struct QCryptoCipherDriver qcrypto_cipher_afalg_driver = { .cipher_encrypt = qcrypto_afalg_cipher_encrypt, .cipher_decrypt = qcrypto_afalg_cipher_decrypt, .cipher_setiv = qcrypto_afalg_cipher_setiv, diff --git a/crypto/cipher-builtin.c.inc b/crypto/cipher-builtin.c.inc index 6a03e23040..1444139f36 100644 --- a/crypto/cipher-builtin.c.inc +++ b/crypto/cipher-builtin.c.inc @@ -22,6 +22,8 @@ #include "crypto/desrfb.h" #include "crypto/xts.h" +static const struct QCryptoCipherDriver qcrypto_cipher_lib_driver; + typedef struct QCryptoCipherBuiltinAESContext QCryptoCipherBuiltinAESContext; struct QCryptoCipherBuiltinAESContext { AES_KEY enc; @@ -292,6 +294,7 @@ qcrypto_cipher_init_aes(QCryptoCipherMode mode, ctxt->encrypt = qcrypto_cipher_encrypt_aes; ctxt->decrypt = qcrypto_cipher_decrypt_aes; + ctxt->base.driver = &qcrypto_cipher_lib_driver; return &ctxt->base; error: @@ -396,6 +399,7 @@ qcrypto_cipher_init_des_rfb(QCryptoCipherMode mode, ctxt->encrypt = qcrypto_cipher_encrypt_des_rfb; ctxt->decrypt = qcrypto_cipher_decrypt_des_rfb; + ctxt->base.driver = &qcrypto_cipher_lib_driver; return &ctxt->base; } diff --git a/crypto/cipher-gcrypt.c.inc b/crypto/cipher-gcrypt.c.inc index 3b3c85e265..7a1fbc9745 100644 --- a/crypto/cipher-gcrypt.c.inc +++ b/crypto/cipher-gcrypt.c.inc @@ -24,6 +24,7 @@ #include +static const struct QCryptoCipherDriver qcrypto_cipher_lib_driver; bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) @@ -258,6 +259,7 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, } #endif + ctx->base.driver = &qcrypto_cipher_lib_driver; return &ctx->base; error: diff --git a/crypto/cipher-nettle.c.inc b/crypto/cipher-nettle.c.inc index d8371d1f37..36d57ef430 100644 --- a/crypto/cipher-nettle.c.inc +++ b/crypto/cipher-nettle.c.inc @@ -34,6 +34,8 @@ #include #endif +static const struct QCryptoCipherDriver qcrypto_cipher_lib_driver; + typedef void (*QCryptoCipherNettleFuncWrapper)(const void *ctx, size_t length, uint8_t *dst, @@ -587,6 +589,7 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, ctx->iv = g_new0(uint8_t, ctx->blocksize); + ctx->base.driver = &qcrypto_cipher_lib_driver; return &ctx->base; error: diff --git a/crypto/cipher.c b/crypto/cipher.c index 737fc0735d..3711b552fa 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -164,13 +164,9 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, Error **errp) { QCryptoCipher *cipher = NULL; - const QCryptoCipherDriver *drv = NULL; #ifdef CONFIG_AF_ALG cipher = qcrypto_afalg_cipher_ctx_new(alg, mode, key, nkey, NULL); - if (cipher) { - drv = &qcrypto_cipher_afalg_driver; - } #endif if (!cipher) { @@ -178,13 +174,10 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, if (!cipher) { return NULL; } - - drv = &qcrypto_cipher_lib_driver; } cipher->alg = alg; cipher->mode = mode; - cipher->driver = drv; return cipher; } diff --git a/crypto/cipherpriv.h b/crypto/cipherpriv.h index 437b109b5e..396527857d 100644 --- a/crypto/cipherpriv.h +++ b/crypto/cipherpriv.h @@ -47,8 +47,6 @@ qcrypto_afalg_cipher_ctx_new(QCryptoCipherAlgorithm alg, const uint8_t *key, size_t nkey, Error **errp); -extern const struct QCryptoCipherDriver qcrypto_cipher_afalg_driver; - #endif #endif