Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Stories from the crypt(ography)

Stories from the crypt(ography)

Marcin Krzyzanowski

November 17, 2018
Tweet

More Decks by Marcin Krzyzanowski

Other Decks in Technology

Transcript

  1. There were some useful mentions about crypto, that I've never

    heard before. But it wasn't so completed as I expected
  2. , Loren lpsum " STRING @x4CyOx6Fi0x72y0x65i0x6D.i . . ) BYTES

    £iorI , . . . . Bits 1001100 w a t t t d MyENCRypt
  3. MyENCRypt 1 t I t yinnoonn , . . .

    Bits d to [0×73 , OxcD] BYTES
  4. 1 t I t yinnoonn , . . . Bits

    d to [0×73 , OxcD] BYTES i. STRING ? NULL
  5. ENCRYPTION in cryptography, the one-time pad (OTP) is an encryption

    technique (cipher) that cannot be cracked, but requires the use of a one-time pre-shared key the same size as, or longer than, the message being sent. key A T e 5 1 / b J { z q C G plaintext L O R E M I P S U M L O R ciphertext 0x12 0xA 0x9F 0x1 0xFF 0x41 0xB 0x97 0x6A 0xA 0xBB 0x3 0x67
  6. CCCrypt(kCCEncrypt, kCCAlgorithmAES128, // Algorithm kCCOptionPKCS7Padding, // Padding key.bytes, // Key

    key.length, // keylength iv.bytes,// IV (NULL) data.bytes, // dataIn data.length, // dataInLength, cipherData.mutableBytes, // dataOut cipherData.length, // dataOutAvailable &outLength); // dataOutMoved COMMONCRYPTO
  7. COMMONCRYPTO CCCrypt(_ op: CCOperation, _ alg: CCAlgorithm, _ options: CCOptions,

    _ key: UnsafeRawPointer!, _ keyLength: Int, _ iv: UnsafeRawPointer!, _ dataIn: UnsafeRawPointer!, _ dataInLength: Int, _ dataOut: UnsafeMutableRawPointer!, _ dataOutAvailable: Int, _ dataOutMoved: UnsafeMutablePointer<Int>!) -> CCCryptorStatus
  8. CCCryptorCreateWithMode(kCCEncrypt, kCCModeCBC, // Block mode kCCAlgorithmAES128, // Algorithm kCCOptionPKCS7Padding, //

    Padding iv.bytes, // IV (OR NULL) key.bytes, // Key key.length, NULL, 0, 0, 0, &cryptor) COMMONCRYPTO
  9. AES ADVANCED ENCRYPTION STANDARD MyENCRypt 1 t I t yinnoonn

    , . . . Bits d to [0×73 , OxcD] BYTES CIPHER
  10. CIPHER BLOCK MODE ... CTR counter mode CCM counter with

    CBC OFB output feedback GCM Galois/Counter Mode
  11. IV IS PUBLIC INITIALIZATIONVECTORCIPHERTEXT NONCE - In cryptography, a nonce

    is an arbitrary number that can be used just once
  12. CCCrypt(kCCEncrypt, kCCAlgorithmAES128, // Algorithm kCCOptionPKCS7Padding, // Padding key.bytes, // Key

    key.length, // keylength NULL, // IV data.bytes, // dataIn data.length, // dataInLength, cipherData.mutableBytes, // dataOut cipherData.length, // dataOutAvailable &outLength); // dataOutMoved COMMONCRYPTO CBC If no IV is provided, an IV of all zeroes will be used.
  13. PKCS5 / PKCS7 PADDING T E X T ? ?

    ? ? ? ? ? ? ? ? ? ? T E X T 12 12 12 12 12 12 12 12 12 12 12 12
  14. Zero Padding PADDING T E X T ? ? ?

    ? ? ? ? ? ? ? ? ? T E X T 0 0 0 0 0 0 0 0 0 0 0 0
  15. CIPHER BLOCK MODE CTR counter mode CCM counter with CBC

    OFB output feedback GCM Galois/Counter Mode no padding no padding no padding no padding
  16. Padding Oracle Attack plaintext dec(Ci) XX XX XX XX XX

    XX XX XX Ci-1 AB 1 4F 21 0 7C 2 9E encoded data XX XX XX XX XX XX XX XX ⊕ =
  17. SUCCESS Padding Oracle Attack plaintext dec(Ci) XX XX XX XX

    XX XX XX XX Ci-1 ZZ ZZ 4F 21 0 7C 2 9E encoded data YY YZ XX XX XX XX XX XX ⊕ =
  18. ERROR Padding Oracle Attack plaintext dec(Ci) XX XX XX XX

    XX XX XX XX Ci-1 ZZ ZZ ZZ 21 0 7C 2 9E encoded data YY YZ ZY XX XX XX XX XX ⊕ =
  19. Padding Oracle Attack plaintext dec(Ci) XX XX XX XX XX

    XX XX XX Ci-1 AB 1 4F 21 0 7C 2 9E encoded data XX XX 6 6 6 6 6 6 SUCCESS ⊕ =
  20. Padding Oracle Attack plaintext dec(Ci) XX XX XX XX XX

    XX XX XX C'i-1 AB 1 4F 21 0 7C 2 9F encoded data XX 7 7 7 7 7 7 7 ERROR 0x9E ⊕ 0x06 ⊕ 0x07 ⊕ =
  21. Padding Oracle Attack plaintext dec(Ci) XX XX XX XX XX

    XX XX XX C'i-1 AB 0,1,2,3,.. 4E 20 1 7D 3 9F encoded data XX 7 7 7 7 7 7 7 ERROR until SUCCESS 0x9E ⊕ 0x06 ⊕ 0x07 ⊕ =
  22. Padding Oracle Attack plaintext dec(Ci) XX 47 XX XX XX

    XX XX XX Ci-1 AB ..., 41 4F 21 0 7C 2 9F encoded data XX 7 7 7 7 7 7 7 XX ⊕ 0x41 = 0x7 ⇒ XX ⊕ 0x01 = (XX ⊕ 0x41) ⊕ (0x41 ⊕ 0x7) ⇒ XX ⊕ 0x01 = 0x07 ⊕ 0x40 = 0x47 ⊕ =
  23. Padding Oracle Attack plaintext dec(Ci) XX 47 XX XX XX

    XX XX XX Ci-1 AB ..., 41 4F 21 0 7C 2 9F encoded data XX 7 7 7 7 7 7 7 XX ⊕ 0x41 = 0x7 ⇒ XX ⊕ 0x01 = (XX ⊕ 0x41) ⊕ (0x41 ⊕ 0x7) ⇒ XX ⊕ 0x01 = 0x07 ⊕ 0x40 = 0x47 ⊕ =
  24. The output is not just a raw ciphertext "IV +

    Salted__ + 8 random bytes + ciphertext"
  25. MAC

  26. AUTHENTICATE TAG A security flaw in your operating system allows

    carefully encrypted messages to be effectively decrypted offline. That’s what happened to Apple with its iOS 9.2 operating system. EVERYTHING MAC
  27. KEY EXCHANGE ASSYMETRIC CRYPTOGRAPHY Diffie–Hellman key exchange PUBLIC KEY -

    PRIVATE KEY PUBLIC KEY ENCRYPTS PRIVATE KEY DECRYPTS
  28. KEY EXCHANGE GENERATE SESSION KEY ENCRYPT SESSION KEY WITH PUBLIC

    KEY → ← DECRYPT SESSION KEY WITH PRIVATE KEY ESTABLISH AES ENCRYPTION
  29. ➤ CIPHER (STREAM OR BLOCK) ➤ CIPHER OPERATION MODE -

    CBC ➤ IV - INITIALIZATION VECTOR (NONCE) - SHOULD BE RANDOM AND USED ONCE
  30. ➤ CIPHER (STREAM OR BLOCK) ➤ CIPHER OPERATION MODE -

    CBC ➤ IV - INITIALIZATION VECTOR (NONCE) - SHOULD BE RANDOM AND USED ONCE ➤ PASSWORD IS NOT A KEY. DERIVE KEY FROM A PASSWORD
  31. ➤ CIPHER (STREAM OR BLOCK) ➤ CIPHER OPERATION MODE -

    CBC ➤ IV - INITIALIZATION VECTOR (NONCE) - SHOULD BE RANDOM AND USED ONCE ➤ PASSWORD IS NOT A KEY. DERIVE KEY FROM A PASSWORD ➤ PADDING CAN BE DANGEROUS
  32. ➤ CIPHER (STREAM OR BLOCK) ➤ CIPHER OPERATION MODE -

    CBC ➤ IV - INITIALIZATION VECTOR (NONCE) - SHOULD BE RANDOM AND USED ONCE ➤ PASSWORD IS NOT A KEY. DERIVE KEY FROM A PASSWORD ➤ PADDING CAN BE DANGEROUS ➤ AUTHENTICATE MESSAGE WITH A MAC
  33. ➤ CIPHER (STREAM OR BLOCK) ➤ CIPHER OPERATION MODE -

    CBC ➤ IV - INITIALIZATION VECTOR (NONCE) - SHOULD BE RANDOM AND USED ONCE ➤ PASSWORD IS NOT A KEY. DERIVE KEY FROM A PASSWORD ➤ PADDING CAN BE DANGEROUS ➤ AUTHENTICATE MESSAGE WITH A MAC ➤ USE RSA TO EXCHANGE AES KEY
  34. There were some useful mentions about crypto, that I've never

    heard before. But it wasn't so completed as I expected