Linux – Why doesn’t `head -c 2 /dev/hwrng` work

deviceslinuxrandomtpm

I have an Atmel 97SC3201 in my computer and set the following in the kernel:

  • CONFIG_HW_RANDOM_TPM
  • CONFIG_TCG_TPM
  • CONFIG_TCG_ATMEL

/dev has tpm0 and hwrng, but running this command returns the following:

head -c 2 /dev/hwrng

output:

head: error reading ‘/dev/hwrng’: Input/output error

In dmesg these messages appear:

tpm_atmel tpm_atmel: A TPM error (2048) occurred attempting get random

additional tries yield these messages:

tpm_atmel tpm_atmel: A TPM error (6) occurred attempting get random

Any ideas why this fails or better, how to get it working?

Best Answer

This RNG comes as part of a Trusted Platform Module. Unless your computer was part of an order for a large organization, the TPM is disabled by default, because it can make your computer unbootable if misconfigured, and because it can make your computer more traceable¹.

If you want to use the RNG, you'll have to enable it in the BIOS. The Thinkpad wiki has detailed instructions for a Thinkpad, which may still help with adaptations if you have another model. I'm not sure if it's enough to enable the TPM in the BIOS or if you also need to initialize it from Linux at boot time. If you need Linux support, install TrouSerS (most distributions should have a package for it).

You can use other things from the TPM, mainly secure boot (so that even someone with root access to your machine can't infect the bootloader to plant a rootkit²). You need Trusted Grub for secure boot.

Note that Linux has a good built-in cryptographic-quality pseudo-random number generator, and is good at collecting entropy to seed that PRNG. So the benefit from a hardware RNG is very limited.

¹ More precisely, a TPM gives your computer a hard-to-spoof identity that you can't easily deny. This would be a major privacy concern, but it is in fact a lot less of a problem than popularly perceived. Software using the TPM correctly does not send your computer's identity to remote parties, but use an application-specific key that isn't traceable to the TPM — so it's like having an account with the third party, no more. Software using the TPM incorrectly can expose your privacy, but so can any software — browsers are famous for revealing a lot of things about you. Everyday web browsing exposes far more than what you risk from a TPM.
² But note that there are other places to plant a rootkit. A TPM can only really provide protection if you lock the system down so much that it's hard to install any extra software.

Related Question