From patchwork Fri Jul 14 18:03:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 788691 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 3x8LFT4ctnz9s65 for ; Sat, 15 Jul 2017 04:05:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R9P9Wh43"; dkim-atps=neutral Received: from localhost ([::1]:39273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW4xn-0005Hr-NP for incoming@patchwork.ozlabs.org; Fri, 14 Jul 2017 14:05:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW4wy-0005F1-JC for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW4wx-000397-BA for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:24 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:36602) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW4wx-00038d-40 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:23 -0400 Received: by mail-pf0-x244.google.com with SMTP id z6so11753940pfk.3 for ; Fri, 14 Jul 2017 11:04:23 -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=R9P9Wh43h8GGdMkOCKLInmkW9u/u2Fyg8uEZPb9vGLeNG4f/aTSXhgKti0A6RowqID dsR7NPNpgcR1HLFt+mubyz7b6lBgcd8rrIcDZLsdJk4VzNK9RxE2isK9mzNRsPYNwZ62 vFRFpS0gfrzLpui0LT0OcP5SE9CYtgyGl4NeNkRvV5ZTt80gFgC8rMpqwGcHd+D8sarq 0/KRiVrRCKQgv4O2Kx365wW6AFaL6EgNCXXYl4/pnK0SB1Ohpv0cvBCQTWjT6lE+qbF6 Z/A/VWwbwamcGikB27/ePvtX8s9JUAeVddKqwgIepmEX+IlbF+pwlPIdPLxaFecYXhs/ epkg== 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=MxmMUBQxeDBzbSeq93F90732ZkRUBpMwq25PnWpzW06AXEf6eTMn8jjKgHtJ6vYQnN iWc+b6T+yAVfRfMPoJAKDvPZsxH3/lGPydy6olPSArcRG6h5n7uFpf6l1C0LDjSg+43l Xf11s/SkR1OeYKT2V7+KEBTFKCl/RiKP4QWVP/pSKO841IWQgmEc6OUbmuzXC4PtIKaW uvCbuqC7Gm0kGDvoF0Bli3ZHIffc0gkzNmu9yXKJrjQUj2r7DU4YuG2tbSvfaO2FDJ8Z 21v6TclDKtb3vvudjaHmDHRpk1XglSGIJGhinWtkJTcWwmfWVGsbqKkTYHb4raBEvkVd ztXA== X-Gm-Message-State: AIVw111UAihAbE9drnRci0A5N0d4zt+RmcFEyhMr8x/kZroEcf2oa0xu JKJ+GPG0hRlKMg== X-Received: by 10.84.224.134 with SMTP id s6mr17094774plj.263.1500055462321; Fri, 14 Jul 2017 11:04:22 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id f87sm19690168pfe.108.2017.07.14.11.04.21 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 11:04:21 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 14:03:59 -0400 Message-Id: <1500055451-14041-7-git-send-email-longpeng.mike@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500055451-14041-1-git-send-email-longpeng.mike@gmail.com> References: <1500055451-14041-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:c00::244 Subject: [Qemu-devel] [PATCH v6 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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