From patchwork Tue Jan 3 00:33:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 9494299 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 2EB96606A8 for ; Tue, 3 Jan 2017 00:35:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 220372723E for ; Tue, 3 Jan 2017 00:35:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16E1427569; Tue, 3 Jan 2017 00:35:12 +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 606792723E for ; Tue, 3 Jan 2017 00:35:11 +0000 (UTC) Received: from localhost ([::1]:59633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOD4I-0002zd-FJ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 02 Jan 2017 19:35:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOD3e-0002xY-RD for qemu-devel@nongnu.org; Mon, 02 Jan 2017 19:34:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cOD3d-0001PI-Ot for qemu-devel@nongnu.org; Mon, 02 Jan 2017 19:34:30 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:6879) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cOD3d-0001LE-26 for qemu-devel@nongnu.org; Mon, 02 Jan 2017 19:34:29 -0500 Received: from 172.24.1.36 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.36]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CNM61330; Tue, 03 Jan 2017 08:34:25 +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; Tue, 3 Jan 2017 08:34:15 +0800 From: "Longpeng(Mike)" To: Date: Tue, 3 Jan 2017 08:33:10 +0800 Message-ID: <1483403591-2564-6-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1483403591-2564-1-git-send-email-longpeng2@huawei.com> References: <1483403591-2564-1-git-send-email-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 119.145.14.66 Subject: [Qemu-devel] [PATCH 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,