Topic 3 - Applied Cryptography and Secure Communication
Topic 3 - Applied Cryptography and Secure Communication
4
Caesar Cipher
• http://www.youtube.com/watch?v=sMOZf4GN3oc
• Substitution cipher
• each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet
5
Caesar Cipher Example
• A left shift of 3
• D would become A
• E would become B
• …. And so on.
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW
7
One Time Pad (OTP)
• http://www.youtube.com/watch?v=FlIG3TvQCBQ
• Each bit or character from the plaintext is encrypted by a modular addition with a bit or character from
a secret random key (or pad) of the same length as the plaintext => resulting in a ciphertext.
• If used correctly, i.e. if the key/pad is
• truly random
• as large as (or greater than) the plaintext
• never reused in whole or part
• kept secret
ciphertext will be impossible to decrypt or break without knowing the key/pad
• Practical problems prevented OTPs from being widely used. 8
True Random ver. Pseudo Random
cryptosystem is said to be computationally secure if the best known algorithm of breaking the system
requires an unreasonably large amount of computational time.
https://www.youtube.com/watch?v=itaMNuWLzJo
9
PRNG
• PRNG: a function which
• takes a certain amount of true randomness (called the seed /key of the PRNG)
• Cryptographically strong PRNG: an algorithm for which it has been proved that an opponent who knows
the algorithm and all of its output bits up to a certain point but not its seed, can not guess the next
output bit with any higher probability than ((1/2)+(e))
• (e) decreases exponentially with some security parameter (typically the length of the PRNG seed).
10
Cryptographic Keys
• Key is a collection of random bits
01010011101011110111
• The more bits in the key => the stronger the key
11
Kerckhoff’s Principle
• The system must be practically, if not mathematically, indecipherable;
• It should not require secrecy, and it should not be a problem if it falls into enemy hands;
• It must be possible to communicate and remember the key without using written notes
• It must be portable, and should not require several persons to handle or operate;
• Lastly, given the circumstances in which it is to be used, the system must be easy to use and should not be
stressful to use or require its users to know and comply with a long list of rules.
• Ciphers used to protect classified government or military information are often kept secret
• It should not be assumed that government/military ciphers must be kept secret to maintain security
14
Brute-Force Attack
• A method of defeating a cryptographic scheme by exhaustively enumeration through all possible keys in
order to decrypt a message
• For symmetric-key encryption, brute force attack typically means: testing all possible keys to recover
plaintext used to produce the ciphertext
• expected number of trials before the correct key is found is equal to half the size of the key space.
• if there are 2^128 possible keys, a brute force attack would, on average, be expected to find a key
after 2^127 trials
• Selection of an appropriate key length depends on the practical feasibility of performing a brute force
attack.
15
Brute-Force Attack & Key Length Setting
• In most cryptographic schemes
• Key-length should be set up in such a way that it would be computationally infeasible to carry out
brute-force enumeration attack.
• Symmetric key cipher is considered secure if there is no attack method less expensive (in time, memory
requirements, etc) than brute force attack
• One definition of "breaking" a cryptographic scheme is to find an attack method faster than a brute
force attack.
16
NIST Encryption Algorithms
17
Data Encryption
• Encryption – the of process of taking data and
a key, feeding it into an encryption function
and receiving encrypted data (cipher-text)
Encryption
Function
18
Data Decryption
• Decryption – the process of taking encrypted
data (cipher-text) and a key and feeding it into
a decryption function and receiving back the
original data
19
Symmetric Encryption
• Encryption and decryption functions that use the
same key are called symmetric
Encrypt
• Anyone who want to read the encrypted data
must have the key used to encrypt the data
Decrypt
20
Symmetric Stream Cipher Summary
• Sender XOR each bit of your plaintext continuous stream with a bit from a pseudo-random sequence
• Receiver, use the same symmetric key, XOR again to extract plaintext
21
Diffie-Hellman (D-H)
Algorithm
22
Diffie-Hellman (DH) Key Exchange
• http://www.youtube.com/watch?v=3QnD2c4Xovk
• DH key exchange - a cryptographic protocol that allows two parties that have no prior knowledge of each
other to jointly establish a shared secret key over an insecure communications channel.
• Key can then be used to encrypt subsequent communications using symmetric encryption algorithm
• The simplest, and original, implementation of the DH protocol uses the Multiplicative group of integers
modulo p
• p is prime
23
Diffie-Hellman Key Exchange (1976)
Alice generates a
Bob generates b.
24
Diffie-Hellman Key-Exchange Example
1. Alice and Bob agree to use a prime number p=23 and base g=5.
2. Alice chooses a secret integer a=6, then sends Bob (ga mod p): 56 mod 23 = 8.
3. Bob chooses a secret integer b=15, then sends Alice (gb mod p): 515 mod 23 = 19.
Both Alice and Bob have arrived at the same value, because gab and gba are equal.
25
Diffie-Hellman Details
• Only a, b and gab = gba are kept secret.
• Shared secret computed (known only to Alice and Bob) can be used as an encryption key for encrypting messages
• Much larger values of a, b, and p would be needed to make this example secure
• there will be, at most, 22 such values, even if a and b are large
• If p were a prime of at least 600 digits, and a and b were at least 600 digits long, then even the best algorithms
known today could not find a given only g, p, and ga mod p, even using all of available computing power.
27
Asymmetric Encryption
• Encryption and decryption functions that use a key pair are called asymmetric encryption
• http://www.youtube.com/watch?v=wXB-V_Keiu8
29
Asymmetric Encryption for Data Confidentiality
• Public keys are used for encrypting.
30
Alice & Bob Communicate Securely over
an Insecure Channel using Asymmetric Encryption
31
Alice Bob
32
Alice Bob
33
Theoretical Comparable Strengths (in bits)
• Sym. Key: Symmetric key encryption algorithms
• FFC and IFC: Finite field discrete log and factoring based public key algorithms
35
Symmetric vs. Asymmetric Encryption
36
Hybrid Crypto-System
• Hybrid cryptosystem combines the convenience of a public-key cryptosystem with the efficiency
of a symmetric-key cryptosystem.
and
37
Hybrid Crypto-System
38
Hybrid Encryption Example#1
ShK
ShK
PrK
PuK PrK
אני
PuK
ShK אתה
39
Hybrid Encryption Example#2
קובץ קובץ
ShK
ShK
PrK PrK
קובץ
PuK PuK
אני אתה
40
What do we know about the message sender in asymmetric encryption?
Bob’s Dilemma
• Nobody can read the message from Alice, but anyone could produce it.
• How does Bob know that the message was really sent from Alice?
• Alice can create a digital signature and prove she sent the message
Message Digest &
Hash Functions
Message Digest – One Way Function
h=H(m) is easy to compute
m=H-1(h) is hard to compute
original message
no practical limit to size
message digest
256 bit/384 bits
easy hard
Message Digest – One Way Function
• "hash function" - a cryptographic function that
44
Hash Function Requirements
• Second preimage resistance (weak hash): given m, it is hard to compute a second preimage of m
• It is hard to find m' such that m ≠ m' and yet H(m) = H(m')
• it is hard to compute m and m' such that m ≠ m' and yet H(m) = H(m')
• The initial IHV is a fixed value, and the final IHV is the hash value.
46
Hash Function Overview
M1 M2 M3 M4
IHV0
IHV4
MAC (Message
Authentication Code)
48
Verifying Data Integrity with Hashes
User A User B
Data Hash
Algorithm Hash Value
If hash values
Hash Algorithm
match, data is valid
Data
Data
Hash Value
Hash Value
50
MAC (Message Authentication Code) Overview
• MAC is a short piece of information used to protects both a message's integrity as well as its authenticity
• MAC algorithm accepts as input a secret key and an arbitrary-length message to be authenticated, and
outputs a MAC
• MAC allow verifiers (who also possess the secret key) to detect any changes to the message content
• Same message can only generate matching MACs if the same secret key is used with the same
algorithms to generate both
• MAC does not necessarily need to be encrypted to provide the same level of assurance.
• MIC (message integrity code) is different from a MAC in that a secret key is not used in its operation
Message Authentication Code (MAC)
• A and B share a secret key
A B: M, CK(M)
52
MAC by Encrypted Hash
• Alice and Bob share a key
• No confidentiality
A B: M,EK[H(M)]
Digital Signature
54
Generating a Digital Signature
• Digital signatures are created by encrypting a hash of
the data with my private key
Hash
• Resulting encrypted data is the digital signature
Hash
=?
Decrypt
Digital Signatures Summary
User A User B
Hash
Algorithm
Data
Data
Hash
Algorithm
User A
Public
Key
Hash Value
Hash Value
• Since this private key is only accessible to its holder, a digital signature proves that a document was signed by
none other than that holder. Thus,
Using Asymmetric Encryption for Message Confidentiality & Integrity
Alice Bob
PrK
PrK PrK
61
Man in The Middle (MITM) Attack PrK
קובץ קובץ
PuK
אתה
PrK PuK PuK
PuK
קובץ PrK
PuK
אני קובץ
PuK
PuK המתחזה
קובץ
62
The Need for a Digital Certificate
• How do you know that you have my correct public key?
• It allows you to know that a given public key belongs to a given user
• Digital Certificates includes a name and a public key (among other things) ?
bundled together and signed by a trusted party (Issuer)
Digital Certificate
Hash
Name
Issuer =?
Public Key Decrypt
Signature
Name Hash
Issuer
Public Key =?
Signature Decrypt
Name: CA
Issuer: CA
CA’s Public Key
CA’s Signature
Self-Signed Certificate Example
68
How Digital Certificate is Created?
Private
User Key Private/Public
Key Pair
Computer
Public
Key
Service
Application
Certification
Authority
Certified
Administrator
How Digital Certificate is Created?
• Client creates a pair of keys (using a software tool)
• Client prepares a Certificate Signing Request (CSR) containing an unsigned certificate that includes
• user identity
• creates a signature by calculating the hash of the unsigned certificate and encrypting the hash with the
CA's private key
• The hassle and cost of setting up an internal CA often drives businesses to use external CA
• If data is sent over the Internet, the only way all parties can trust the certificate is if it was
issued by a trusted third-party CA.
Trusted Certificate
Authorities & PKI
Who Signs Certificates?
• A small set of trusted entities known as Trusted Certificate Authorities (CAs) Name
2. Company that wants its website to be secured, purchases a website certificate at the CA (the green one in diagram).
• certificate is signed by the CA and guarantees the identity of the website to the users
3. When a user wants to visit the secure website, the web browser will first ask the web server for the certificate. If its
signature can be verified with the certificate of a CA in the trust list, the website certificate will be accepted.
• Then the website will be loaded into the browser, and all traffic between the browser and the website will be
secured by using SSL/LTS
Where is the “Trusted Root Certificates” List Stored?
Where is the “Trusted Root Certificates” List Stored?
• Many software products (OSs and browsers) come with a list of “trusted root certificates”
• Microsoft update the list periodically through Windows Update and their other updating
mechanisms.
• Applications may use the OS trusted root list or include their own trusted root list
• But
• Is CA1 trustworthy?
79
Issuer Subject Name Subject PubKey Signature
• Link can be verified by verifying the certificate's signature, using the public key of the issuing CA.
• CA public key can be found inside the CA certificate, one layer upwards in the hierarchy.
• It is "self signed“
86
Secure Communication Requirements
• Confidentiality/Privacy: information should be readable only by the intended receiver. i.e., protect the
information from being eavesdropped.
• Integrity/authenticity: receiver can confirm that a message has not been altered during transmission,
i.e., protect the message from tampering.
• Authentication: sender and/or receiver can verify that the other party is who he/she claims to be, i.e.,
validate the identity of the other party.
• Non-repudiation: sender cannot deny what he/she has done. e.g., if a transaction (e.g., a purchase) has
occurred between two parties, the non-repudiation service can prove that the sender really performed
the transaction him/herself
Transport Layer Security (TLS/SSL)
• Many application protocols include the use of cryptography as part of the application level protocol.
• Secure Sockets Layer (SSL) is a different approach - a new layer is added that provides a secure channel
over TCP (currently TCP only).
TLS/SSL Goals:
SSL Record
Protocol
TCP
• Anti-Replay
• Each SSL record data is optionally compressed – not recommended any more (due to CRIME attack)
• Symmetric digital signature (MAC) is computed over the record (and the header) and added to the record
• The header plus the encrypted (data + MAC) is sent using the TCP protocol
SSL Record Protocol Operation
SSL v3 Scenario: Encryption Process
How encrypted, MAC'd records are sent and received
In the handshake phase, client and server have verified each other's certificates, have agreed upon which algorithms to
use, and have agreed upon symmetric keys (both for encryption and for the MAC)
TCP/IP TCP/IP
96
SSL Handshake Protocol
SSL Handshake Goals
• Establish security capabilities/parameters
• PFS ensures that encrypted communications and sessions recorded in the past cannot decrypted should
long-term secret keys or passwords be compromised in the future
• => there is no one secret value whose acquisition would compromise multiple messages
• Any cipher with PFS property must use keys with effectively the same requirements as OTP keys.
• Public-key system has the PFS property if it generates one random public key per session to complete
a key agreement, without using a deterministic algorithm
101
102
SSL v3 Scenario: How SSL Works
The Handshake
module is called
when a
Signals connection is
change in started or
cipher resumed
strategy
Client Server Signals
Application Application Errors
(HTTP Client) (HTTP Server)
SSL
SSL SSL
Change
Alert Handshake
Cipher
SSL SSL
• There it a DTLS version that can be used for application protocols using UDP
• Environmental limitation
• The path to the network and from the network is not secured
SSL to Secure e-Commerce Applications
• Client authentication not needed until client decides to buy something.
• No guarantees about what happens to client data (including credit card details) after session:
may be stored on insecure server.
• Because there is a legitimate SSL connection between the client and the server, SSL reports no
problems
Source: Jeremiah Grossman, BlackHat 2001
Securing Network Communications
• Working assumption should always be, that an attacker can install a sniffer to capture sensitive
information, transmitted over the network
• Not encrypting sensitive communications means that attacker who can sniff traffic from the network
will be able to access credentials or other sensitive information transmitted.
• Encrypting sensitive data, such as credit cards and social security numbers, has become a privacy and
financial regulation for many organizations.
• PCI requires that all credit card information being transmitted over the internet be encrypted
• Neglecting to use SSL for connections handling such data creates a compliance risk.
Securing Network Communications
• Securing communication with end users is critical, as they are very likely to be using insecure networks
to access web applications
• SSL should be used whenever sensitive or value data, (e.g. credit card details, health and other private
information) is being transmitted
• Web applications are using authentication or session token for authenticated connections.
• Since HTTP includes authentication credentials or a session token with every single request, all
authenticated traffic needs to go over SSL, not just the actual login request.
Vulnerabilities Related
to Data Exposure
OWASP Top-10 2013
114
OWASP Top-10 2017
115
116
117
118