in Ruby Rzeszów Ruby User Group #3 Wojciech Rząsa [email protected] @wrzasa Katedra Informatyki i Automatyki, Politechnika Rzeszowska http://www.kia.prz.edu.pl/ 16.12.2016 Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 1/26
Confidentiality (data privacy) Authenticity (who wrote it?) Integrity (was it changed along the way?) Non-repudiation . . . Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 4/26
Frequently used in cryptography Simple Cheap Easily reversible a b a ⊕ b 1 1 0 0 0 0 1 0 1 0 1 1 a ⊕ b ⊕ a = b (1) a ⊕ b ⊕ b = a (2) Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 5/26
modes Characteristics In Ruby Electronic Code Book (ECB) – example Original [https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation] Tux the Penguin, the Linux mascot. Created in 1996 by Larry Ewing with The GIMP. Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 9/26
modes Characteristics In Ruby Electronic Code Book (ECB) – example Original ECB encrypted [https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation] Tux the Penguin, the Linux mascot. Created in 1996 by Larry Ewing with The GIMP. Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 9/26
modes Characteristics In Ruby Electronic Code Book (ECB) – example Original ECB encrypted Securely encrypted [https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation] Tux the Penguin, the Linux mascot. Created in 1996 by Larry Ewing with The GIMP. Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 9/26
modes Characteristics In Ruby Characteristics Shared key Only the key must be kept secret Initialization vector (IV) required Never reuse IV with the same key! Check how to chose IV Consciously! Randomly? Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 12/26
1 require ’openssl ’ 2 3 digest = OpenSSL :: Digest.new(’SHA256 ’) 4 5 5. times do 6 digest.update gets 7 end 8 9 puts digest.hexdigest ¦ ¥ Compute digest in Ruby Litwo, Ojczyzno moja! ty jesteś jak zdrowie; Ile cię trzeba cenić, ten tylko się dowie, Kto cię stracił. Dziś piękność twą w całej ozdobie Widzę i opisuję, bo tęsknię po tobie. 899b352ef6b61bd08a2872a912908c2a54837efc1853c5458c08e9b2f17550bf Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 17/26
Function (PBKDF) Use password as input Generate binary (pseudorandom) key Use a lot of CPU time salt hash function XOR a lot of iterations (from 1000 in year 2000 to 10,000 in IOS 4, and even 100,000 now, serverside) Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 20/26
Be sure to know what you do before you do it! No ”but it works... somehow...” approach! Next: asymmetric cryptography Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 24/26
rdoc Samolej, Rząsa, Rzońca, Sadolewski: Wprowadzenie do informatyki II – bezpieczeństwo systemów informatycznych, sieci komputerowe, systemy operacyjne i bazy danych, Oficyna Wyd. PRz., 2014. RFC 2898 PKCS #5: Password-Based Cryptography Specification Version 2.0 https://tools.ietf.org/html/rfc2898#section-5.2 https://en.wikipedia.org/wiki/Block_cipher_mode_ of_operation Wojciech Rząsa, @wrzasa, KIiA PRz RRUG#3, Symmetric Cryptography in Ruby 25/26