From patchwork Thu Jan 5 00:49:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 9498141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D61AB606B4 for ; Thu, 5 Jan 2017 00:55:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAC2F28384 for ; Thu, 5 Jan 2017 00:55:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC998283A6; Thu, 5 Jan 2017 00:55:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9531628384 for ; Thu, 5 Jan 2017 00:55:32 +0000 (UTC) Received: from localhost ([::1]:43060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOwL5-00069j-MC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 04 Jan 2017 19:55:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOwGF-00024v-4C for qemu-devel@nongnu.org; Wed, 04 Jan 2017 19:50:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cOwGD-0008Ng-5e for qemu-devel@nongnu.org; Wed, 04 Jan 2017 19:50:31 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:41924) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cOwGC-0008KF-H4 for qemu-devel@nongnu.org; Wed, 04 Jan 2017 19:50:29 -0500 Received: from 172.24.1.137 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.137]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DSZ81168; Thu, 05 Jan 2017 08:50:22 +0800 (CST) Received: from localhost (10.177.246.209) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Thu, 5 Jan 2017 08:50:14 +0800 From: "Longpeng(Mike)" To: Date: Thu, 5 Jan 2017 08:49:40 +0800 Message-ID: <1483577381-38088-6-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1483577381-38088-1-git-send-email-longpeng2@huawei.com> References: <1483577381-38088-1-git-send-email-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.586D984E.00BE, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: b0b8244f749b2d732309e05ddc035f29 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 119.145.14.65 Subject: [Qemu-devel] [PATCH RESEND 5/6] crypto: implement other common funcs for AEAD algorithms X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Longpeng\(Mike\)" , arei.gonglei@huawei.com, qemu-devel@nongnu.org, wu.wubin@huawei.com, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If currently gcrypt/nettle doesn't support AEAD alg, then we should implement some no-op funcs. Signed-off-by: Longpeng(Mike) --- crypto/aead.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/crypto/aead.c b/crypto/aead.c index 47639b7..effe45e 100644 --- a/crypto/aead.c +++ b/crypto/aead.c @@ -16,18 +16,58 @@ #include "qapi/error.h" #include "crypto/aead.h" +#if defined(CONFIG_NETTLE_AEAD) || defined(CONFIG_GCRYPT_AEAD) + +static size_t alg_key_len[QCRYPTO_AEAD_ALG__MAX] = { + [QCRYPTO_CIPHER_ALG_AES_128] = 16, + [QCRYPTO_CIPHER_ALG_AES_192] = 24, + [QCRYPTO_CIPHER_ALG_AES_256] = 32, +}; + bool qcrypto_aead_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) { + switch (alg) { + case QCRYPTO_CIPHER_ALG_AES_128: + case QCRYPTO_CIPHER_ALG_AES_192: + case QCRYPTO_CIPHER_ALG_AES_256: + break; + default: + return false; + } + + switch (mode) { + case QCRYPTO_CIPHER_MODE_CCM: + case QCRYPTO_CIPHER_MODE_GCM: + return true; + default: + break; + } + return false; } size_t qcrypto_aead_get_key_len(QCryptoCipherAlgorithm alg) { - return -1; + if (alg > G_N_ELEMENTS(alg_key_len)) { + return 0; + } + + return alg_key_len[alg]; } -#if !defined(CONFIG_NETTLE_AEAD) && !defined(CONFIG_GCRYPT_AEAD) +#else + +bool qcrypto_aead_supports(QCryptoCipherAlgorithm alg, + QCryptoCipherMode mode) +{ + return false; +} + +size_t qcrypto_aead_get_key_len(QCryptoCipherAlgorithm alg) +{ + return -1; +} QCryptoAead *qcrypto_aead_new(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode,