From patchwork Thu Aug 13 03:25:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 247654 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp925909ilo; Wed, 12 Aug 2020 20:28:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSMvie3ZHsjyv5vBXFMJWN9OMBCV5npQxk7iDZjhRoIyylvdFVGuMiHigk9QAB+yLNsrvo X-Received: by 2002:a25:3556:: with SMTP id c83mr3815452yba.412.1597289305853; Wed, 12 Aug 2020 20:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597289305; cv=none; d=google.com; s=arc-20160816; b=Ku0zvlCRaSw4EV9NeE3RmfBPTFgOFIPqzHQrKUPaZ8Wy3hQxhaHCuTFYiuy5JgIqiD N8BjlVtx2g4NNFS0Jc6eOweM0ULQTi7gPRkUA7luzKq2Ot74XLF8bUv9rYseFKCmLWzS frpBEXBK6dcenfdaWVBEkdzGLIx6YYpTtky+gv9dk3/RmqOVWK+M4U8fivxcW8ZwNA6R NgecihQn57weaM8DUU5lEjog54sj9vGHL6AE/vKhlshuWSah3D6bWSsRS9lVma1WwsJi 2nL8J8BZoDkQgM1B9XF/DZOKDGXkOuOMqG97xg4TRKlKJJRXZ4keGikHJ+vUYpXtO2J1 2ApQ== 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=nOP/WB4f5EOc+9iMNgr1GvARoRc8y3IjDCJ8RShT+rk=; b=IaKTsen7CPnEwii3xIQe0f5mkq14ENEkJohLLDKySOD8UUVPrhhdPFEcXuD/t9nu6M cxfb21QrGGhEJYrNTmE1iwpHJuhiy8itgb/mRUJpp9Z+PzfAaxtMPhffaFNuMPfzTVVX 5q7OFdcRZvNeCbBhahcEgEfeQqpM+8wuA3z/NTH0jMZ5b9LgXgD5uaLaYrtEjwUC7TsP GLKCQkrFHBFrvVjF7+/xrN/bvXPztQ5WI+lFWJZDLbT/C+8415NAns0s2uonIR0OOVB4 e9ypXobS9i/n2T8x6R93C1mv6rlWmIm27njqaSiA5KVez6k+UwNIMgiP7rN+YtMIje7I KM/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZU27wAbV; 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 h128si3690237ybg.387.2020.08.12.20.28.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Aug 2020 20:28:25 -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=ZU27wAbV; 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]:55714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k63uj-00013O-8p for patch@linaro.org; Wed, 12 Aug 2020 23:28:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k63sJ-00053P-SV for qemu-devel@nongnu.org; Wed, 12 Aug 2020 23:25:55 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:50822) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k63sI-00009X-0D for qemu-devel@nongnu.org; Wed, 12 Aug 2020 23:25:55 -0400 Received: by mail-pj1-x102f.google.com with SMTP id e4so2119511pjd.0 for ; Wed, 12 Aug 2020 20:25:53 -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=nOP/WB4f5EOc+9iMNgr1GvARoRc8y3IjDCJ8RShT+rk=; b=ZU27wAbV9bFAD3vOJnqL/otthlPiL6zh0mPvAV8aZr4CpRznmH0NZlR4ER1nnURy9Q YTrHXfW46dK+iw43XtdsWd6amV2neT690U0sZsITBByGi9ieCijEoXz98+5aLhnEKr5/ XCg9a6pFV1E0VS6BOQ+efHMPD7cNOWwZXqHIqIoYF05MuBuyMUYcYU48z0I0T/ssS1iS E53ycr+yfmngcwGTcCLIwY4uGcdc1M/2S1jiflFNSH384Od0nkAx+BW96kJbNzWW0o+4 qC1ILEvhpZeY5rwo9UuL/tStNPgLpwraHMn5xDpeJpGSmg8veoHsgUfVuInsDkn37pek gRMg== 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=nOP/WB4f5EOc+9iMNgr1GvARoRc8y3IjDCJ8RShT+rk=; b=InPQaICtb818wHpYVSZ4H8iDl7S7Sjgm/VLhCvb5ZxI2WEg/u+utajKlM6doJbvdHr 57pVUi6pMgszb6Jt4oHoOK/G20WZ1QP2jsaYEos1dell5QofLRnT6agcIC+9ITVDA/k/ ESh4tFg/naH0CFpIq4L1aGaM/uSusvmTAHGt8tKlkZKFOm8kXDejnY9gTsoY2EuKw23L ziN+EBhyGGD2HIsFclQerzzvXt13UvN9alN/tlRxFMNNYupuduynr2SsRNWcn/zxI1UG JvC5HzQbCEuXZVh6r0Y0RLgrwG8BapxDO2xjQypOJ4BrhHkl861ERmba/Ar5J74UIG/C 3/Ng== X-Gm-Message-State: AOAM5333DblMeg0tFtcTYaeMaIWZZO8oOO5XStYon3eEcMWJGsBr3WnF NNpIqhoyqPR38sfLwbfjtxgWMTH3P+U= X-Received: by 2002:a17:90a:eac9:: with SMTP id ev9mr3008655pjb.106.1597289152307; Wed, 12 Aug 2020 20:25:52 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id m19sm3633164pgd.21.2020.08.12.20.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 20:25:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 09/17] crypto: Move cipher->driver init to qcrypto_*_cipher_ctx_new Date: Wed, 12 Aug 2020 20:25:29 -0700 Message-Id: <20200813032537.2888593-10-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::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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" 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 --- crypto/cipherpriv.h | 2 -- crypto/cipher-afalg.c | 5 ++++- crypto/cipher-builtin.inc.c | 4 ++++ crypto/cipher-gcrypt.inc.c | 2 ++ crypto/cipher-nettle.inc.c | 3 +++ crypto/cipher.c | 7 ------- 6 files changed, 13 insertions(+), 10 deletions(-) -- 2.25.1 Reviewed-by: Daniel P. Berrangé 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 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.inc.c b/crypto/cipher-builtin.inc.c index 6a03e23040..1444139f36 100644 --- a/crypto/cipher-builtin.inc.c +++ b/crypto/cipher-builtin.inc.c @@ -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.inc.c b/crypto/cipher-gcrypt.inc.c index 3b3c85e265..7a1fbc9745 100644 --- a/crypto/cipher-gcrypt.inc.c +++ b/crypto/cipher-gcrypt.inc.c @@ -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.inc.c b/crypto/cipher-nettle.inc.c index d8371d1f37..36d57ef430 100644 --- a/crypto/cipher-nettle.inc.c +++ b/crypto/cipher-nettle.inc.c @@ -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 6ea75bb764..6e25f68f5c 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; }