Py Vegas - Tales from the crypt

37
Tales From the Crypt A Cryptography Primer Adam Englander, iovation

Transcript of Py Vegas - Tales from the crypt

Page 1: Py Vegas - Tales from the crypt

Tales From the CryptA Cryptography Primer

Adam Englander, iovation

Page 2: Py Vegas - Tales from the crypt

Who Am I?

Page 3: Py Vegas - Tales from the crypt

What We Will Discuss

Wearegoingtotalkaboutthecommonmethodsandtermsusedforcryptographyinapplicationdevelopment.

Page 4: Py Vegas - Tales from the crypt

Don’t Dwell

Donotfeelashamedbecauseyouaredoinganyofthiswrong.Justfixitmovingforward.

Page 5: Py Vegas - Tales from the crypt

What Is Cryptography?

Cryptography…isthepracticeandstudyoftechniquesforsecurecommunicationinthepresenceofthirdpartiescalledadversaries. Wikipedia

Page 6: Py Vegas - Tales from the crypt

My Definition of Cryptography

Cryptographyobscuresdatainsuchawaythatitisdifficultandcostlytoduplicateorreverse.

Page 7: Py Vegas - Tales from the crypt

What is Good Cryptography?

Goodcryptographyhasahighlevelofentropy.Thatis,thattheencryptedorhasheddatahasalowlevelofpredictability.

Page 8: Py Vegas - Tales from the crypt

Why Is Entropy Important?

Alldatahaspatterns.Ifyourencryptedorhasheddataretainsthosepatterns,itismuchlessdifficultandlesscostlytoduplicateorreverse.

Page 9: Py Vegas - Tales from the crypt

Example of Poor Entropy

Page 10: Py Vegas - Tales from the crypt

How To Increase Entropy•IncreaseentropybymixingincryptographicallysecurepseudorandomdataintheformofaniniFalizaFonvector(IV)orsalt

•Increaseentropywithfeedbackloops

Page 11: Py Vegas - Tales from the crypt

Feedback Loop Example

Page 12: Py Vegas - Tales from the crypt

Example of Good Entropy

Page 13: Py Vegas - Tales from the crypt

Localized vs Global Entropy

• Highentropyonanitemisgood

• HighentropyacrossthedatasetisbeLer

• PaLernsexistacrossyourenFredatasetthatmayaidadversaries

Page 14: Py Vegas - Tales from the crypt

Cryptography Types

• SymmetricKeyCryptographyusessharedsecrets

• AsymmetricKeyCryptographyusesprivate/publickeypairs

Page 15: Py Vegas - Tales from the crypt

Cryptography Applications

• EncrypFon

• DigitalSignatures

• KeyDerivaFon

Page 16: Py Vegas - Tales from the crypt

Encryption

• ProtecFngdatathatneedstoberecalled

• CanbereversedviadecrypFon

Page 17: Py Vegas - Tales from the crypt

Digital Signature

• UsedtoverifyauthenFcityofdata

• Usedmostlyfordatatransfer

• CannotbereversedbutcanbereproducedforverificaFon

Page 18: Py Vegas - Tales from the crypt

Key Derivation

• A.K.A.passwordhashing

• Cannotbereversed

• ComputaFonallyexpensivebydesign

Page 19: Py Vegas - Tales from the crypt

Symmetric Key Cryptography

Page 20: Py Vegas - Tales from the crypt

Symmetric Key Cryptography

• Sharedsecrets

• Usescipheralgorithmsagainstblocksorstreamsofdata

• MostimplementaFonswilluseblock

Page 21: Py Vegas - Tales from the crypt

Block Cipher Modes

• DO NOT USE Electronic Cookbook (ECB)!!!

• Cipher Block Chaining (CBC) will be the right choice for most implementations

Page 22: Py Vegas - Tales from the crypt

Cipher Block Chaining (CBC)

• EnFremessageisrequiredfordecrypFon

• Fullciphertextblockisusedastheseedforthenextblock

Page 23: Py Vegas - Tales from the crypt

Cipher Block Chaining (CBC)

Page 24: Py Vegas - Tales from the crypt

Digital Signatures (HMAC)• Hash-basedMessageAuthenFcaFonCode(HMAC)

• Hashingcombinedwithkey

• SHA-256orbeLerispreferredtoensureuniqueness

Page 25: Py Vegas - Tales from the crypt

Asymmetric Key Cryptography

Page 26: Py Vegas - Tales from the crypt

Asymmetric Key Cryptography• RSAiscommonandavailable

• Usesverylargeprimeintegers

• VerycomputaFonallyexpensive

• Useskeypairstoprotectsecret

Page 27: Py Vegas - Tales from the crypt

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

Page 28: Py Vegas - Tales from the crypt

Key Size and Hash Algorithm

• Currentminimumrecommendkeysizeis2048

• SHA1isconsideredsafebutSHA-256isbeLer

Page 29: Py Vegas - Tales from the crypt

Data Limitations• RSAcanonlyencryptorsigndatauptothelengthofthekeysize

• Signaturesusehashing

• Cryptoo_enmixedwithsymmetrickeycryptography

Page 30: Py Vegas - Tales from the crypt

Padding• PaddingishowRSAcreatesaddiFonalentropy

• RSA_PKCS1_OAEP_PADDINGisdefaultandshouldalwaysbeused

• RSA_PKCS1_PADDINGisnotsafe

Page 31: Py Vegas - Tales from the crypt

Key Derivation Functions a.k.a Password Hashing

Page 32: Py Vegas - Tales from the crypt

Password Hashing

NEVERusestandardhashingfunc6onlikeMD5orSHA!

Onlyusekeyderiva6onfunc6ons!

Page 33: Py Vegas - Tales from the crypt

Key Derivation• Iterates to increase cost• Iterates to increase cost• Can create cost via threads and

memory• Bigger is better!

Page 34: Py Vegas - Tales from the crypt

Which KDF Should I Use• argon2iisthenewhotness

• scryptispreferred

• bcryptisacceptable

• pbkdf2canbeusedinapinch

• Nopasswordsarebest

Page 35: Py Vegas - Tales from the crypt

Recommendations

Page 36: Py Vegas - Tales from the crypt

Types• UseRSAasymmetrickeycryptographywhentransferringdataandAES/CBCotherwise

• MixwithAESandrandomkeys/IVspertransfer

• Usecrypto.randomBytesforrandomness

• Usebcrypt/scrypt/argon2iforpasswords

Page 37: Py Vegas - Tales from the crypt

Strength

• AES:aes-256-cbc/sha256

• RSA:2048+PKCS1_OAEP/RSA-SHA256

• HashunFlithurts!