]> git.karo-electronics.de Git - linux-beck.git/commitdiff
hw_random: add support for the TPM chip as a hardware RNG source
authorKent Yoder <key@linux.vnet.ibm.com>
Wed, 8 Aug 2012 19:18:57 +0000 (14:18 -0500)
committerKent Yoder <key@linux.vnet.ibm.com>
Wed, 22 Aug 2012 16:11:41 +0000 (11:11 -0500)
This driver will make use of any available TPM chip on the system as a
hwrng source.

Acked-by: David Safford <safford@linux.vnet.ibm.com>
Signed-off-by: Kent Yoder <key@linux.vnet.ibm.com>
drivers/char/hw_random/Kconfig
drivers/char/hw_random/Makefile
drivers/char/hw_random/tpm-rng.c [new file with mode: 0644]

index 7c0d391996b5b4e82432b9b3418d427f7a42894a..fbd9b2b850ef1de0a84a57182ff79bdd38064896 100644 (file)
@@ -289,3 +289,16 @@ config HW_RANDOM_EXYNOS
          module will be called exynos-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.
index 39a757ca15b65c59b188d0489b12488e4b4c6ac3..1fd7eec9fbf6421ace05971f95671095917bf4fa 100644 (file)
@@ -25,3 +25,4 @@ 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_EXYNOS) += exynos-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 (file)
index 0000000..d6d4482
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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)
+{
+       return tpm_get_random(TPM_ANY_NUM, data, 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");