EDUCATION, CRYPTO, KEYS

🔐 Cryptography - data at rest, transmission and use

Seven themes on what directly protects data in each state: what are primitive and whose problem each solves, how data is protected on disk, network and during processing, how keys are managed and what changes with post-quantity standards.

Data Life Cycle

Three situations, three threat models, three controls

Datu trīs stāvokļi un katram atbilstošā aizsardzība Dati miera stāvoklī, pārraidē un lietošanā; katram stāvoklim savs drauds un sava kontrole. Viens datu kopums, trīs draudu modeļi MIERA STĀVOKLĪ Nozagts disks vai kopija Diska un lauka šifrēšana Atslēgu hierarhija PĀRRAIDĒ Noklausīšanās, starpnieks TLS 1.3, mTLS Sertifikātu ķēde LIETOŠANĀ RAM Atmiņas izraksts, administrators Minimizēšana, tokenizācija Uzticamā izpildes vide Vājākais stāvoklis nosaka kopējo aizsardzību

There is no point encrypting the disk if the same data travels over the network without TLS, and there is no point in TLS if the backup is lying open. Protection is planned for all three conditions, not one.

Cryptography Is Not Purpose

This is a control that transfers risk from data to keys. If the key is stored next to encrypted data, the risk is not reduced, only shifted.

Three objectives

Confidentiality (nobody else reads), integrity (nobody changes unnoticed), authenticity (known who sent). Encryption itself gives only the first.

Most frequent error

The cryptographic code itself is written. Algorithms are public and tested; vulnerabilities arise in introduction - random source, repeated noncirculation, time leak.

Building blocks

Primitives - Who solves the problem

Kriptogrāfijas primitīvi un to atrisinātās problēmas Katrs primitīvs risina citu problēmu Simetriskā Viena atslēga AES-256-GCM ChaCha20-Poly1305 Ātra, liels datu apjoms Problēma: atslēgas nodošana Asimetriskā Atslēgu pāris RSA-3072, ECDSA P-256 X25519, Ed25519 Atrisina atslēgas nodošanu Lēna, maziem datiem Jaucējfunkcijas Vienvirziena SHA-256, SHA-3 BLAKE2 Pirkstu nospiedums datiem NAV paroļu glabāšanai Atvasināšana No paroles uz atslēgu Argon2id, scrypt HKDF (atslēgām) Apzināti lēna, ar sāli Pretojas vārdnīcas uzbrukumam MAC un AEAD HMAC-SHA256, AES-GCM Integritāte pret NODOMU Prasa kopīgu slepenu atslēgu Ciparparaksti Ed25519, ECDSA, RSA-PSS Integritāte + autorība Pārbauda ikviens, nenoliedzamība

In practice, they are combined: the session key is asymmetrically agreed, the symmetrical encryption of data flows, while the AEAD ensures confidentiality and integrity. It works for TLS.

Used

  • AEAD mode: AES-256-GCM or ChaCha20-Poly1305
  • Passwords: Argon2id (this site also uses it)
  • For accidental use: secrets module Python
  • Library cryptography, not own written code

Do not use

  • AES-ECB - the same blocks give the same encryption
  • MD5, SHA-1 - collisions are practical
  • Mixed function passwords without salt and without cost
  • random module a2 - expected

Data on disk and database

Envelope encryption - key hierarchy

Envelope encryption: datu atslēga, atslēgu atslēga un saknes atslēga Datus šifrē DEK, DEK šifrē KEK, KEK aizsargā saknes atslēga HSM iekšienē. Katru atslēgu aizsargā nākamā DATI Šifrēti ar DEK AES-256-GCM DEK Datu atslēga Glabāta šifrēta KEK Atslēgu atslēga HSM / KMS HSM Saknes atslēga Nekad neiziet ārā Dalītas zināšanas šifrē šifrē sargā Rotācija pāršifrē tikai DEK - miljons ierakstu paliek vietā.

Why two levels: key rotation means to decrypt only DEK, not all data. One million records remain in place, one small value changes.

Full disc

Protects against stolen equipment. When the system is running, the data is open - therefore it does not protect against entering the server.

Field level

Encrypt specific fields (personal data, health data). Also protects against DB administrator, but broken search and handling.

Spare copies

The most frequently forgotten place. The copy shall be the same data without access control. The copies of this site are encrypted by age and stored outside the server.

Network data

TLS 1.3 - what it gives and what does not give

TLS 1.3 rokasspiediens vienā apkārtgājienā TLS 1.3: viens turp-atpakaļ cikls Klients Serveris ClientHello + key_share ServerHello + sertifikāts + Finished Šifrēti lietojumdati Viens turp-atpakaļ cikls (1-RTT). TLS 1.3 noņēma novecojušos šifrus un vienmēr nodrošina forward secrecy.

Forward secret (PFS) means that the private key of a later stolen server does not decrypt the previously recorded traffic - each session has its own temporary key. It is commonly called a future mystery, but the industry uses the original term.

What TLS does NOT protect

Metadata: with which server speaks, how much and how often. Content is closed, there is no fact of communication.

Final points

TLS ends at the server. If the data behind it goes between microservices, only the first step is protected - therefore mTLS internal network.

Certificate proves domain

Normal certificate confirms domain control, not that the owner is honest. The phishing page also has a valid lock.

The Challenge

Data at the time of processing - what can be done with them

Pieejas datu aizsardzībai lietošanas laikā Jo lielāka aizsardzība, jo augstāka cena Minimizēšana Neapstrādā to, kas nav vajadzīgs Briedums: pilnīgs Cena: zema Sāc ar šo Tokenizācija Īstā vērtība aizstāta ar bezjēdzīgu marķieri Briedums: pilnīgs Cena: vidēja Maksājumu kartēm Trusted Execution Env. Aparatūras anklāvs SGX, TDX, SEV-SNP Briedums: augošs Cena: augsta Slēpj no mākoņa uzturētāja Homomorfā Rēķina, neatšifrējot Arī drošs vairākpušu Briedums: šaurs Cena: ļoti augsta Specifiskiem uzdevumiem No kreisās uz labo: pieaug aizsardzība, pieaug arī cena un sarežģītība

The state of use is the only one where there is no universal solution. Fairly for most systems: minimizing and tokenisation solves most, and only then is it worth looking at the enclaves.

Attestation

The value of the reliable environment is the remote assay: the code can prove who works directly in it. Without it, the enclave is just another black box.

Transfer of Confidence

The enclave transfers trust from the cloud maintainer to the processor manufacturer. It is a change, not an elimination - and it has been vulnerable to side-channel attacks.

In practice

This site uses the simplest layer: card data never reaches the server (payments are processed by Klix), so they do not need to be protected in the condition of use.

Where cryptography in practice falls

Key Life Cycle (NIST SP 800-57)

Atslēgas dzīves cikla posmi Atslēgas dzīves cikls Ģenerēšana Droša nejaušība Glabāšana HSM, KMS Lietošana Viens mērķis Rotācija Plānota, ne tikai pēc Atsaukšana, iznīcināšana Arī no kopijām Vairums kriptogrāfijas kļūmju nav algoritmā, bet šajā ciklā Atslēga repozitorijā, atslēga blakus datiem, atslēga, kas nekad nav rotēta

An identified leak of mystery means rotation, not deletion of history. What has once been public must be regarded as known.

One key, one goal

The same key for encryption and signing weakens both. Separate keys also mean that a single compromise does not open everything.

Shared knowledge

No man knows the root key completely. It is divided into parts and renewal requires a number of people - protection from one weak point.

Crypto-agility

System in which the cryptographic algorithm can be changed without overwrite. It became a practical requirement precisely because of the post-quantum transition.

Standard landscape

What has been confirmed and what changes

Post-kvantu standarti un pārejas laika līnija Post-kvantu pāreja jau ir sākusies 2024-08-13 NIST apstiprina FIPS 203, 204, 205 Šodien Hibrīdā pāreja Klasiskā un post-kvantu kopā Nākotne Klasiskā izņemta RSA un ECC pakāpeniski ārā Harvest now, decrypt later Šodien pārtverta satiksme var tikt atšifrēta nākotnē, kad būs pietiekami jaudīgs kvantu dators. Ilgi dzīvojoši noslēpumi ir apdraudēti jau tagad.

FIPS 203 (ML-KEM, key encapsulation), FIPS 204 (ML-DSA, signatures) and FIPS 205 (SLH-DSA, interface-based signatures) were approved by NIST on 13 August 2024.

Algorithms

FIPS 197 (AES), FIPS 180-4 (SHA-2), FIPS 202 (SHA-3), FIPS 186-5 (signatures). The transition periods are set by the NIST SP 800-131A.

Application

NIST SP 800-175B (as to use), SP 800-57 (keys), ISO/IEC 19790 (module requirements), OWASP USS section 6 (development of testing requirements).

Legal

Article 21 (2) (h) of the NIS2 requires a cryptographic policy. eIDAS regulates trust services and qualified e-signatures in the EU.

Abbreviations

All signs used in the guide in one place.

AEAD
Authenticated Entry with Associated Data - encryption and at the same time ensuring integrity.
AES
Advanced Entry Standard - symmetrical block code (FIPS 197).
DEK
Data Encryption Key - a key to encrypt the data itself.
FIPS
Federal Information Processing Standards - U.S. federal standards; cryptography de facto international.
HKDF
HMAC-based Key Derivation Function - derived keys from an already secret value.
HMAC
Hash-based Message Authentication Code - integrity with a common secret key.
HSM
Hardware Security Module - hardware that does not leave the key.
KEK
Key Encryption Key - a key to encrypt other keys.
KMS
Key Management Service - key management service.
ML-DSA
Module-Lattice-Based Digital Signature Algorithm - post-quantity signature (FIPS 204).
ML-KEM
Module-Lattice-Based Key-Encapsulation Mechanism - post-quantum key exchange (FIPS 203).
MPC
Multi-Party Computation - several parties invoice a joint result without revealing their data.
PFS
Perfect Forward Secrety - later stolen key does not decipher the earlier traffic; the industry uses the English term.
PQC
Post-Quantum Cryptography - algorithms that are also resistant to quantum computers.
SLH-DSA
Stateless Hash-Based Digital Signature Algorithm - post-quantity signature (FIPS 205).
TEE
Trusted Executive Environment - hardware enclave for data during use.
TLS
Transport Layer Security - encrypted network channel; version 1.3 is current.