From: David Safford <safford@linux.vnet.ibm.com>
To: Kent Yoder <key@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org, tpmdd-devel@lists.sourceforge.net,
m.selhorst@sirrix.com, David Safford <safford@us.ibm.com>
Subject: Re: [PATCH 2/2] hw_random: add support for the TPM chip as a hardware RNG source
Date: Fri, 08 Jun 2012 15:13:16 -0400 [thread overview]
Message-ID: <1339182796.2297.12.camel@localhost.localdomain> (raw)
In-Reply-To: <1339094862.21398.6.camel@key-ThinkPad-W510>
On Thu, 2012-06-07 at 13:47 -0500, Kent Yoder wrote:
> This driver will make use of any available TPM chip on the system as a
> hwrng source.
>
> Signed-off-by: Kent Yoder <key@linux.vnet.ibm.com>
Acked-by: David Safford <safford@linux.vnet.ibm.com>
> ---
> 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 <linux/module.h>
> +#include <linux/hw_random.h>
> +#include <linux/tpm.h>
> +
> +#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 <key@linux.vnet.ibm.com>");
> +MODULE_DESCRIPTION("RNG driver for TPM devices");
next prev parent reply other threads:[~2012-06-08 19:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-07 18:42 [PATCH 0/2] Move the tpm_get_random api and add an hwrng driver for it Kent Yoder
2012-06-07 18:47 ` [PATCH 1/2] tpm: Move tpm_get_random api into the TPM device driver Kent Yoder
2012-06-08 19:13 ` David Safford
2012-07-26 22:12 ` H. Peter Anvin
2012-07-27 14:49 ` Kent Yoder
2012-07-27 15:07 ` H. Peter Anvin
2012-07-27 0:10 ` H. Peter Anvin
2012-07-27 14:51 ` Kent Yoder
2012-06-07 18:47 ` [PATCH 2/2] hw_random: add support for the TPM chip as a hardware RNG source Kent Yoder
2012-06-08 19:13 ` David Safford [this message]
2012-07-26 21:58 ` H. Peter Anvin
2012-07-26 22:28 ` H. Peter Anvin
2012-06-08 19:13 ` [PATCH 0/2] Move the tpm_get_random api and add an hwrng driver for it David Safford
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1339182796.2297.12.camel@localhost.localdomain \
--to=safford@linux.vnet.ibm.com \
--cc=key@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.selhorst@sirrix.com \
--cc=safford@us.ibm.com \
--cc=tpmdd-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox