devutils/ATFQ/book ATFQ git

Part I · How it works

11.1 Hashes, encryption and signatures

alsohashhashinghash functionsha256sha-256sha256summd5md5sumsha1encryptionsymmetric encryptionaesaes-gcmchacha20signaturedigital signaturehmacchecksumpassword hashingbcryptargon2

TL;DR

  • A hash turns any data into a short fingerprint (SHA-256: 32 bytes). Same input, same hash; you can't go back, nor find two inputs with the same hash.
  • Encryption needs a key to read the data again. With symmetric encryption (AES, ChaCha20) one shared key both locks and unlocks.
  • A signature proves who wrote something and that it wasn't changed: made with a private key, checked with the public one (11.2).
sha256sum ubuntu.iso            # compare with the published hash
sha256sum -c SHA256SUMS --ignore-missing

On your machine

alice@laptopexample
$ atfq 11.1
  Trusted   3 certificate authorities, in /etc/ssl/certs/ca-certificates.crt
  AES       aes-aesni, with the CPU's AES instructions · SHA-256: sha256-ni
  RNG       hardware generator tpm-rng-0 feeds the kernel
  TPM       version 2: can hold keys and seal disk keys

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

Why is a hash enough to check a download?

If the hash on the official site matches the file's, the file is the one they published: finding a different file with the same SHA-256 is out of reach. The hash itself must come from a trusted place (an HTTPS page or a signed file), otherwise an attacker swaps both.

How fast is encryption today?

With the CPU's AES instructions (AES-NI on x86, the crypto extensions on ARM), one core encrypts several gigabytes per second: faster than most disks and networks. That's why encrypting disks and all web traffic costs almost nothing now. Chips without them use ChaCha20, fast in plain software.

Commands
sha256sum openssl
Paths
/proc/crypto
See also
11.2 Public-key cryptography
11.4 Random numbers: /dev/urandom and entropy
2.1 What a CPU does: instructions and architectures