From patchwork Fri Jul 14 11:38:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 9840679 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 C1C2A60212 for ; Fri, 14 Jul 2017 11:46:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B48A128755 for ; Fri, 14 Jul 2017 11:46:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A97CB2876E; Fri, 14 Jul 2017 11:46:59 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 025EC2875A for ; Fri, 14 Jul 2017 11:46:57 +0000 (UTC) Received: from localhost ([::1]:37205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVz3g-0000UY-MV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Jul 2017 07:46:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVyvt-0000um-JX for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVyvs-0007lE-CG for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:53 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:33849) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVyvs-0007kX-5U for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:52 -0400 Received: by mail-pg0-x242.google.com with SMTP id j186so10399446pge.1 for ; Fri, 14 Jul 2017 04:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3T/Ytu7nWKDWHiMOWPNZ4+oh0I1rtTMYFF0p9qzhNmw=; b=Thbkb8xupCurWCDnmopnhDJMby/bzO9iN2qSb7gw5Jpa74DXOv1nL33QlsVobrTgKP Zsk5GTQNpI4+qGHmNgo3VaAeFmImCLLziQB/8LRTfllcFzblDlgi/RNvQPfnVXkpYbom A3PUC+gMntj4hZstf67EItWC33H35l8n3FdRlr+AK8DNpDuiDwafhQzmmKT14hIfag0M SCwoiIBfW9yVezHve6smAAY90vjD9MIIkJKZzQiA9/2dBT61u9swoKKnpCCe66KuYPLX MdmVDCoiPsNvSvXZ9C5gV+uOMHCve3dnMU234VwNwI4stvio2CmWW4E4ovLaPuTQqqgL r7eQ== 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; bh=3T/Ytu7nWKDWHiMOWPNZ4+oh0I1rtTMYFF0p9qzhNmw=; b=XEBnoaiJCesjhm9xVm4CWwxJ952NiwvSBs77U1Tj+Z48/W5tV1zdTHvz2LqP9RDu6d u/ZhAxx834vnfdHWFFn5VEdP5df1ijko03+tJLecfL3ir/kAONaxMZceCXVHcbYVDH/l bNdd6zLy2AEed62oIHC0gaqeuMo6EwrOM4TX673ZC8OGWnWXXh1gB9F5iYf3jLdRWy6E DY4A5sDvi61AZbqbMpzg3N+cglSNtr1Z9grIrFOphxaM6sHu7nv+jZERbEsxG7lZWRNv nngDJM5sFHpgRwvC2zc6P3HgBQXSJv5qpZMuI7kuWejK7dFM1cuhNiM1i4bC8sqnO4su Go+w== X-Gm-Message-State: AIVw110Kg2SdbaVCSFZ1PMDli6w6O1GyMygvyrOYthypt5BczqSh6SLn DwYyHbss3ijfjZDZ/rc= X-Received: by 10.84.195.131 with SMTP id j3mr15686014pld.147.1500032331350; Fri, 14 Jul 2017 04:38:51 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id b85sm18385615pfe.94.2017.07.14.04.38.50 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 04:38:50 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 07:38:28 -0400 Message-Id: <1500032321-13951-7-git-send-email-longpeng.mike@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500032321-13951-1-git-send-email-longpeng.mike@gmail.com> References: <1500032321-13951-1-git-send-email-longpeng.mike@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v5 06/18] crypto: hash: add hash driver framework 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, weidong.huang@huawei.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Longpeng(Mike)" 1) makes the public APIs in hash-nettle/gcrypt/glib static, and rename them with "nettle/gcrypt/glib" prefix. 2) introduces hash framework, including QCryptoHashDriver and new public APIs. Reviewed-by: Daniel P. Berrange Reviewed-by: Gonglei Signed-off-by: Longpeng(Mike) --- crypto/hash-gcrypt.c | 19 +++++++++++++------ crypto/hash-glib.c | 19 +++++++++++++------ crypto/hash-nettle.c | 19 +++++++++++++------ crypto/hash.c | 13 +++++++++++++ crypto/hashpriv.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 crypto/hashpriv.h diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c index 7690690..972beaa 100644 --- a/crypto/hash-gcrypt.c +++ b/crypto/hash-gcrypt.c @@ -22,6 +22,7 @@ #include #include "qapi/error.h" #include "crypto/hash.h" +#include "hashpriv.h" static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = { @@ -44,12 +45,13 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) } -int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp) +static int +qcrypto_gcrypt_hash_bytesv(QCryptoHashAlgorithm alg, + const struct iovec *iov, + size_t niov, + uint8_t **result, + size_t *resultlen, + Error **errp) { int i, ret; gcry_md_hd_t md; @@ -107,3 +109,8 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, gcry_md_close(md); return -1; } + + +QCryptoHashDriver qcrypto_hash_lib_driver = { + .hash_bytesv = qcrypto_gcrypt_hash_bytesv, +}; diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c index ec99ac9..a5871cc 100644 --- a/crypto/hash-glib.c +++ b/crypto/hash-glib.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "crypto/hash.h" +#include "hashpriv.h" static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = { @@ -47,12 +48,13 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) } -int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp) +static int +qcrypto_glib_hash_bytesv(QCryptoHashAlgorithm alg, + const struct iovec *iov, + size_t niov, + uint8_t **result, + size_t *resultlen, + Error **errp) { int i, ret; GChecksum *cs; @@ -95,3 +97,8 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, g_checksum_free(cs); return -1; } + + +QCryptoHashDriver qcrypto_hash_lib_driver = { + .hash_bytesv = qcrypto_glib_hash_bytesv, +}; diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c index 6a206dc..96f186f 100644 --- a/crypto/hash-nettle.c +++ b/crypto/hash-nettle.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "crypto/hash.h" +#include "hashpriv.h" #include #include #include @@ -103,12 +104,13 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) } -int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, - const struct iovec *iov, - size_t niov, - uint8_t **result, - size_t *resultlen, - Error **errp) +static int +qcrypto_nettle_hash_bytesv(QCryptoHashAlgorithm alg, + const struct iovec *iov, + size_t niov, + uint8_t **result, + size_t *resultlen, + Error **errp) { int i; union qcrypto_hash_ctx ctx; @@ -152,3 +154,8 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, return 0; } + + +QCryptoHashDriver qcrypto_hash_lib_driver = { + .hash_bytesv = qcrypto_nettle_hash_bytesv, +}; diff --git a/crypto/hash.c b/crypto/hash.c index 0f1ceac..c43fd87 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "crypto/hash.h" +#include "hashpriv.h" static size_t qcrypto_hash_alg_size[QCRYPTO_HASH_ALG__MAX] = { [QCRYPTO_HASH_ALG_MD5] = 16, @@ -38,6 +39,18 @@ size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg) return qcrypto_hash_alg_size[alg]; } +int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, + const struct iovec *iov, + size_t niov, + uint8_t **result, + size_t *resultlen, + Error **errp) +{ + return qcrypto_hash_lib_driver.hash_bytesv(alg, iov, niov, + result, resultlen, + errp); +} + int qcrypto_hash_bytes(QCryptoHashAlgorithm alg, const char *buf, diff --git a/crypto/hashpriv.h b/crypto/hashpriv.h new file mode 100644 index 0000000..5e505e0 --- /dev/null +++ b/crypto/hashpriv.h @@ -0,0 +1,31 @@ +/* + * QEMU Crypto hash driver supports + * + * Copyright (c) 2017 HUAWEI TECHNOLOGIES CO., LTD. + * + * Authors: + * Longpeng(Mike) + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + * + */ + +#ifndef QCRYPTO_HASHPRIV_H +#define QCRYPTO_HASHPRIV_H + +typedef struct QCryptoHashDriver QCryptoHashDriver; + +struct QCryptoHashDriver { + int (*hash_bytesv)(QCryptoHashAlgorithm alg, + const struct iovec *iov, + size_t niov, + uint8_t **result, + size_t *resultlen, + Error **errp); +}; + +extern QCryptoHashDriver qcrypto_hash_lib_driver; + +#endif