CNS Lecture 6
Total Page:16
File Type:pdf, Size:1020Kb
In the news CNS Lecture 6 • Microsoft IE Active X remote code execution • Microsoft powerpoint remote code execution (0-day) Block ciphers -- AES (Rijndael) • MAX OS X multiple vulnerabilities Stream ciphers • OpenSSL ASN.1 remote buffer overflow Key management • gzip, firefox, Adobe flash player, … review assignment 5 A assignment 6 CNS Lecture 6 - 2 Block cipher modes You are here … Attacks & Defenses Cryptography Applied crypto • ECB, CBC, CFB, OFB, CTR • Risk assessment •Random numbers •SSH • applies to all block ciphers • Viruses • •Hash functions •PGP Padding, chaining and IV’s • Unix security • hide repeated plaintext MD5, SHA,RIPEMD •S/Mime • authentication • different error/attack properties • Network security •Classical + stego •SSL Firewalls,vpn,IPsec,IDS •Number theory •Kerberos •Symmetric key •IPsec encryption does not guarantee message integrity! DES, Rijndael, RC5 •Public key RSA, DSA, D-H,ECC CNS Lecture 6 - 3 CNS Lecture 6 - 4 Padding, IV’s, and key generation in OpenSSL Block ciphers • Encryption will pad to block size of cipher (DES: 8 bytes, AES 16) Feistel substitution and permutation – E.g., 3 bytes in 8 encrypted bytes out, 21 in 24 out – May want to pre-pad with random “salt” to obscure same message • DES •performance (time/space) vs strength • OpenSSL standard API encryption pads with bytes of IV • Lucifer •large keys – EVP methods pads with byte count (PKCS 5) •strong subkey generation and pre-pends 8-byte magic “Salted__” and 8 byte random salt • blowfish •large blocks – openssl des-cbc: 7 bytes in 24 encrypted bytes out, 8 bytes in 32 encrypted •simple operations, non-linear functions (S-box, rotate) bytes out • CAST •iterative, more rounds • Cipher may be attackable if attacker knows IV •resist known attacks (diff./lin.) – Best practice: derive IV from shared secret (asnmt 7) + nonce? •ciphertext should have uniform distribution (look random) – Need different IV when restarting encryption non-Feistel – OpenSSL EVP optionally derives IV from MD5 of key • Converting a password to a key • IDEA – Assignment 7 uses MD5 • RC2, RC5 – OpenSSL EVP_BytesToKey() generates key and IV from password using MD5 • AES (Rijndael) • For non-feistel need invertible operations CNS Lecture 6 - 5 CNS Lecture 6 - 6 1 AES Mars (IBM) Advanced Encryption Standard Other crypto bake-offs • replace DES Europe: NESSIE • '97 call for algorithms Japan: CRYPTREC • Feistel (1/4, 3/4 rather than even split) – royalty free, publicly disclosed • 8 (unkeyed) pre/post-whitening rounds –128-bit block symmetric key cipher –addition, XOR, and 512x32 S-box (32-bit –key-sizes: 128, 192, 256 words) evaluation criteria • 16 keyed rounds • security –addition, XOR, and S-box, multiplication, • cost/performance (memory, computational efficiency) data-dependent rotations, key addition • architecture -- simplicity, flexibility • S-box: pseudo-random and tested • hardware/software suitability • key schedule: linear transform and S-box, with pattern matching to eliminate weak subkeys • '98 15 candidates keys copied in to T[i] • '99 5 finalists (MARS, RC6, Rijndael, Serpent, Twofish) CNS Lecture 6 - 7 CNS Lecture 6 - 8 serpent Rijndael rhine-doll (or rain doll) • substitution-linear transform network • son of Square cipher • non-feistel – need inverse S-boxes and inverse transform • substitution-linear transform network • 256-bit key, 128-bit blocks, 32-bit work unit non-feistel (need inverse) • bit-slice mode • plaintext block (16 bytes) treated as 4x4 array (state array) • • 8 4x4 DES-like S-boxes Linear transform (L) 10/12/14 rounds (128/192/256 key size) – pseudorandom with testing S-box, row shifts, column mixing, key-XOR • key schedule: S-box, constants with XOR, rotates • 32 rounds (most secure, slow) • 16x16 S-box (256 bytes) – XOR, S-boxes, linear transform • For decryption need inverse S-box and inverse mixcol – avalanche after 3 rounds user key wi • Rijndael uses polynomial arithmetic (S boxes and mixcol) 3 2 4 • key schedule: affine recurrence with S-boxes a(x) = a3x + a2x + a1x +a0 mod (x + 1) 8 33 128-bit subkeys coefficients (bytes) ai are in GF(2 ) • RC6 (son of RC5) • Twofish (son of Blowfish) CNS Lecture 6 - 9 CNS Lecture 6 - 10 Rijndael setup – key expansion Rijndael setup -- S box setup • S-box (and inverse S-box) (256-byte) can be calculated or bytes pre-built (time vs memory) (permutation of all 256 bytes) • Key expansion (16B key 1 76B subkeys) S-box creation: – g: byte rotate, S-box, XOR with consti – Subkey (4 4-byte words) for each round plus words 1. initialize to 00 … FF one more subkey 2. calculate multiplicative inverse of each element – For AES-128, 11 subkeys (10 rounds + 1) repeat over GF(28) mod x8+x4+x3+x+1 3. transform bits of byte with XOR with constant • Rationale – Resistant to attacks Combine words into subkeys – Round constants eliminate symmetry Example: 97 88 – Knowledge of some bits of key or subkey does not help calculating other subkeys • Rationale – Diffusion –Low correlation between input and output bits – Speed – – Can generate subkeys on the fly (time/space) Must be invertible –Step 3 prevents interpolation attacks and eliminates S(a)=a and S(a)=a’ –Only non-linear transform of cipher CNS Lecture 6 - 11 CNS Lecture 6 - 12 2 16 bytes data/state Encryption/decryption Rinjdael stages •Byte substitution -- S-box (nonlinear, strength) Encryption is not identical to decryption. Decryption is same sequence of •Shift rows – permutation (diffusion) transformations, but using inverse transforms Change of subkeys needed •Mix columns – substitution using arithmetic over GF(28) Need rounds+1 subkeys -multiplies data array with constant array Note last round has no mixcolumn -multiplication is polynomial multiplication First/last step is add round key … why? mod x4 + 1 over GF(28) -- easy in hardware and fast table-lookup in software (256-entry multiplication table) -each element of a column is function of all the elements of the column (mixing) round •Add round key – XOR with round key (simple Vernam/XOR cipher) data/state key -on 32-bit processor, round transformation can be done in set of table lookups -table lookups contribute to speed of Rijndael and prevent timing/power attacks - Potential for parallelism and each stage is reversible decryption works CNS Lecture 6 - 13 CNS Lecture 6 - 14 Rijndael data structures Rijndael round • 128-bit (16 byte) data block treated at 4x4 byte array CNS Lecture 6 - 15 CNS Lecture 6 - 16 Row and column transformations Substitute byte and add round key Row transform •Row 1 -- unchanged •Row 2 – rotate left 1 byte •Row 3 – rotate right 2 •Row 4 – rotate right 1 The row transform shifts column values, the 4 bytes of one column are spread out to four different columns. Mix column each byte of a column is mapped ⊕ into a new value that is a function of all four bytes in the column. matrix multiply is over GF(28) After a few rounds, all output bits depend on all input bits. CNS Lecture 6 - 17 CNS Lecture 6 - 18 3 Rijndael decryption The mathematics of cryptography Finite (discrete) mathematics •Each stage is reversible •Modular arithmetic (shift ciphers, polyalphabets, Hill cipher) alter direction of shift rows •Primes and prime factors, greatest common divisor, BIG integer libraries invert Sbox •Linear transforms (row/column transpositions, linear algebra) Invert mixcolumn (mod x4 + 1) •Exponentiation/discrete logs (D-H, RSA) a(x) = {03}x3 + {01}x2 + {01}x + {02} •Polynomial arithmetic (CRC, AES, LFSR, ECC) a-1(x) = {0B}x3 + {0D}x2 + {09}x + {0E} •Elliptic curves (ECC) •Modified round key pre-calculate when making subkeys So decryption differs slightly from encryption CNS Lecture 6 - 19 CNS Lecture 6 - 20 Finite field of dreams Rijndael and polynomial arithmetic • What we’d like is arithmetic over a finite field –Computers do better with finite (discrete) arithmetic • Rijndael utilizes polynomial arithmetic in two ways (really one) –Field is associative, commutative, etc, with additive inverse, –Invertible arithmetic (finite field) over 8-bit numbers (+ x ) multiplicative inverse invertible S-box –Works for arithmetic mod a prime, e.g (5/4) mod 7 = 3 linear transforms (mixcolumn) –But computer “words” are usually powers of 2, (5/4) mod 8 = –4-byte arithmetic (constant poly is relatively prime to x4 + 1 ) • Stay tuned … corn fields, wheat fields, Galois fields ☺ Invert mixcolumn mod (x4 + 1) a(x) = {03}x3 + {01}x2 + {01}x + {02} Polynomial arithmetic used by CRC's, Rijndael, LFSR's, ECC CNS Lecture 6 - 21 CNS Lecture 6 - 22 Polynomial arithmetic Polynomial arithmetic over GF(2) Galois fields: finite fields of • addition and multiplication • hardware influence: use coefficients mod 2 order pn, written GF(pn) –Think of each bit as a coefficient (3x4 + 5x2) + (x3 + 6x2) = 3x4 + x3 + 11x2 – addition/subtraction is XOR, multiply is AND • polynomial: x3 + x + 1 is 1011 (3x4 + 2x3) (x +1) = 3x5 + 5x4 + 2x3 (x + 1) (x2 + x) = x3 + x2 + x2 + x = x3 + x • Hardware/software: fast, XOR and table lookups • division: 3x7 + x5 + x2 - 2 divided by x4 -1 equals 3x3 + x with remainder 3x3 + x2 + x – 2 • Coefficients can be integers or mod p (Zp) ((3x4 + 5x2) + (x3 + 6x2) ) mod 7 = (3x4 + x3 + 11x2 ) mod 7 = 3x4 + x3 + 4x2 see CRC reading or Rijndael spec or text Ch 4 and Ch. 5 appendix CNS Lecture 6 - 23 CNS Lecture 6 - 24 4 Modular polynomial arithmetic over GF(2n) poly arithmetic in GF(28) • Do polynomial multiplication mod an irreducible polynomial • Extended Euclid algorithm can be used to find the multiplicative inverse • Notion of prime/irreducible polynomials of a polynomial (exists