[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 05 Oct 2019 20:38:53 -0400
From: Mimi Zohar <zohar@...ux.ibm.com>
To: James Bottomley <James.Bottomley@...senPartnership.com>,
Jerry Snitselaar <jsnitsel@...hat.com>,
Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>,
David Safford <david.safford@...com>,
linux-integrity@...r.kernel.org, stable@...r.kernel.org,
David Howells <dhowells@...hat.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
"David S. Miller" <davem@...emloft.net>,
"open list:ASYMMETRIC KEYS" <keyrings@...r.kernel.org>,
"open list:CRYPTO API" <linux-crypto@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] KEYS: asym_tpm: Switch to get_random_bytes()
On Fri, 2019-10-04 at 15:11 -0700, James Bottomley wrote:
> +
> +/**
> + * tpm_get_random() - get random bytes influenced by the TPM's RNG
> + * @chip: a &struct tpm_chip instance, %NULL for the default chip
> + * @out: destination buffer for the random bytes
> + * @max: the max number of bytes to write to @out
> + *
> + * Uses the TPM as a source of input to the kernel random number
> + * generator and then takes @max bytes directly from the kernel. In
> + * the worst (no other entropy) case, this will return the pure TPM
> + * random number, but if the kernel RNG has any entropy at all it will
> + * return a mixed entropy output which doesn't rely on a single
> + * source.
> + *
> + * Return: number of random bytes read or a negative error value.
> + */
> +int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
> +{
> + int rc;
> +
> + rc = __tpm_get_random(chip, out, max);
> + if (rc <= 0)
> + return rc;
> + /*
> + * assume the TPM produces pure randomness, so the amount of
> + * entropy is the number of bits returned
> + */
> + add_hwgenerator_randomness(out, rc, rc * 8);
> + get_random_bytes(out, rc);
Using the TPM as a source of input to the kernel random number
generator is fine, but please don't change the meaning of trusted
keys. The trusted-encrypted keys documentation clearly states
"Trusted Keys use a TPM both to generate and to seal the keys."
If you really want to use a different random number source instead of
the TPM, then define a new trusted key option (eg. rng=kernel), with
the default being the TPM.
Mimi
> +
> + return rc;
> +}
> EXPORT_SYMBOL_GPL(tpm_get_random);
Powered by blists - more mailing lists