Py Vegas - Tales from the crypt
-
Upload
adam-englander -
Category
Software
-
view
42 -
download
1
Transcript of Py Vegas - Tales from the crypt
Tales From the CryptA Cryptography Primer
Adam Englander, iovation
Who Am I?
What We Will Discuss
Wearegoingtotalkaboutthecommonmethodsandtermsusedforcryptographyinapplicationdevelopment.
Don’t Dwell
Donotfeelashamedbecauseyouaredoinganyofthiswrong.Justfixitmovingforward.
What Is Cryptography?
Cryptography…isthepracticeandstudyoftechniquesforsecurecommunicationinthepresenceofthirdpartiescalledadversaries. Wikipedia
My Definition of Cryptography
Cryptographyobscuresdatainsuchawaythatitisdifficultandcostlytoduplicateorreverse.
What is Good Cryptography?
Goodcryptographyhasahighlevelofentropy.Thatis,thattheencryptedorhasheddatahasalowlevelofpredictability.
Why Is Entropy Important?
Alldatahaspatterns.Ifyourencryptedorhasheddataretainsthosepatterns,itismuchlessdifficultandlesscostlytoduplicateorreverse.
Example of Poor Entropy
How To Increase Entropy•IncreaseentropybymixingincryptographicallysecurepseudorandomdataintheformofaniniFalizaFonvector(IV)orsalt
•Increaseentropywithfeedbackloops
Feedback Loop Example
Example of Good Entropy
Localized vs Global Entropy
• Highentropyonanitemisgood
• HighentropyacrossthedatasetisbeLer
• PaLernsexistacrossyourenFredatasetthatmayaidadversaries
Cryptography Types
• SymmetricKeyCryptographyusessharedsecrets
• AsymmetricKeyCryptographyusesprivate/publickeypairs
Cryptography Applications
• EncrypFon
• DigitalSignatures
• KeyDerivaFon
Encryption
• ProtecFngdatathatneedstoberecalled
• CanbereversedviadecrypFon
Digital Signature
• UsedtoverifyauthenFcityofdata
• Usedmostlyfordatatransfer
• CannotbereversedbutcanbereproducedforverificaFon
Key Derivation
• A.K.A.passwordhashing
• Cannotbereversed
• ComputaFonallyexpensivebydesign
Symmetric Key Cryptography
Symmetric Key Cryptography
• Sharedsecrets
• Usescipheralgorithmsagainstblocksorstreamsofdata
• MostimplementaFonswilluseblock
Block Cipher Modes
• DO NOT USE Electronic Cookbook (ECB)!!!
• Cipher Block Chaining (CBC) will be the right choice for most implementations
Cipher Block Chaining (CBC)
• EnFremessageisrequiredfordecrypFon
• Fullciphertextblockisusedastheseedforthenextblock
Cipher Block Chaining (CBC)
Digital Signatures (HMAC)• Hash-basedMessageAuthenFcaFonCode(HMAC)
• Hashingcombinedwithkey
• SHA-256orbeLerispreferredtoensureuniqueness
Asymmetric Key Cryptography
Asymmetric Key Cryptography• RSAiscommonandavailable
• Usesverylargeprimeintegers
• VerycomputaFonallyexpensive
• Useskeypairstoprotectsecret
Private/Public Key Pair
• Private key can do encrypt, decrypt, sign, and verify signature
• Public key does not have enough data to decrypt or sign. Can only encrypt and verify signature
Key Size and Hash Algorithm
• Currentminimumrecommendkeysizeis2048
• SHA1isconsideredsafebutSHA-256isbeLer
Data Limitations• RSAcanonlyencryptorsigndatauptothelengthofthekeysize
• Signaturesusehashing
• Cryptoo_enmixedwithsymmetrickeycryptography
Padding• PaddingishowRSAcreatesaddiFonalentropy
• RSA_PKCS1_OAEP_PADDINGisdefaultandshouldalwaysbeused
• RSA_PKCS1_PADDINGisnotsafe
Key Derivation Functions a.k.a Password Hashing
Password Hashing
NEVERusestandardhashingfunc6onlikeMD5orSHA!
Onlyusekeyderiva6onfunc6ons!
Key Derivation• Iterates to increase cost• Iterates to increase cost• Can create cost via threads and
memory• Bigger is better!
Which KDF Should I Use• argon2iisthenewhotness
• scryptispreferred
• bcryptisacceptable
• pbkdf2canbeusedinapinch
• Nopasswordsarebest
Recommendations
Types• UseRSAasymmetrickeycryptographywhentransferringdataandAES/CBCotherwise
• MixwithAESandrandomkeys/IVspertransfer
• Usecrypto.randomBytesforrandomness
• Usebcrypt/scrypt/argon2iforpasswords
Strength
• AES:aes-256-cbc/sha256
• RSA:2048+PKCS1_OAEP/RSA-SHA256
• HashunFlithurts!