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

Three positions of data and adequate protection for each Data in peace, transmission and use; each state has its own threat and control. One set of data, three threat models PEACE A stolen disk or copy Disc and field encryption Key hierarchy MONITORING Hearing, Mediator TLS 1.3, mTLS Certificate chain PACKAGE LEAFLET RAM Memory Extract, Administrator Minimisation, tokenisation Trusted execution environment The weakest condition determines the overall protection

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 checked; vulnerabilities arise in implementation: the weak random source, the re-used noncirculation (in a single number, which should not be used twice) or the time of leakage (after how long the check takes place, you can guess the mystery).

Building blocks

Primitives - Who solves the problem

The priority is the basic block of cryptography - one operation with one task. No block delivers everything: encryption hides content, but does not prove who sent it; signature proves sender, but content does not hide. That's why they put them together in systems.

  • common one key for both parties
  • public may all know
  • private only the owner knows

How communication works - step by step

Choose a way and go through the steps. The middle bar shows what the attacker, who listens to the net, sees on the way.

Symmetric encryption

  1. 1
    Alice and Bobk keyAlice and Bob already have

    Both agree on one common key K. This is the weak point: how to transfer it if the channel is not yet secure?

  2. 2
    AliseHi+K=x7#Qp9..

    Alise encrypts a message with key K. The result is an incomprehensible code.

  3. 3
    Alice → Bobx7#Qp9..

    The attacker sees in the network: x7#Qp9... an incomprehensible chiff

    The code goes on the net. The attacker sees it, but without K can't read it.

  4. 4
    Bobx7#Qp9..+same K=Hi

    Bob decodes with the same key K.

  5. 5
    NoteIf the attacker ever gets K, he can decode everything that's encrypted with it.

    Therefore, the common key is transferred by asymmetric cryptography - the next example.

Asymmetric encryption

  1. 1
    Bobcreate a pair of:pprivate S

    Bob makes a pair of keys. Private S doesn't give anyone.

  2. 2
    Bob → Alicep

    The attacker sees in the network: public key P - it's no secret

    Bob sends Alice his public key. The attacker sees it, but it can only be locked, not unlocked.

  3. 3
    AliseEncrypted:Hi+P=k2

    Alise encrypts a message with Bob's public key P.

  4. 4
    Alice → Bobk2

    The attacker sees in the network: k2!Vz8... - a chiff that can only be unlocked by S

    The code goes on the net. The attacker has P, but P cannot turn this chiff off.

  5. 5
    Bobk2+private S=Hi

    Bob deciphers with his private key S - it's just for him.

  6. 6
    NoteIn practice, it encrypts not the entire message, but only the common key K.

    Asymmetric is slow, so it safely transmits K, and the data goes with the fast symmetrical - it starts TLS.

Mixed function

  1. 1
    Issued byprogram.zip→ SHA-256 →9f2c...a41

    The publisher calculates the fileprint and publishes it on his website.

  2. 2
    Publisher → Userprogram.zip

    The attacker sees in the network: the file - and can replace it with his

    The file goes over the network or through a mirror server. The attacker can replace it.

  3. 3
    Userreceived file→ SHA-256 →9f2c...a41

    The user himself calculates the printout of the received file.

  4. 4
    Usercompares with published: matches → file unchanged

    If the attacker changed the file, the print would be completely different. But the imprint must come from a reliable source - otherwise the attacker replaces it.

Password Derivation

  1. 1
    User → Serverpassword

    The attacker sees in the network: nothing - the connection is encrypted (TLS)

    On registration, the user sends the password through an encrypted connection.

  2. 2
    Servercreates accidentalsalt→ Argon2id, slow →value to be stored

    The password is not stored by the server. It only stores salt and results obtained with deliberately slow function.

  3. 3
    User → Serverpassword

    The attacker sees in the network: nothing - the connection is encrypted

    When the user applies, he sends the password again.

  4. 4
    Serversame salt → Argon2id → compared to stored

    The server repeats the calculation and compares. Match - password correct.

  5. 5
    NoteThe attacker steals the database: sees only salt and the result.

    Each guess costs ~0.1 s, and due to salt the same passwords look different - billion guesses become years.

MAC

  1. 1
    System and Storek keyboth parties already have

    Both sides previously have one common key K.

  2. 2
    Systempaid 10 €+K→ HMAC →code a83f..

    The sender calculates the check code from the message and key.

  3. 3
    System → Storepaid 10 €code a83f..

    The attacker sees in the network: the news openly and the code - the content of the MAC is not hidden

    The message goes with the code. The attacker can change '10 €' to '1000 €', but without K the correct code cannot be created.

  4. 4
    Shopmessage received+K→ HMAC → compares

    The recipient himself calculates the code and compares. If the message is changed, the codes do not match and the message is rejected.

Digital signature

  1. 1
    Issued bycreate a pair of:private Sp

    The publisher creates a pair of keys. Public P is published (e.g. on a certificate), private S is kept in a secure place.

  2. 2
    Issued byupdate+S→signature

    The publisher signs the file with his private key S.

  3. 3
    Publisher → Everyoneupdatesignature

    The attacker sees in the network: file and signature - both no secret

    File goes with signature. The signature does not hide content - it proves origin.

  4. 4
    Everyonefile + signature+p→ valid

    Everyone checks with the publisher's public key P. Valid - the file has not been changed and it was signed by the S holder.

  5. 5
    NoteThe attacker replaces the file → signature no longer fits, and without S a new create can not be created.

    Unlike the MAC check can anyone, but only sign the private key holder.

Summary: Which type fits

Symmetric encryption

One common key: with the same lock and unlock.

Text common key Encryption same key Text

EXP
Large data - disks, files, network flow. Fast.
Problem
How to transfer the common key safely to the other side if the channel is not yet secure?
Examples
AES-256-GCM, ChaCha20-Poly1305

Asymmetric encryption

Key pair: public may know everyone, private only recipient. With public lock, unlock can only with private.

Text public Encryption private beneficiary Text

EXP
Joint key transfer and agreement on it (it starts TLS connection).
Problem
Much slower than symmetrical, so only small data - usually the key itself - is encrypted with it.
Examples
X25519, RSA-3072, ECDH P-256

Mixed function

Converts data of any size into a short "fingerprint." Back data cannot be derived from it, and the smallest change gives a completely different footprint.

File, any size SHA-256 64-character imprint

EXP
Check that the file has not been changed - for example, the download checkup.
Problem
It is fast, so the passwords are invalid: the attacker checks billions of guesses per second.
Examples
SHA-256, SHA-3, BLAKE2

Password Derivation

Special, consciously slow mixing function for passwords. Add salt (salt) - an incidental value that is different for each password - and the cost of working factors that determine how slowly it works.

Password salt Argon2id, slow Value to be stored

EXP
Password storage and key extraction from the password. The user does not notice 0.1 s, the attacker with billions of guesses becomes years.
Problem
The work factor must be increased when computers become faster - otherwise protection weakens over time.
Examples
Argon2id, scrypt, bcrypt

MAC (report verification code)

Both sides have one common key. The sender adds a check code to the data, the recipient calculates it again and compares - if the data is changed, the code does not match.

Data common key Data + code same key match/non-match

EXP
API requests, cookies, payment notifications - where both parties already know the key.
Problem
Only who has a key can check, so it does not prove to the third person who created the code.
Examples
HMAC-SHA256 (AES-GCM included in encryption)

Digital signature

Signed with a private key, checked by public. It shall be demonstrated that the data have not been changed and that they have been signed directly by the private key holder.

Document signatory private Document + signature signatory public valid/ invalid

EXP
Software updates, certificates, e-signature - where everyone can check.
Problem
If the private key is stolen, it can sign anything - so it is stored in HSM or in a safe place.
Examples
Ed25519, ECDSA, RSA-PSS

It works at TLS: asymmetrically negotiates a common key, the digital signature on the server certificate proves that the server is the right one, and the symmetrical (AEAD) encryption of data and at the same time checking that it has not been changed.

Used

  • AEAD mode: AES-256-GCM or ChaCha20-Poly1305 - they encrypt and check at the same time that data have not been changed
  • Passwords: Argon2id or bcrypt - they add salt and work factor themselves (see side by side)
  • For keys and tokens: secrets module Python - its numbers cannot be predicted
  • Library cryptography, not own written code

Do not use

  • AES-ECB - each block is encrypted separately, so the same data gives the same encryption and the data pattern remains visible
  • MD5, SHA-1 - can deliberately create two different files with the same mixing value (clash), so the integrity check and signature with them are not reliable
  • For storage of quick mixing functions (MD5, SHA-256). The password requires salt - a random value that is different for each password so that the same passwords do not give the same result - and the working factor (cost) that deliberately slows down each guess. Without them, the stolen password list is hacked in hours.
  • random module secrets - from some of its numbers can be calculated next

Data on disk and database

Envelope encryption - key hierarchy

Envelope encryption: data key, key key and root key Data is encrypted by DEK, DEK is encrypted by KEK, KEK protects the root key inside HSM. Each key is protected next DATA Encrypted by DEC AES-256-GCM DEK Data key Storage encrypted KEK Key Key HSM / KMS HSM Root Key Never Leave Shared knowledge encryption encryption protected Rotation recodes only DEK - a million records remain in place.

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 the DB administrator, but the encrypted fields can no longer be searched and sorted.

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 handshake in one round TLS 1.3: one outward cycle Client Server ClientHello + key_share ServerHello + Certificate + Finished Encrypted application data One back cycle (1-RTT). TLS 1.3 removed obsolete chiffs and always provides forward secret.

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.

TLS 1.3 step by step

As a browser and server, a common key is agreed without anyone sending it over the network.

TLS 1.3 handshake

  1. 1
    Browser → ServerClientHelloclient key share

    The attacker sees in the network: site name (SNI) and client key part - it is not a secret

    The browser greets the server, names supported chiffs and immediately sends its short-term key section.

  2. 2
    Serverselect the font, create its own part;common key= total of the two parts

    The server calculates the common key (ECDHE) from both parts of the keys. It never goes on the net.

  3. 3
    Server → BrowserServerHelloserver partcertificate + signature

    Network attacker sees: ServerHello exposed; certificate and everything else is already encrypted

    The server responds with its own part, certificate and signature, which proves that it has the private key of the certificate.

  4. 4
    Browserchecks the certificate (reliable issuer, correct domain) and signature →same common key

    The browser makes sure you talk to the right server and calculates the same common key.

  5. 5
    Browser → ServerHTTP Request

    The attacker sees in the network: only encrypted data and their volume

    One round-back cycle, and the data already goes encrypted with the common key.

  6. 6
    NoteKey parts for each session are new - later stolen server key will not decode old entries.

    This is called forward secret: the recorded traffic remains secure even if the server is later hacked.

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

Access to data protection during use The more protection, the higher the price Minimisation Not processed by not required Judgment: Complete Price: low Start with this Tokenisation Real value replaced with a pointless marker Judgment: Complete Price: medium For payment cards Trusted Executive Env. Apparatus enclave SGX, TDX, SEV-SNP Delusion: Growing Price: high Hides from the cloud maintainer Homomorphous Invoice without decryption Also safe multipush Delusion: narrow Price: very high Specific tasks From left to right: protection increases, price increases and complexity increases

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 Performance Environment (TEE) is the Remote Attestation: the enclave can prove which code 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 against side channel attacks (reading of secrets after processor time, cache or consumption) they have been vulnerable.

In practice

This site uses the simplest layer: card data never gets to the server (payments are processed by the payment service provider) so they do not need to be protected in the state of use.

Where cryptography in practice falls

Key Life Cycle (NIST SP 800-57)

Key life cycle stages Key Life Cycle Generation Safe Chance Storage HSM, KMS Administration Single objective Rotation Planned, not only after Withdrawal, destruction Also from copies Most cryptographic failures are not algorithmic but within this cycle Key in repository, key next to data, key that has never been rotated

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 cryptography (PQC) transition.

Standard landscape

What has been confirmed and what changes

Post-quantum standards and transitional line The post-quantum transition has already started 2024-08-13 NIST confirmed FIPS 203, 204, 205 Today Hybrid transition Classical and post-quantum total Future Classically removed RSA and ECC gradually out Harvest now, decrypt later Today, intercepted traffic can be deciphered in the future when there will be enough quantum computer. Long-lived secrets are already under threat.

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. In 2025, NIST was selected as a backup by KEM for HQC. NIST IR 8547 (project) foresees an ageing of RSA and ECC from 2030 and a ban from 2035.

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 USAS 5.0 V11 (testable requirements for development).

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).
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.