From patchwork Mon Apr 10 08:59:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 748892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w1kjK4rYWz9sNH for ; Mon, 10 Apr 2017 19:02:43 +1000 (AEST) Received: from localhost ([::1]:33075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxVDd-0000xJ-8w for incoming@patchwork.ozlabs.org; Mon, 10 Apr 2017 05:02:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxVBJ-0007t4-Qr for qemu-devel@nongnu.org; Mon, 10 Apr 2017 05:00:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxVBF-0001om-3y for qemu-devel@nongnu.org; Mon, 10 Apr 2017 05:00:17 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3418 helo=dggrg02-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxVBE-0001mf-1v for qemu-devel@nongnu.org; Mon, 10 Apr 2017 05:00:13 -0400 Received: from 172.30.72.54 (EHLO DGGEML404-HUB.china.huawei.com) ([172.30.72.54]) by dggrg02-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id ALI34219; Mon, 10 Apr 2017 17:00:07 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEML404-HUB.china.huawei.com (10.3.17.39) with Microsoft SMTP Server id 14.3.301.0; Mon, 10 Apr 2017 17:00:00 +0800 From: "Longpeng(Mike)" To: Date: Mon, 10 Apr 2017 16:59:53 +0800 Message-ID: <1491814793-56832-1-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 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.0A0B0202.58EB4998.0134, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 63bffe3ea8a93024f830839db4de0d75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.188 Subject: [Qemu-devel] [PATCH for-2.10 06/19] 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\)" , xuquan8@huawei.com, arei.gonglei@huawei.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Longpeng(Mike) --- crypto/hash-gcrypt.c | 17 +++++++++++------ crypto/hash-glib.c | 17 +++++++++++------ crypto/hash-nettle.c | 17 +++++++++++------ crypto/hash.c | 12 ++++++++++++ include/crypto/hash.h | 12 ++++++++++++ 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c index 7690690..21c990f 100644 --- a/crypto/hash-gcrypt.c +++ b/crypto/hash-gcrypt.c @@ -44,12 +44,12 @@ 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 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 +107,8 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, gcry_md_close(md); return -1; } + + +QCryptoHashDriver qcrypto_hash_lib_driver = { + .hash_bytesv = gcrypt_hash_bytesv, +}; diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c index ec99ac9..72be47e 100644 --- a/crypto/hash-glib.c +++ b/crypto/hash-glib.c @@ -47,12 +47,12 @@ 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 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 +95,8 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, g_checksum_free(cs); return -1; } + + +QCryptoHashDriver qcrypto_hash_lib_driver = { + .hash_bytesv = glib_hash_bytesv, +}; diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c index 6a206dc..9233e10 100644 --- a/crypto/hash-nettle.c +++ b/crypto/hash-nettle.c @@ -103,12 +103,12 @@ 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 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 +152,8 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, return 0; } + + +QCryptoHashDriver qcrypto_hash_lib_driver = { + .hash_bytesv = nettle_hash_bytesv, +}; diff --git a/crypto/hash.c b/crypto/hash.c index 0f1ceac..0b0d479 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -38,6 +38,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/include/crypto/hash.h b/include/crypto/hash.h index ca3267f..00b764e 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -25,6 +25,18 @@ /* See also "QCryptoHashAlgorithm" defined in qapi/crypto.json */ +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; + /** * qcrypto_hash_supports: * @alg: the hash algorithm