SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
October 2011




Cryptography in PHP:
use cases
Enrico Zimuel
Zend Technologies
About me
                                                      October 2011

                           • Enrico Zimuel (ezimuel)
                           • Software Engineer since 1996
                             – Assembly x86, C/C++, Java, Perl, PHP
                           • Enjoying PHP since 1999
                           • Senior PHP Engineer at Zend
                               Technologies since 2008
                           • Author of two italian books about
Email: enrico@zend.com
                               applied cryptography
                           • B.Sc. Computer Science and
                               Economics from University of
                               Pescara (Italy)
Summary
                                         October 2011




●   Cryptography in PHP
●   Some use cases:
    ●   Safe way to store passwords
    ●   Generate pseudo-random numbers
    ●   Encrypt/decrypt sensitive data
●   Demo: encrypt PHP session data
Cryptography in PHP
                     October 2011




● crypt()
● Mcrypt


● Hash


● OpenSSL
crypt()
                                   October 2011




●   One-way string hashing
●   Support strong cryptography
    ● bcrypt, sha-256, sha-512
●   PHP 5.3.0 – bcrypt support
●   PHP 5.3.2 – sha-256/512
●   Note: don't use PHP 5.3.7 (bug #55439)
Mcrypt
                                            October 2011




●   Mcrypt is an interface to the mcrypt library
●   Supports the following encryption algorithms:
    ●   3DES, ARCFOUR, BLOWFISH, CAST, DES,
        ENIGMA, GOST, IDEA (non-free), LOKI97,
        MARS, PANAMA, RIJNDAEL, RC2, RC4,
        RC6, SAFER, SERPENT, SKIPJACK, TEAN,
        TWOFISH, WAKE, XTEA
Hash
                                    October 2011




●   Enabled by default from PHP 5.1.2
●   Hash or HMAC (Hash-based Message
    Authentication Code)
●   Supported hash algorithms: MD4, MD5,
    SHA1, SHA256, SHA384, SHA512,
    RIPEMD, RIPEMD, WHIRLPOOL, GOST,
    TIGER, HAVAL, etc
OpenSSL
                                        October 2011




●   The OpenSSL extension uses the functions of
    the OpenSSL project for generation and
    verification of signatures and for sealing
    (encrypting) and opening (decrypting) data
●   Public key cryptography (RSA algorithm)
Which algorithm?
                                      October 2011




●   Some suggestions:
    ●   Symmetric encryption:
         – Blowfish / Twofish
         – Rijndael (AES, FIST 197 standard
           since 2001)
    ●   Hash: SHA-256, 384, 512
    ●   Public key: RSA
Cryptography vs. Security

                                        October 2011




●   Cryptography doesn't mean security
●   Encryption is not enough
●   Bruce Schneier quotes:
    ●   “Security is only as strong as the
        weakest link”
    ●   “Security is a process, not a product”
Cryptography vs. Security

                   October 2011
October 2011




Use cases
Use case 1: store a password

                                    October 2011




●   Scenario:
    ● Web applications with a protect area
    ● Username and password to login


●   Problem: how to safely store a password?
Hash a password
                                                      October 2011




●   Basic ideas, use of hash algorithms:
    ●   md5($password) – not secure
        –   Dictionary attack (pre-built)
    ●   md5($salt . $password) – better but still insecure
        –   Dictionary attacks:
             ● 700'000'000 passwords a second using CUDA (budget

               of 2000 $, a week)
             ● Cloud computing, 500'000'000 passwords a second

               (about $300/hour)
bcrypt
                                            October 2011




●   Better idea, use of bcrypt algorithm:
    ●   bcrypt prevent the dictionary attacks
        because is slow as hell
    ●   Based on a variant of Blowfish
    ●   Introduce a work factor, which allows you to
        determine how expensive the hash function
        will be
bcrypt in PHP
                                                         October 2011




    ●   Hash the password using bcrypt (PHP 5.3+)

$salt = substr(str_replace('+', '.',
$salt = substr(str_replace('+', '.',
               base64_encode($salt)), 0, 22);
               base64_encode($salt)), 0, 22);
$hash = crypt($password,'$2a$'.$workload.'$'.$salt);
$hash = crypt($password,'$2a$'.$workload.'$'.$salt);


●
        $salt is a random string (it is not a secret!)
●
        $workload is the bcrypt's workload (from 10 to 31)
bcrypt workload benchmark
                           $workload   time in sec
                                                 October 2011
                              10           0.1
                              11           0.2
                              12           0.4
                              13           0.7
                              14           1.5
Suggestion:
Spend ≈ 1 sec (or more)       15           3
                              16           6
                              17           12
                              18          24.3
                              19          48.7
                              20          97.3
                              21         194.3
 OS: Linux kernel 2.6.38
CPU: Intel Core2, 2.1Ghz      22         388.2
RAM: 2 GB - PHP: 5.3.6        …            …
bcrypt output
                                                October 2011




  ●   Example of bcrypt's output:
$2a$14$c2Rmc2Fka2hmamhzYWRmauBpwLLDFKNPTfmCeuMHVnMVaLatNlFZO



  ●   c2Rmc2Fka2hmamhzYWRmau is the salt
  ●   Workload: 14
  ●   Length of 60 btyes
bcrypt authentication
                                    October 2011




●   How to check if a $userpassword is valid
    for a $hash value?

if ($hash==crypt($userpassword,$hash)) {
 if ($hash==crypt($userpassword,$hash)) {
   echo 'The password is correct';
    echo 'The password is correct';
} else {
 } else {
   echo 'The password is not correct!';
    echo 'The password is not correct!';
}}
Use case 2: generate random
            data in PHP
                                    October 2011




●   Scenario:
    ●   Generate random passwords for
         – Login systems
         – API systems
    ●   Problem: how to generate random data
        in PHP?
Random number generators
                  October 2011
PHP vs. randomness
                                         October 2011




●   How generate a pseudo-random value in PHP?
●   Not good for cryptography purpose:
    ●   rand()
    ●   mt_rand()
●   Good for cryptography (PHP 5.3+):
    ●   openssl_random_pseudo_bytes()
rand() is real random?
                                     October 2011



Pseudo-random bits   rand() in PHP on Windows




                             From random.org website
Use case 3: encrypt data
                                      October 2011




●   Scenario:
    ● We want to store some sensitive data
      (e.g. credit card numbers)
●   Problem:
    ●   How to encrypt this data in PHP?
Symmetric encryption
                                          October 2011




●   Using Mcrypt extension:
    ●
        mcrypt_encrypt(string $cipher,string $key,
        string $data,string $mode[,string $iv])
    ●
        mcrypt_decrypt(string $cipher,string $key,
        string $data,string $mode[,string $iv])
●   What are these $mode and $iv parameters?
Encryption mode
                                          October 2011




●   Symmetric encryption mode:
    ●   ECB, CBC, CFB, OFB, NOFB or STREAM
●   We are going to use the CBC that is the most
    used and secure
●   Cipher-Block Chaining (CBC) mode of operation
    was invented in 1976 by IBM
CBC
                                                             October 2011

              The Plaintext (input) is divided into blocks


         Block 1                Block 2                Block 3




                                                                       ...

         Block 1               Block 2                 Block 3


The Ciphertext (output) is the concatenation of the cipher-blocks
IV
                                               October 2011




●   Initialization Vector (IV) is a fixed-size input that
    is typically required to be random or pseudo
●   The IV is not a secret, you can send it in
    plaintext
●   Usually IV is stored before the encrypted
    message
●   Must be unique for each encrypted message
Encryption is not enough
                                               October 2011




●   We cannot use only encryption to store sensitive
    data, we need also authentication!
●   Encryption doesn't prevent alteration of data
    ●   Padding Oracle Attack (Vaudenay, EuroCrypt 2002)
●   We need to authenticate:
    ●   MAC (Message Authentication Code)
    ●   HMAC (Hash-based Message Authentication
        Code)
HMAC
                                           October 2011




●   In PHP we can generate an HMAC using the
    hash_hmac() function:

    hash_hmac ($algo, $msg, $key)

    $algo is the hash algorithm to use (e.g. sha256)
    $msg is the message
    $key is the key for the HMAC
Encryption + authentication
                                    October 2011




●   Three possible ways:
    ● Encrypt-then-authenticate
    ● Authenticate-then-encrypt


    ● Encrypt-and-authenticate


●   We will use encrypt-then-authenticate,
    as suggested by Schneier in [1]
Demo: encrypt session data

                                             October 2011




●   Specific PHP session handler to encrypt
    session data using files
●   Use of AES (Rijndael 128) + HMAC (SHA-256)
●   Pseudo-random session key
●   The encryption and authentication keys are
    stored in a cookie variable
●   Source code:
    https://github.com/ezimuel/PHP-Secure-Session
Conclusion (1)
                                            October 2011




●   Use standard algorithms for cryptography:
    ●   AES (Rijndael 128), SHA-* hash family, RSA
●   Generate random data using the function:
    ●   openssl_random_pseudo_bytes()
●   Store passwords using bcrypt:
    ●   crypt($password, '$2a$'.$workload.'$'.$salt)
Conclusion (2)
                                         October 2011




●   For symmetric encryption:
    ●   Use CBC mode with a different random IV
        for each encryption
    ●   Always authenticate the encryption data
        (using HMAC): encrypt-then-authenticate
●   Use HTTPS (SSL/TLS) to protect the
    communication client/server
References
                                                    October 2011



(1) N. Ferguson, B. Schneier, T. Kohno, “Cryptography
   Engineering”, Wiley Publishing, 2010
(2) Serge Vaudenay, “Security Flaws Induced by CBC Padding
   Applications to SSL, IPSEC, WTLS”, EuroCrypt 2002
●   Web:
    ●   PHP cryptography extensions
    ●   How to safely store a password
    ●   bcrypt algorithm
    ●   SHA-1 challenge
    ●   Nvidia CUDA
    ●   Random.org
Thank you!
                                  October 2011




●   Vote this talk:
    ●   http://joind.in/3748
●   Comments and feedbacks:
    ●   enrico@zend.com

Mais conteúdo relacionado

Mais procurados

HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developersMario Cardinal
 
GroongaでRedmineを高速全文検索
GroongaでRedmineを高速全文検索GroongaでRedmineを高速全文検索
GroongaでRedmineを高速全文検索Kouhei Sutou
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application Carlo Bonamico
 
ある工場のRedmine
ある工場のRedmineある工場のRedmine
ある工場のRedmineKohei Nakamura
 
Level Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege EscalationLevel Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege Escalationjakx_
 
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法NGINX, Inc.
 
20120711 WUM Redmineの使い道_公開版
20120711 WUM Redmineの使い道_公開版20120711 WUM Redmineの使い道_公開版
20120711 WUM Redmineの使い道_公開版Yu Nakata
 
PPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみよう
PPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみようPPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみよう
PPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみようDaisuke Masubuchi
 
Go 製リアルタイムサーバーの Kubernetes での運用について
Go 製リアルタイムサーバーの  Kubernetes での運用についてGo 製リアルタイムサーバーの  Kubernetes での運用について
Go 製リアルタイムサーバーの Kubernetes での運用についてKairiOkumura
 
細かすぎて伝わらないD3 ver.4の話
細かすぎて伝わらないD3 ver.4の話細かすぎて伝わらないD3 ver.4の話
細かすぎて伝わらないD3 ver.4の話清水 正行
 
IDA Vulnerabilities and Bug Bounty  by Masaaki Chida
IDA Vulnerabilities and Bug Bounty  by Masaaki ChidaIDA Vulnerabilities and Bug Bounty  by Masaaki Chida
IDA Vulnerabilities and Bug Bounty  by Masaaki ChidaCODE BLUE
 
DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]
DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]
DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]DeNA
 
OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014
OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014
OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014Leonardo Nve Egea
 
BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...
BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...
BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...Benjamin Delpy
 
Killzone Shadow Fall: Creating Art Tools For A New Generation Of Games
Killzone Shadow Fall: Creating Art Tools For A New Generation Of GamesKillzone Shadow Fall: Creating Art Tools For A New Generation Of Games
Killzone Shadow Fall: Creating Art Tools For A New Generation Of GamesGuerrilla
 
MCC CTF講習会 pwn編
MCC CTF講習会 pwn編MCC CTF講習会 pwn編
MCC CTF講習会 pwn編hama7230
 
遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)
遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)
遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)Kuniyasu Suzaki
 
State-Based Scripting in Uncharted 2: Among Thieves
State-Based Scripting in Uncharted 2: Among ThievesState-Based Scripting in Uncharted 2: Among Thieves
State-Based Scripting in Uncharted 2: Among ThievesNaughty Dog
 
Ansibleの実行速度を1/3にした話
Ansibleの実行速度を1/3にした話Ansibleの実行速度を1/3にした話
Ansibleの実行速度を1/3にした話KeijiUehata1
 
.NET 7期待の新機能
.NET 7期待の新機能.NET 7期待の新機能
.NET 7期待の新機能TomomitsuKusaba
 

Mais procurados (20)

HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developers
 
GroongaでRedmineを高速全文検索
GroongaでRedmineを高速全文検索GroongaでRedmineを高速全文検索
GroongaでRedmineを高速全文検索
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application
 
ある工場のRedmine
ある工場のRedmineある工場のRedmine
ある工場のRedmine
 
Level Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege EscalationLevel Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege Escalation
 
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
 
20120711 WUM Redmineの使い道_公開版
20120711 WUM Redmineの使い道_公開版20120711 WUM Redmineの使い道_公開版
20120711 WUM Redmineの使い道_公開版
 
PPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみよう
PPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみようPPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみよう
PPT Full version: 世界中のゲーム分析をしてきたPlayFabが大進化!一緒に裏側の最新データ探索の仕組みを覗いてみよう
 
Go 製リアルタイムサーバーの Kubernetes での運用について
Go 製リアルタイムサーバーの  Kubernetes での運用についてGo 製リアルタイムサーバーの  Kubernetes での運用について
Go 製リアルタイムサーバーの Kubernetes での運用について
 
細かすぎて伝わらないD3 ver.4の話
細かすぎて伝わらないD3 ver.4の話細かすぎて伝わらないD3 ver.4の話
細かすぎて伝わらないD3 ver.4の話
 
IDA Vulnerabilities and Bug Bounty  by Masaaki Chida
IDA Vulnerabilities and Bug Bounty  by Masaaki ChidaIDA Vulnerabilities and Bug Bounty  by Masaaki Chida
IDA Vulnerabilities and Bug Bounty  by Masaaki Chida
 
DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]
DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]
DeNAにおけるCorpTechエンジニアリング [DeNA TechCon 2019]
 
OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014
OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014
OFFENSIVE: Exploiting DNS servers changes BlackHat Asia 2014
 
BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...
BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...
BlueHat 2014 - The Attacker's View of Windows Authentication and Post Exploit...
 
Killzone Shadow Fall: Creating Art Tools For A New Generation Of Games
Killzone Shadow Fall: Creating Art Tools For A New Generation Of GamesKillzone Shadow Fall: Creating Art Tools For A New Generation Of Games
Killzone Shadow Fall: Creating Art Tools For A New Generation Of Games
 
MCC CTF講習会 pwn編
MCC CTF講習会 pwn編MCC CTF講習会 pwn編
MCC CTF講習会 pwn編
 
遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)
遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)
遠隔デバイスとの信頼を築くための技術とその標準(TEEP RATS)
 
State-Based Scripting in Uncharted 2: Among Thieves
State-Based Scripting in Uncharted 2: Among ThievesState-Based Scripting in Uncharted 2: Among Thieves
State-Based Scripting in Uncharted 2: Among Thieves
 
Ansibleの実行速度を1/3にした話
Ansibleの実行速度を1/3にした話Ansibleの実行速度を1/3にした話
Ansibleの実行速度を1/3にした話
 
.NET 7期待の新機能
.NET 7期待の新機能.NET 7期待の新機能
.NET 7期待の新機能
 

Semelhante a Cryptography in PHP: use cases

Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroTal Shmueli
 
Password (in)security
Password (in)securityPassword (in)security
Password (in)securityEnrico Zimuel
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHPEnrico Zimuel
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamCodemotion
 
Redis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRedis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRoberto Franchini
 
All Your Password Are Belong To Us
All Your Password Are Belong To UsAll Your Password Are Belong To Us
All Your Password Are Belong To UsCharles Southerland
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...Dataconomy Media
 
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESPyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESAlessandro Molina
 
Module: drand - the Distributed Randomness Beacon
Module: drand - the Distributed Randomness BeaconModule: drand - the Distributed Randomness Beacon
Module: drand - the Distributed Randomness BeaconIoannis Psaras
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend FrameworkEnrico Zimuel
 
Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2aspyker
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONLyon Yang
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNoSuchCon
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...Alexandre Moneger
 
inside-linux-kernel-rng-presentation-sept-13-2022.pdf
inside-linux-kernel-rng-presentation-sept-13-2022.pdfinside-linux-kernel-rng-presentation-sept-13-2022.pdf
inside-linux-kernel-rng-presentation-sept-13-2022.pdfxiso
 
"Developing a multicurrency, multisignature wallet" by Alex Melville
"Developing a multicurrency, multisignature wallet" by Alex Melville  "Developing a multicurrency, multisignature wallet" by Alex Melville
"Developing a multicurrency, multisignature wallet" by Alex Melville ICOVO
 
Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?Docker, Inc.
 

Semelhante a Cryptography in PHP: use cases (20)

Cryptography in PHP: Some Use Cases
Cryptography in PHP: Some Use CasesCryptography in PHP: Some Use Cases
Cryptography in PHP: Some Use Cases
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies Intro
 
Password (in)security
Password (in)securityPassword (in)security
Password (in)security
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHP
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time stream
 
Redis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRedis for duplicate detection on real time stream
Redis for duplicate detection on real time stream
 
All Your Password Are Belong To Us
All Your Password Are Belong To UsAll Your Password Are Belong To Us
All Your Password Are Belong To Us
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
 
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESPyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
 
Module: drand - the Distributed Randomness Beacon
Module: drand - the Distributed Randomness BeaconModule: drand - the Distributed Randomness Beacon
Module: drand - the Distributed Randomness Beacon
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend Framework
 
Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge Solution
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
 
inside-linux-kernel-rng-presentation-sept-13-2022.pdf
inside-linux-kernel-rng-presentation-sept-13-2022.pdfinside-linux-kernel-rng-presentation-sept-13-2022.pdf
inside-linux-kernel-rng-presentation-sept-13-2022.pdf
 
Cryptography Attacks and Applications
Cryptography Attacks and ApplicationsCryptography Attacks and Applications
Cryptography Attacks and Applications
 
"Developing a multicurrency, multisignature wallet" by Alex Melville
"Developing a multicurrency, multisignature wallet" by Alex Melville  "Developing a multicurrency, multisignature wallet" by Alex Melville
"Developing a multicurrency, multisignature wallet" by Alex Melville
 
Advances in Open Source Password Cracking
Advances in Open Source Password CrackingAdvances in Open Source Password Cracking
Advances in Open Source Password Cracking
 
Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?
 

Mais de Enrico Zimuel

Integrare Zend Framework in Wordpress
Integrare Zend Framework in WordpressIntegrare Zend Framework in Wordpress
Integrare Zend Framework in WordpressEnrico Zimuel
 
Quick start on Zend Framework 2
Quick start on Zend Framework 2Quick start on Zend Framework 2
Quick start on Zend Framework 2Enrico Zimuel
 
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheIntroduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheEnrico Zimuel
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2Enrico Zimuel
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick startEnrico Zimuel
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Enrico Zimuel
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Enrico Zimuel
 
Framework software e Zend Framework
Framework software e Zend FrameworkFramework software e Zend Framework
Framework software e Zend FrameworkEnrico Zimuel
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applicationsEnrico Zimuel
 
Velocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community EditionVelocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community EditionEnrico Zimuel
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsEnrico Zimuel
 
XCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsXCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsEnrico Zimuel
 
Introduzione alle tabelle hash
Introduzione alle tabelle hashIntroduzione alle tabelle hash
Introduzione alle tabelle hashEnrico Zimuel
 
Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Enrico Zimuel
 
Introduzione alla crittografia
Introduzione alla crittografiaIntroduzione alla crittografia
Introduzione alla crittografiaEnrico Zimuel
 
Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Enrico Zimuel
 
Sviluppo di applicazioni sicure
Sviluppo di applicazioni sicureSviluppo di applicazioni sicure
Sviluppo di applicazioni sicureEnrico Zimuel
 
Misure minime di sicurezza informatica
Misure minime di sicurezza informaticaMisure minime di sicurezza informatica
Misure minime di sicurezza informaticaEnrico Zimuel
 

Mais de Enrico Zimuel (20)

Integrare Zend Framework in Wordpress
Integrare Zend Framework in WordpressIntegrare Zend Framework in Wordpress
Integrare Zend Framework in Wordpress
 
Quick start on Zend Framework 2
Quick start on Zend Framework 2Quick start on Zend Framework 2
Quick start on Zend Framework 2
 
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecnicheIntroduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick start
 
PHP goes mobile
PHP goes mobilePHP goes mobile
PHP goes mobile
 
Zend Framework 2
Zend Framework 2Zend Framework 2
Zend Framework 2
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
 
Framework software e Zend Framework
Framework software e Zend FrameworkFramework software e Zend Framework
Framework software e Zend Framework
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
 
Velocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community EditionVelocizzare Joomla! con Zend Server Community Edition
Velocizzare Joomla! con Zend Server Community Edition
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applications
 
XCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processorsXCheck a benchmark checker for XML query processors
XCheck a benchmark checker for XML query processors
 
Introduzione alle tabelle hash
Introduzione alle tabelle hashIntroduzione alle tabelle hash
Introduzione alle tabelle hash
 
Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?Crittografia quantistica: fantascienza o realtà?
Crittografia quantistica: fantascienza o realtà?
 
Introduzione alla crittografia
Introduzione alla crittografiaIntroduzione alla crittografia
Introduzione alla crittografia
 
Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?Crittografia è sinonimo di sicurezza?
Crittografia è sinonimo di sicurezza?
 
Sviluppo di applicazioni sicure
Sviluppo di applicazioni sicureSviluppo di applicazioni sicure
Sviluppo di applicazioni sicure
 
Misure minime di sicurezza informatica
Misure minime di sicurezza informaticaMisure minime di sicurezza informatica
Misure minime di sicurezza informatica
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
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 2024The Digital Insurer
 
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 businesspanagenda
 
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 2024The Digital Insurer
 
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 Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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 SavingEdi Saputra
 
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 CVKhem
 
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 StreamsRoshan Dwivedi
 
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 WoodJuan lago vázquez
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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 educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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 DevelopmentsTrustArc
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
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
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 

Cryptography in PHP: use cases

  • 1. October 2011 Cryptography in PHP: use cases Enrico Zimuel Zend Technologies
  • 2. About me October 2011 • Enrico Zimuel (ezimuel) • Software Engineer since 1996 – Assembly x86, C/C++, Java, Perl, PHP • Enjoying PHP since 1999 • Senior PHP Engineer at Zend Technologies since 2008 • Author of two italian books about Email: enrico@zend.com applied cryptography • B.Sc. Computer Science and Economics from University of Pescara (Italy)
  • 3. Summary October 2011 ● Cryptography in PHP ● Some use cases: ● Safe way to store passwords ● Generate pseudo-random numbers ● Encrypt/decrypt sensitive data ● Demo: encrypt PHP session data
  • 4. Cryptography in PHP October 2011 ● crypt() ● Mcrypt ● Hash ● OpenSSL
  • 5. crypt() October 2011 ● One-way string hashing ● Support strong cryptography ● bcrypt, sha-256, sha-512 ● PHP 5.3.0 – bcrypt support ● PHP 5.3.2 – sha-256/512 ● Note: don't use PHP 5.3.7 (bug #55439)
  • 6. Mcrypt October 2011 ● Mcrypt is an interface to the mcrypt library ● Supports the following encryption algorithms: ● 3DES, ARCFOUR, BLOWFISH, CAST, DES, ENIGMA, GOST, IDEA (non-free), LOKI97, MARS, PANAMA, RIJNDAEL, RC2, RC4, RC6, SAFER, SERPENT, SKIPJACK, TEAN, TWOFISH, WAKE, XTEA
  • 7. Hash October 2011 ● Enabled by default from PHP 5.1.2 ● Hash or HMAC (Hash-based Message Authentication Code) ● Supported hash algorithms: MD4, MD5, SHA1, SHA256, SHA384, SHA512, RIPEMD, RIPEMD, WHIRLPOOL, GOST, TIGER, HAVAL, etc
  • 8. OpenSSL October 2011 ● The OpenSSL extension uses the functions of the OpenSSL project for generation and verification of signatures and for sealing (encrypting) and opening (decrypting) data ● Public key cryptography (RSA algorithm)
  • 9. Which algorithm? October 2011 ● Some suggestions: ● Symmetric encryption: – Blowfish / Twofish – Rijndael (AES, FIST 197 standard since 2001) ● Hash: SHA-256, 384, 512 ● Public key: RSA
  • 10. Cryptography vs. Security October 2011 ● Cryptography doesn't mean security ● Encryption is not enough ● Bruce Schneier quotes: ● “Security is only as strong as the weakest link” ● “Security is a process, not a product”
  • 13. Use case 1: store a password October 2011 ● Scenario: ● Web applications with a protect area ● Username and password to login ● Problem: how to safely store a password?
  • 14. Hash a password October 2011 ● Basic ideas, use of hash algorithms: ● md5($password) – not secure – Dictionary attack (pre-built) ● md5($salt . $password) – better but still insecure – Dictionary attacks: ● 700'000'000 passwords a second using CUDA (budget of 2000 $, a week) ● Cloud computing, 500'000'000 passwords a second (about $300/hour)
  • 15. bcrypt October 2011 ● Better idea, use of bcrypt algorithm: ● bcrypt prevent the dictionary attacks because is slow as hell ● Based on a variant of Blowfish ● Introduce a work factor, which allows you to determine how expensive the hash function will be
  • 16. bcrypt in PHP October 2011 ● Hash the password using bcrypt (PHP 5.3+) $salt = substr(str_replace('+', '.', $salt = substr(str_replace('+', '.', base64_encode($salt)), 0, 22); base64_encode($salt)), 0, 22); $hash = crypt($password,'$2a$'.$workload.'$'.$salt); $hash = crypt($password,'$2a$'.$workload.'$'.$salt); ● $salt is a random string (it is not a secret!) ● $workload is the bcrypt's workload (from 10 to 31)
  • 17. bcrypt workload benchmark $workload time in sec October 2011 10 0.1 11 0.2 12 0.4 13 0.7 14 1.5 Suggestion: Spend ≈ 1 sec (or more) 15 3 16 6 17 12 18 24.3 19 48.7 20 97.3 21 194.3 OS: Linux kernel 2.6.38 CPU: Intel Core2, 2.1Ghz 22 388.2 RAM: 2 GB - PHP: 5.3.6 … …
  • 18. bcrypt output October 2011 ● Example of bcrypt's output: $2a$14$c2Rmc2Fka2hmamhzYWRmauBpwLLDFKNPTfmCeuMHVnMVaLatNlFZO ● c2Rmc2Fka2hmamhzYWRmau is the salt ● Workload: 14 ● Length of 60 btyes
  • 19. bcrypt authentication October 2011 ● How to check if a $userpassword is valid for a $hash value? if ($hash==crypt($userpassword,$hash)) { if ($hash==crypt($userpassword,$hash)) { echo 'The password is correct'; echo 'The password is correct'; } else { } else { echo 'The password is not correct!'; echo 'The password is not correct!'; }}
  • 20. Use case 2: generate random data in PHP October 2011 ● Scenario: ● Generate random passwords for – Login systems – API systems ● Problem: how to generate random data in PHP?
  • 21. Random number generators October 2011
  • 22. PHP vs. randomness October 2011 ● How generate a pseudo-random value in PHP? ● Not good for cryptography purpose: ● rand() ● mt_rand() ● Good for cryptography (PHP 5.3+): ● openssl_random_pseudo_bytes()
  • 23. rand() is real random? October 2011 Pseudo-random bits rand() in PHP on Windows From random.org website
  • 24. Use case 3: encrypt data October 2011 ● Scenario: ● We want to store some sensitive data (e.g. credit card numbers) ● Problem: ● How to encrypt this data in PHP?
  • 25. Symmetric encryption October 2011 ● Using Mcrypt extension: ● mcrypt_encrypt(string $cipher,string $key, string $data,string $mode[,string $iv]) ● mcrypt_decrypt(string $cipher,string $key, string $data,string $mode[,string $iv]) ● What are these $mode and $iv parameters?
  • 26. Encryption mode October 2011 ● Symmetric encryption mode: ● ECB, CBC, CFB, OFB, NOFB or STREAM ● We are going to use the CBC that is the most used and secure ● Cipher-Block Chaining (CBC) mode of operation was invented in 1976 by IBM
  • 27. CBC October 2011 The Plaintext (input) is divided into blocks Block 1 Block 2 Block 3 ... Block 1 Block 2 Block 3 The Ciphertext (output) is the concatenation of the cipher-blocks
  • 28. IV October 2011 ● Initialization Vector (IV) is a fixed-size input that is typically required to be random or pseudo ● The IV is not a secret, you can send it in plaintext ● Usually IV is stored before the encrypted message ● Must be unique for each encrypted message
  • 29. Encryption is not enough October 2011 ● We cannot use only encryption to store sensitive data, we need also authentication! ● Encryption doesn't prevent alteration of data ● Padding Oracle Attack (Vaudenay, EuroCrypt 2002) ● We need to authenticate: ● MAC (Message Authentication Code) ● HMAC (Hash-based Message Authentication Code)
  • 30. HMAC October 2011 ● In PHP we can generate an HMAC using the hash_hmac() function: hash_hmac ($algo, $msg, $key) $algo is the hash algorithm to use (e.g. sha256) $msg is the message $key is the key for the HMAC
  • 31. Encryption + authentication October 2011 ● Three possible ways: ● Encrypt-then-authenticate ● Authenticate-then-encrypt ● Encrypt-and-authenticate ● We will use encrypt-then-authenticate, as suggested by Schneier in [1]
  • 32. Demo: encrypt session data October 2011 ● Specific PHP session handler to encrypt session data using files ● Use of AES (Rijndael 128) + HMAC (SHA-256) ● Pseudo-random session key ● The encryption and authentication keys are stored in a cookie variable ● Source code: https://github.com/ezimuel/PHP-Secure-Session
  • 33. Conclusion (1) October 2011 ● Use standard algorithms for cryptography: ● AES (Rijndael 128), SHA-* hash family, RSA ● Generate random data using the function: ● openssl_random_pseudo_bytes() ● Store passwords using bcrypt: ● crypt($password, '$2a$'.$workload.'$'.$salt)
  • 34. Conclusion (2) October 2011 ● For symmetric encryption: ● Use CBC mode with a different random IV for each encryption ● Always authenticate the encryption data (using HMAC): encrypt-then-authenticate ● Use HTTPS (SSL/TLS) to protect the communication client/server
  • 35. References October 2011 (1) N. Ferguson, B. Schneier, T. Kohno, “Cryptography Engineering”, Wiley Publishing, 2010 (2) Serge Vaudenay, “Security Flaws Induced by CBC Padding Applications to SSL, IPSEC, WTLS”, EuroCrypt 2002 ● Web: ● PHP cryptography extensions ● How to safely store a password ● bcrypt algorithm ● SHA-1 challenge ● Nvidia CUDA ● Random.org
  • 36. Thank you! October 2011 ● Vote this talk: ● http://joind.in/3748 ● Comments and feedbacks: ● enrico@zend.com