From patchwork Tue Sep 13 03:52:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9328353 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 5298F60839 for ; Tue, 13 Sep 2016 04:07:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40A1528DE9 for ; Tue, 13 Sep 2016 04:07:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3531C29094; Tue, 13 Sep 2016 04:07:26 +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 1293328FD4 for ; Tue, 13 Sep 2016 04:07:25 +0000 (UTC) Received: from localhost ([::1]:46374 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjf0G-0008Rz-8c for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 00:07:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjepm-0000NG-1a for qemu-devel@nongnu.org; Mon, 12 Sep 2016 23:56:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjepj-0003yS-91 for qemu-devel@nongnu.org; Mon, 12 Sep 2016 23:56:34 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:52001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjepi-0003wu-LW for qemu-devel@nongnu.org; Mon, 12 Sep 2016 23:56:31 -0400 Received: from 172.24.1.36 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.36]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DQY76483; Tue, 13 Sep 2016 11:53:00 +0800 (CST) Received: from localhost (10.177.18.62) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Tue, 13 Sep 2016 11:52:48 +0800 From: Gonglei To: , Date: Tue, 13 Sep 2016 11:52:10 +0800 Message-ID: <1473738741-220600-5-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.6.3.windows.1 In-Reply-To: <1473738741-220600-1-git-send-email-arei.gonglei@huawei.com> References: <1473738741-220600-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.57D7781D.010F, 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: e430bc70f7572c4205d9f23fd8a36303 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH v2 04/15] crypto: add symetric algorithms support 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: claudio.fontana@huawei.com, mst@redhat.com, xin.zeng@intel.com, luonengjun@huawei.com, peter.huangpeng@huawei.com, agraf@suse.de, nmorey@kalray.eu, mike.caraman@nxp.com, Gonglei , stefanha@redhat.com, pbonzini@redhat.com, vincent.jardin@6wind.com, weidong.huang@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch include three parts, the first is define the session structure and the second is the opertion structure, whose properties are needed to finish the symetric algorithms. The third part defines some function pointers. Signed-off-by: Gonglei --- crypto/crypto.c | 16 +++++++++- include/crypto/crypto.h | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/crypto/crypto.c b/crypto/crypto.c index 3f760fd..958a959 100644 --- a/crypto/crypto.c +++ b/crypto/crypto.c @@ -177,7 +177,21 @@ int qemu_deliver_crypto_packet(CryptoClientState *sender, void *header_opqaue, void *opaque) { - return 0; + CryptoClientState *cc = opaque; + int ret = -1; + + if (!cc->ready) { + return 1; + } + + if (flags == QEMU_CRYPTO_PACKET_FLAG_SYM) { + CryptoSymOpInfo *op_info = header_opqaue; + if (cc->info->do_sym_op) { + ret = cc->info->do_sym_op(cc, op_info); + } + } + + return ret; } int qemu_send_crypto_packet_async(CryptoClientState *sender, diff --git a/include/crypto/crypto.h b/include/crypto/crypto.h index 4f0efb7..95cca23 100644 --- a/include/crypto/crypto.h +++ b/include/crypto/crypto.h @@ -33,10 +33,50 @@ #define MAX_CRYPTO_QUEUE_NUM 64 +#define QEMU_CRYPTO_PACKET_FLAG_NONE (0) +#define QEMU_CRYPTO_PACKET_FLAG_SYM (1 << 0) + +typedef struct CryptoSymSessionInfo { + uint8_t op_code; + uint8_t op_type; + uint8_t direction; + uint32_t cipher_alg; + uint32_t key_len; + uint8_t *cipher_key; + + uint32_t hash_alg; + uint8_t hash_mode; + uint32_t hash_result_len; + uint8_t alg_chain_order; + uint32_t auth_key_len; + uint32_t add_len; + uint8_t *auth_key; +} CryptoSymSessionInfo; + +typedef struct CryptoSymOpInfo { + uint64_t session_id; + uint8_t op_type; /* cipher or algo chainning */ + uint8_t *src; + uint8_t *dst; + uint8_t *iv; + uint8_t *aad_data; /* additional auth data */ + uint32_t aad_len; + uint32_t iv_len; + uint32_t src_len; + /* the dst_len is equal to src_len + hash_result_len + * if hash alg configured */ + uint32_t dst_len; + uint8_t data[0]; +} CryptoSymOpInfo; + typedef void (CryptoPoll)(CryptoClientState *, bool); typedef void (CryptoCleanup) (CryptoClientState *); typedef void (CryptoClientDestructor)(CryptoClientState *); typedef void (CryptoHWStatusChanged)(CryptoClientState *); +typedef int (CryptoCreateSymSession)(CryptoClientState *, + CryptoSymSessionInfo *, uint64_t *); +typedef int (CryptoCloseSession)(CryptoClientState *, uint64_t); +typedef int (CryptoDoSymOp)(CryptoClientState *, CryptoSymOpInfo *); typedef struct CryptoClientInfo { CryptoClientOptionsKind type; @@ -45,6 +85,9 @@ typedef struct CryptoClientInfo { CryptoCleanup *cleanup; CryptoPoll *poll; CryptoHWStatusChanged *hw_status_changed; + CryptoCreateSymSession *create_session; + CryptoCloseSession *close_session; + CryptoDoSymOp *do_sym_op; } CryptoClientInfo; struct CryptoClientState { @@ -57,6 +100,21 @@ struct CryptoClientState { char info_str[256]; CryptoQueue *incoming_queue; unsigned int queue_index; + + /* Supported service mask */ + uint32_t crypto_services; + + /* Detailed algorithms mask */ + uint32_t cipher_algo_l; + uint32_t cipher_algo_h; + uint32_t hash_algo; + uint32_t mac_algo_l; + uint32_t mac_algo_h; + uint32_t asym_algo; + uint32_t kdf_algo; + uint32_t aead_algo; + uint32_t primitive_algo; + CryptoClientDestructor *destructor; }; @@ -69,6 +127,20 @@ typedef struct CryptoLegacyHWPeers { typedef struct CryptoLegacyHWConf { CryptoLegacyHWPeers peers; + + /* Supported service mask */ + uint32_t crypto_services; + + /* Detailed algorithms mask */ + uint32_t cipher_algo_l; + uint32_t cipher_algo_h; + uint32_t hash_algo; + uint32_t mac_algo_l; + uint32_t mac_algo_h; + uint32_t asym_algo; + uint32_t kdf_algo; + uint32_t aead_algo; + uint32_t primitive_algo; } CryptoLegacyHWConf; typedef struct CryptoLegacyHWState { @@ -104,4 +176,17 @@ void qemu_del_crypto_legacy_hw(CryptoLegacyHWState *crypto); CryptoClientState * qemu_get_crypto_subqueue(CryptoLegacyHWState *crypto, int queue_index); +CryptoLegacyHWState *qemu_get_crypto_legacy_hw(CryptoClientState *cc); + +void *qemu_get_crypto_legacy_hw_opaque(CryptoClientState *cc); + +int qemu_find_crypto_clients_except(const char *id, CryptoClientState **ccs, + CryptoClientOptionsKind type, int max); + +int qemu_crypto_create_session(CryptoClientState *cc, + CryptoSymSessionInfo *info, + uint64_t *session_id); +int qemu_crypto_close_session(CryptoClientState *cc, + uint64_t session_id); + #endif /* QCRYPTO_CRYPTO_H__ */