Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932895Ab2FGSrY (ORCPT ); Thu, 7 Jun 2012 14:47:24 -0400 Received: from e7.ny.us.ibm.com ([32.97.182.137]:40395 "EHLO e7.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932818Ab2FGSrT (ORCPT ); Thu, 7 Jun 2012 14:47:19 -0400 Message-ID: <1339094862.21398.6.camel@key-ThinkPad-W510> Subject: [PATCH 2/2] hw_random: add support for the TPM chip as a hardware RNG source From: Kent Yoder To: linux-kernel@vger.kernel.org Cc: tpmdd-devel@lists.sourceforge.net, m.selhorst@sirrix.com, safford@us.ibm.com, key@linux.vnet.ibm.com Date: Thu, 07 Jun 2012 13:47:42 -0500 In-Reply-To: <1339094567.21398.2.camel@key-ThinkPad-W510> References: <1339094567.21398.2.camel@key-ThinkPad-W510> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.2- Content-Transfer-Encoding: 7bit Mime-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12060718-5806-0000-0000-000015FEB0F7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3503 Lines: 111 This driver will make use of any available TPM chip on the system as a hwrng source. Signed-off-by: Kent Yoder --- drivers/char/hw_random/Kconfig | 13 +++++++++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/tpm-rng.c | 55 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 0 deletions(-) create mode 100644 drivers/char/hw_random/tpm-rng.c diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index f45dad3..4e8c01a 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -263,3 +263,16 @@ config HW_RANDOM_PSERIES module will be called pseries-rng. If unsure, say Y. + +config HW_RANDOM_TPM + tristate "TPM HW Random Number Generator support" + depends on HW_RANDOM && TCG_TPM + default HW_RANDOM + ---help--- + This driver provides kernel-side support for the Random Number + Generator in the Trusted Platform Module + + To compile this driver as a module, choose M here: the + module will be called tpm-rng. + + If unsure, say Y. diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index d901dfa..5dc10da 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile @@ -23,3 +23,4 @@ obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o obj-$(CONFIG_HW_RANDOM_PICOXCELL) += picoxcell-rng.o obj-$(CONFIG_HW_RANDOM_PPC4XX) += ppc4xx-rng.o obj-$(CONFIG_HW_RANDOM_PSERIES) += pseries-rng.o +obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o diff --git a/drivers/char/hw_random/tpm-rng.c b/drivers/char/hw_random/tpm-rng.c new file mode 100644 index 0000000..a869b42c --- /dev/null +++ b/drivers/char/hw_random/tpm-rng.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012 Kent Yoder IBM Corporation + * + * HWRNG interfaces to pull RNG data from a TPM + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#define MODULE_NAME "tpm-rng" + +static int tpm_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) +{ + int err; + size_t tpm_max = max; + + err = tpm_get_random(TPM_ANY_NUM, data, &tpm_max); + + return err ? 0 : tpm_max; +} + +static struct hwrng tpm_rng = { + .name = MODULE_NAME, + .read = tpm_rng_read, +}; + +static int __init rng_init(void) +{ + return hwrng_register(&tpm_rng); +} +module_init(rng_init); + +static void __exit rng_exit(void) +{ + hwrng_unregister(&tpm_rng); +} +module_exit(rng_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Kent Yoder "); +MODULE_DESCRIPTION("RNG driver for TPM devices"); -- 1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/