SlideShare une entreprise Scribd logo
1  sur  45
Introduction to
Encryption

6th Feb 2014
Who am I?
PHP Developer

@faffyman
@phpbelfast
What’s this talk about?
Mostly the Why and the What
And just a little bit of the How
What this talk is not about
Probability Theory behind encryption

encryption model definitions
Why Encrypt?
Secure communications
- TLS Email
- SSL web

Payment Gateways
-Credit Cards
-Bitcoins

Filesystems
-DVD
-Memory Cards

Cable TV Signals

Online Voting

DRM

WEP

Skype Calls
What is Encryption?
Είναι όλα ελληνικά για μένα
It’s all Greek to me
*Encryption is…
“An algorithm that can encode a message
such that it is only readable by authorized
persons”

*Generally speaking.
*Encryption is… a Cipher..
“A pair of algorithms such that the output
ciphertext of the encoding algorithm can be
efficiently transformed back to the original text
by the decoding algorithm”
*not always true
Examples of
Encryption through
history
The Caesar Cipher
Also known as the shift cipher
Or substitution cipher
Shift 3 chars left

Plain : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW

Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD
Plaintext: the quick brown fox jumps over the lazy dog
The Vigener Cipher
16th Century Rome

Is a Modulo shift cipher
Create a repeating key the same length as the message

Plain : PHP BELFAST ENCRYTION TALK
Key : BLI NKSTUDI OSBLINKST UDIO
Cipher: RTY PPEZVWC TEEDHHTHH OEUZ

P = 16 + B=2 = 18 = R
H = 8 + L=12 = 20 = T
L = 12 + S=19 = 31 % 26 = 5 = E
Playfair Mr Kennedy
Famous WWII message involving JFK

PHBEL
FASTC
DGIKM
NOQRU
VWXYZ

http://j.mp/pFAIR

IN TR OD UC TI ON TO EN CR YP TI ON

DQ KY NG ZM SK QO AR PR TU VE SK QO
The One Time Pad
1917, Vernam

Symantically secure, practically useless
Very fast encode / decode
Stream Cipher
The One Time Pad

Uses A Random Key of equal length to the message
AJDPWNCGS82NCPS03NCBS72HGTWX1EZMBLHPY04YDVS2D
Rotor Machines
Lorenz Cipher (a.k.a. Tunny)

Enigma
“Nothing to report”
Encryption is just XOR?
There is a lot if it - yes
M: 0 1 1 0 1 1 1
Ke: 1 0 1 1 0 0 1
C: 1 1 0 1 1 1 0
Kd: 1 0 1 1 0 0 1
M: 0 1 1 0 1 1 1
Symmetric Ciphers
D ( K, E(k, m) ) = M

Decryption of Encrypted Message = Original Message
Symmetric Ciphers
2 Identical Inputs = 2 different outputs
Making It Practical
Stream Ciphers
And

Block Ciphers
In danger of getting complex now…
Pseudo Randomness
Pseudo Random Key
PRF – Pseudo Rand Function
PRG – Pseudo Rand Generator
PRP – Pseudo Rand Permutation
Pseudo Random Keys
Short Input => Long Output
Data Encryption Standard
DES
1970 – 1976 - IBMs Lucifer cipher approved as Fed. Standard
1997 - DES is broken by exhaustive search
Internet search – took 3 months
1998 – Deep Crack does it in 3 days (cost $250K)
1999 – combined search 22 hours

2000 – New Fed Standard adopted. Rijndael or AES
Feistel Network
Common Block Cipher Construction

DES is a 16 round Fiestel construction

http://j.mp/feistDES
Advanced Encryption Standard

AES
Uses block cipher – But NOT a Fiestel Construction
1997: DES Broken NIST requests proposal for new std
1999: 5 shortlisted options
2000: Rijndael chosen to be new AES
AES
Side Channel Attacks
•
•
•
•

j.mp/1c9v9Vi

Timing Attacks
Power Attacks
Sound Attacks
Replay Attacks
ECB
Electronic Code Book

Encrypted with ECB

j.mp/1kONKMk

Encrypted in other modes
show pseudo randomness
CBC
Chain Block Cipher

j.mp/1kONKMk
CTR
Counter Mode
MICs and MACs
Message Integrity or Authentication Code
Basically - Hash Functions
MD5 - weak
SHA-1 - weak
SHA-256 - better
Anti-Tamper codes
Authenticated Encryption
Encrypt then MAC
- always provides A.E.

MAC then Encrypt is open to CCA attacks
- it’s ok IF you use rand-CBC or rand-CTR mode
- still open to padding attacks
Key Exchange
Public/Private Keys
Public key used to encrypt
Private key used to decrypt
Uses large primes (600+ digits) and modulus of the
powers of factors of that prime
Public/Private Keys
ALICE
Generate array of
public & private keys
Alice decrypts with Secret key
To obtain Bobs random number

BOB
Bob chooses one
public key
Chooses a random
secret {0,1}128
encrypts it using
Public Key

They now have a shared secret or key (Bobs
number) with which to encrypt future
messages
PHP – password storage
•
•
•
•
•
•
•

Raw / Plaintext – do people really do this?
Roll your own encryption mechanism
MySQL Encrypt()
MD5() – no collision too common
SHA and store salt
bcrypt – No salt storage required
phpass – no salt storage required

j.mp/1nPFttR
Golden Rule:
Libraries, libraries, libraries
Always use a tried & tested library

*NEVER*
Roll your own
PHP – MAC
hash_hmac()
hash_hmac ($algo, $data, $key [$raw_output = false])
hash_hmac(’sha256’,’phpbelfast rocks', ’MySecret');

php.net/hash_hmac
PHP crypt()

j.mp/1nPFttR
PHP – openssl library
openssl_get_cipher_methods()

openssl_cipher_iv_length()
openssl_encrypt()
openssl_decrypt()
j.mp/1dp8OTq
PHPass – for php v 5.4-

j.mp/phpass
PHP password_hash()
v5.5+
password_hash( $password, $algo [, $options] )
password_verify( $password, $hash )

php.net/password_hash
j.mp/1err98n
Credits
Cover image -Enigma Machine by Skittledog
http://flic.kr/p/9VjJz5
Creative Commons
http://creativecommons.org/licenses/by-nc-sa/2.0/
Fiestel Network Diagram
Dan Boneh, Stanford Unversity (Coursera – Cryptography I course)

Link Bundle

j.mp/1iq3xA5
Final Thought
“Only amateurs attack machines,
professionals attack humans”
- Bruce Schneier

Contenu connexe

Tendances

Ch03 block-cipher-and-data-encryption-standard
Ch03 block-cipher-and-data-encryption-standardCh03 block-cipher-and-data-encryption-standard
Ch03 block-cipher-and-data-encryption-standard
tarekiceiuk
 
Design and Simulation Triple-DES
Design and Simulation Triple-DESDesign and Simulation Triple-DES
Design and Simulation Triple-DES
chatsiri
 
Stream ciphers presentation
Stream ciphers presentationStream ciphers presentation
Stream ciphers presentation
degarden
 

Tendances (20)

RC 4
RC 4 RC 4
RC 4
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)
 
Ch03
Ch03Ch03
Ch03
 
DES (Data Encryption Standard) pressentation
DES (Data Encryption Standard) pressentationDES (Data Encryption Standard) pressentation
DES (Data Encryption Standard) pressentation
 
Class3
Class3Class3
Class3
 
Cryptographic Algorithms: DES and RSA
Cryptographic Algorithms: DES and RSACryptographic Algorithms: DES and RSA
Cryptographic Algorithms: DES and RSA
 
Block cipher modes of operation
Block cipher modes of operation Block cipher modes of operation
Block cipher modes of operation
 
Block Ciphers and the Data Encryption Standard
Block Ciphers and the Data Encryption StandardBlock Ciphers and the Data Encryption Standard
Block Ciphers and the Data Encryption Standard
 
Block Cipher and its Design Principles
Block Cipher and its Design PrinciplesBlock Cipher and its Design Principles
Block Cipher and its Design Principles
 
Overview on Cryptography and Network Security
Overview on Cryptography and Network SecurityOverview on Cryptography and Network Security
Overview on Cryptography and Network Security
 
Cryptography and Network Security William Stallings Lawrie Brown
Cryptography and Network Security William Stallings Lawrie BrownCryptography and Network Security William Stallings Lawrie Brown
Cryptography and Network Security William Stallings Lawrie Brown
 
Cryptography
CryptographyCryptography
Cryptography
 
Modern symmetric cipher
Modern symmetric cipherModern symmetric cipher
Modern symmetric cipher
 
Unit 2
Unit 2Unit 2
Unit 2
 
Ch03 block-cipher-and-data-encryption-standard
Ch03 block-cipher-and-data-encryption-standardCh03 block-cipher-and-data-encryption-standard
Ch03 block-cipher-and-data-encryption-standard
 
Sunanda cryptography ppt
Sunanda cryptography pptSunanda cryptography ppt
Sunanda cryptography ppt
 
Network security Encryption
Network security EncryptionNetwork security Encryption
Network security Encryption
 
Design and Simulation Triple-DES
Design and Simulation Triple-DESDesign and Simulation Triple-DES
Design and Simulation Triple-DES
 
Stream ciphers presentation
Stream ciphers presentationStream ciphers presentation
Stream ciphers presentation
 
A study of cryptography for satellite applications
A study of cryptography for satellite applicationsA study of cryptography for satellite applications
A study of cryptography for satellite applications
 

Similaire à Introduction to encryption

Cryptography
CryptographyCryptography
Cryptography
Rohan04
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
James Wong
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
Young Alista
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
David Hoen
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
Tony Nguyen
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
Luis Goldster
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
Fraboni Ec
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developers
Kai Koenig
 

Similaire à Introduction to encryption (20)

Cryptography
CryptographyCryptography
Cryptography
 
Cryptography - A Brief History
Cryptography - A Brief HistoryCryptography - A Brief History
Cryptography - A Brief History
 
Day5
Day5Day5
Day5
 
Encryption
EncryptionEncryption
Encryption
 
Jaimin chp-8 - network security-new -use this - 2011 batch
Jaimin   chp-8 - network security-new -use this -  2011 batchJaimin   chp-8 - network security-new -use this -  2011 batch
Jaimin chp-8 - network security-new -use this - 2011 batch
 
Cryptography - An Overview
Cryptography - An OverviewCryptography - An Overview
Cryptography - An Overview
 
AWS re:Invent 2016: Encryption: It Was the Best of Controls, It Was the Worst...
AWS re:Invent 2016: Encryption: It Was the Best of Controls, It Was the Worst...AWS re:Invent 2016: Encryption: It Was the Best of Controls, It Was the Worst...
AWS re:Invent 2016: Encryption: It Was the Best of Controls, It Was the Worst...
 
Iss lecture 2
Iss lecture 2Iss lecture 2
Iss lecture 2
 
Cryptography
CryptographyCryptography
Cryptography
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
 
Introduction to security_and_crypto
Introduction to security_and_cryptoIntroduction to security_and_crypto
Introduction to security_and_crypto
 
Go paranoid
Go paranoidGo paranoid
Go paranoid
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developers
 
Ch02...1
Ch02...1Ch02...1
Ch02...1
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Introduction to encryption

Notes de l'éditeur

  1. Because it’s basically about encoding the data into a format your enemy cannot understand.
  2. Symmettric and Asymmetric encryption is different.
  3. Using a 26 letter alphabet there are 26! Combinations = 2^88 or 88bits
  4. The PT Boat incident.Kennedy’s message gave away the position of the boat and their pick up times.Wheatston & palmerston
  5. Very fast encoding and decoding – but the length of the key makes it impractical. It’s as difficult to transmit the key as the plaintext message.WEP 802.11b is bad crypto – it’s keyspace is exhausted so it’s effectively 2 time pad.IV is 24bit so it recycles after 16million data packetsWorse still it resets to zero each time the router reboots.
  6. Key is very longSharing the Key s difficultSharing the key is as insecure as sharing the messageMessages should never repeatMessages with known portions are prone to being tampered with“nothing to report”
  7. A German in the desert consistently sent the message Nothing to reportKnown plain text + intercepted cipher text meant they could figure out the machine settings for the day
  8. XOR makes hardware encoding really fast and simplegenerally convert plain text messages to HEX pairs and XOR those pairs (perhaps via binary)The XOR rule above is WHY we cannot have a two time PADXOR +XOR = original text
  9. Hopefully one of the only formula’s you’ll encounter tonightBasically Decrypt(encrypted message) = message
  10. The One Time pad is a stream cipherStream ciphers use a small key but PAD it out to the required length with Pseudo randomnessStream ciphers are fast and commonly used by hardware systems – e.g. DVD encryption, GSM phones, Bluetooth all use stream ciphersRC4 (1987) is a common stream cipher encrypts 1 byte per roundDVD Encryption uses CSS (Code scrambling system)Salsa 20 is a modern stream cipher – process 5 x faster than RC4Block ciphers are the workhorse of modern encryptionExamples includes 3DES (64bit blocks) and key is 168 bitAES (128 bit blocks) key is 128,192 or 256 bitKey is expanded into one key per blockEncryption of block one is fed into block two and so on….Block ciphers are much slower than stream ciphers SLOWER is BETTERI’ll do a few definitions only.
  11. Pseudo random keys are generated by PRGsA PRG uses a PRF A PRP is an invertible PRFAll PRPs are PRFsNOT all PRFs are PRPs some are non invertiblePRG – Stream CipherPRP = Block CipherA PRP is used by Block ciphers – not stream ciphers - think AES, 3DES etc
  12. Small keys are EXPANDED by the PRG to form a ONE TIME PAD key of the required length.
  13. DES used for cheque clearing and many other legacy banking systems.AES is Advanced Encryption Standard.Developed by Horst Fiestel in 1970s3DES tripled the workload time2DES is useless as it is prone to a meet in the middle attack
  14. Used by DES, 3DES and Blowfish among othersTakes a *secure* PRF (non invertible) and makes it Efficiently invertble after 3 rounds.DES uses 16 rounds.TODO Small PHP script to demonstrate – add to gist - ? TODO
  15. Substituion permutation layersKey XOR inputByte substitutionShift rowMix columnXOR with next key loop
  16. Timing AttacksPower AttacksSound AttacksReplay attacks – resend a scrambled signal – could result in a duplicate web order
  17. Electronic Code book sometimes falls foul of two time padSematic security says that cipher text tells you NOTHING about plain textBut in ECB if block n == block m then those two cipher texts are identicalEach block is encoded separately and independently of the others.
  18. CBC gets over the short comings of ECB by feeding the results of one block into the intiialisation of the next block
  19. Turns a Block Cipher into Stream CipherThe initalisation vector in this instance is eth Nonce + The CounterEach block differs from previous one due to eth counter – but not dependant on the previous blockYou can decrypt block independently of each other, or simultaneously is you know the number of blocksHence stream cipher
  20. Most of the time when talking about encryption – we really mean hashingBecause most of the time we don’t need to decrypt only to confirm.Checking and rejecting an encrypted message based on MAC can leave you open to timing attacksIf decrypt fails or (login guessing) always add a random time interval before returning an error code.MAC also used to authenticate a message but do not provide confidentiality (Authenticated Encryption)
  21. CCA – Chosen Cipher text attackCPA – Chosen Plaintext AttackAlways use hmac() in your own code.hash_hmac() provides keyed hashing not JUST hashing.Authenticated Encryption is relatively new – circa 2000
  22. Physical world representation of secure communicationMathematical handshakes basically carry out the above scenario.The mathematical equivalent Public Key crypto was thought up by GCHQ employeeCliff Cocks 1973 – only declassified in 1997He worked it out in his head in 3 hours and had to remember it!!!!Source The Infinite Monkey Cage – 3rd Dec 2012 - Secret ScienceSimon Singh, Dr. Sue Back
  23. Diffie / Hellmann is the modern approved Public Key system (RSA)It’s all about prime numbers & factorsPick a large primePick a number less than the primeRaise a fixed number to the power of that number less than the prime128bit encryption has modulus size of 3072 bits256bit AES has modulus size of 15,360bits – that’s why it’s a good protocol.
  24. This is basically Diffie Hellman.
  25. Many older systems still have plain text passowrds stored
  26. Use a really long random key – Generate a random key with e.g. openssl_random_pseudo_bytes(64)Don’t reuse the same key over and over againUse a random 64bit minimum saltStore the salt along side the hashYou can store an encrypted version of the Salt with a re-usable key from your site configvars
  27. Use OPEN SSL if decryption is required.Use openssl for Public private key encryption/decryptionOpenssl_public_[en|de]cryptOpenssl_private_[en|de]crypt
  28. For versions of PHP less than 5.5 this is a good solid easy to use option
  29. Php 5.5 password_hash is a wrapper for crypt()Hashes created by crypt can be used with password_hash()By default uses bcrypt CRYPT_BLOWFISHThe $hash returned by password_hash contains the algorith, workload and salt.Retrievable with password_get_info()