650 likes | 1.38k Views
symmetric key cryptography. tkkwon@snu.ac.kr. Symmetric Encryption. Classic ciphers also known as (AKA) single key Secret key sender and recipient share a common key was only type prior to invention of public-key cryptography until second half of 1970 ’ s. Symmetric Cipher Model.
E N D
symmetric key cryptography tkkwon@snu.ac.kr
Symmetric Encryption • Classic ciphers • also known as (AKA) • single key • Secret key • sender and recipient share a common key • was only type prior to invention of public-key cryptography • until second half of 1970’s
Symmetric Cipher Model there must be a secure mechanism for the distribution of this key a priori source: William Stallings
Requirements • two requirements for secure use of symmetric encryption: • a strong encryption algorithm • a secret key known only to sender / receiver Y = EK(X) X = DK(Y) • assume encryption algorithm is known • Kerckhoffs’s Principle: A cryptosystem should be secure even if everything about the system, except the key, is public knowledge • imply a secure channel to distribute the key
cryptographic attacks • The language of the plaintext and the nature of the cipher are assumed to be known to the adversary. • Ciphertext-only attack: The adversary knows only a number of ciphertexts. • Known-plaintext attack: The adversary knows some pairs of ciphertext and corresponding plaintext. • Chosen-plaintext attack: The adversary can choose a number of messages and obtain the ciphertexts • Chosen-ciphertext attack: The adversary can choose a number of ciphertexts and obtain the plaintexts. * These attacks are also applicable to PKC
requirements for a secure cipher • In cryptography, confusion and diffusion are two properties of the operation of a secure cipher [Claude Shannon] • Diffusion means that if we change a character of the plaintext, then several characters of the ciphertext should change, and similarly, if we change a character of the ciphertext, then several characters of the plaintext should change • Confusion means that the key does not relate in a simple way to the ciphertext. In particular, each character of the ciphertext should depend on several parts of the key
popular primitives • Substitution • Permutation/transposition • exclusive-OR:
first substitution (shift) cipher • Caesar Cipher: E(x) = x+3 (mod 26) • monoalphabeticcipher • then, how to decrypt? D(y)? • is it secure?
affine cipher • another monoalphabetic substitution cipher • for English alphabet, m is 26 below • E(x) = (ax+b) mod m • D(y) = a-1(y-b) mod m • how many keys? • 26 letters • 12 numbers for a, 26 numbers for b • is it secure?
Monoalphabetic Substitution Cipher • The key space: all permutations of = {A, B, C, …, Z} • Encryption given a key : • each letter X in the plaintext P is replaced with (X) • Decryption given a key : • each letter Y in the ciphertext C is replaced with -1(Y) Example: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z = B A D C Z H W Y G O Q X S V T R N M L K J I P F E U BECAUSEAZDBJSZ • is it secure?
frequency analysis • Frequency analysis is based on the fact that, in any given stretch of written language, certain letters and combinations of letters occur with varying frequencies.
another hints to guess • Most common English bigrams (frequency in 1000 words)
Vigenère Cipher polyalphabetic (polygraphic) substitution [A=0, B=1, …, Z=25], Zn= {0, 1, …, n-1}, P = C = (Z26)* Definition: Given m (key length), and K = (k1, k2, … , km) a key, Encryption: ek(p1, p2… pm) = (p1+k1, p2+k2…pm+km) (mod 26) Decryption: dk(c1, c2… cm) = (c1-k1, c2-k2 … cm- km) (mod 26) Example: Plaintext: C R Y P T O G R A P H Y Key: L U C K L U C K L U C K Ciphertext: N L A Z E I I B L J J I
Vigenère Cipher • An attacker can figure out key length m? • If the attacker finds the key length, then what happens?
Hill Cipher • polygraphicsubstitution cipher based on linear algebra C1 = 9*p1 + 18*p2 + 10*p3 (mod 26) C2 = 16*p1 + 21*p2 + 1*p3 (mod 26) C3 = 5*p1 + 12*p2 + 23*p3 (mod 26) C1 9 18 10 p1 C2 = 16 21 1 p2 (mod 26) C3 5 12 23 p3 • how to decrypt?
Hill cipher: A key is a matrix k11 k12 k13 k21 k22 k23 k31 k32 k33 • Generalize to any size, larger blocks • matrix multiplication can provide diffusion • Matrix must be invertible • is it secure? • is vulnerable to a known-plaintext attack
transposition cipher • aka permutation cipher columnar cipher
X-or() in cryptography • Sender wants to send M to receiver • M (Original plaintext): 1010 • K (Key): 0011 • M K = 1001 (Encrypted ciphertext) 1001 transmitted • Receiver already knows K • (M K) K= 1001 0011 = 1010 = M -> original message is restored!
one time pad (OTP) • The one-time pad, which is a provably secure cryptosystem, Gilbert Vernam in 1918. • aka Vernamcipher • The message is represented as a binary string (a sequence of 0’s and 1’s using a coding mechanism such as ASCII coding. • The key is a truly random sequence of 0’s and 1’s of the same length as the message. • The encryption is done by adding the key to the message modulo 2, bit by bit. This process is often called exclusive or, XOR ()
OTP: Example • message =‘IF’ • then its ASCII code =(1001001 1000110) • key = (1010110 0110001) • Encryption: • 1001001 1000110 plaintext • 1010110 0110001 key • 0011111 1110110 ciphertext • Decryption: • 0011111 1110110 ciphertext • 1010110 0110001 key • 1001001 1000110 plaintext
OTP problems • Key should be as long as plaintext • key should not be reused • Key distribution & Management difficult
Two types of symmetric ciphers • Stream cipher • Encrypts one bit at a time • mimicking OTP • e.g. RC4 • Block cipher • Encrypts a block of bits at a time • e.g. DES, AES
stream cipher • Generalization of one-time pad • Stream cipher is initialized with key • Key is “stretched” into long keystream • Keystream plaintext = ciphertext • Stream cipher is a keystream generator Key Stream Keystream Generator Keystream Generator Plaintext Ki Keystream Keystream Ki Pi Å Å Pi Ci Plaintext = Plaintext Ciphertext Ciphertext
S0 S1 S2 stream cipher: LFSR • linear feedback shift register (LFSR) st+3 = st+1+ st S0 S1 S2 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 0 1 0 0 ----------------- 0 0 1 Initial fill determines the sequence of states Generates a periodic sequence …0010111... Maximal period 23-1=7
revisit confusion and diffusion • confusion refers to making the relationship between the ciphertext and the symmetric key as complex and involved as possible; • diffusion refers to dissipating the statistical structure of plaintext over bulk of ciphertext. • This complexity is generally implemented through a series of substitutions and permutations • The simplest way to achieve both diffusion and confusion is to use a substitution-permutation network
advanced encryption standard (AES) • based on Rijndael cipher • data block viewed as 4-by-4 table of bytes • Such a table is called the current state • 3 key lengths (128/192/256), 128 bit key is assumed here • key is expanded to array of words • each word is 128 bit long • has 10 rounds in which state goes through the following transformations (called `layers’): • SubBytes: byte substitution (1 S-box used on every byte) • ShiftRows: shift rows (permute bytes between groups/columns) • MixColumns: mix columns (uses matrix multiplication in GF(256)) • AddRoundKey: add round key (XOR state with round key) • First and last round are a little bit different
AES: SubBytes (S-box) • a simple substitution of each byte • a byte = two nibbles • S-box has 16x16 entries: all possible 8-bit values • each byte of state is replaced by byte indexed by row (left 4-bits) & column (right 4-bits)
AES: ShiftRows • a circular byte shift in each row (permutation) • 1st row is unchanged • 2nd row does 1 byte circular shift to left • 3rd row does 2 byte circular shift to left • 4th row does 3 byte circular shift to left
AES: Mix Columns • each column is processed separately • each byte is replaced by a value dependent on all 4 bytes in the column • effectively a matrix multiplication (Hill Cipher)
AES: Add Round Key • XOR state with 128-bits of the round key
Modes of Operations • message is typically longer than the block size • DES and AES have multiple modes of operations • depending on how consecutive blocks are processed • five modes • ECB • CBC • CFB • OFB • CTR
Electronic CodeBook (ECB) • message is broken into independent blocks which are encrypted • each block is a value which is substituted, like a codebook, hence name • each block is encoded independently of the other blocks Ci = EK1(Pi) • uses: secure transmission of single values
Electronic Codebook Mode (ECB) 64 bit (8 byte) blocks in DES Ci-1 Ci Ci+1 Pi-1 Pi Pi+1 Ek Ek Dk Dk Ek Dk Ci-1 Ci Ci+1 Pi-1 Pi Pi+1 Ciphertext = (C0C1 ... Cn)
Advantages and Limitations of ECB • repetitions in message may show in ciphertext • if aligned with message block • particularly with data such graphics • or with messages that change very little, which become a code-book analysis problem • weakness due to encrypted message blocks being independent • ECB mode is susceptible to substitution attacks • main use is sending a few blocks of data
Cipher Block Chaining (CBC) • Two identical plain messages produce two different cipher messages. • This prevents Chosen plaintext attack.
Cipher Block Chaining (CBC) • message is broken into blocks • but these are linked together in the encryption operation • each previous cipher blocks is chained with current plaintext block, hence name • use Initialization Vector (IV) to start process Ci = EK1(PiXOR Ci-1) C-1 = IV • uses: bulk data encryption, authentication
Cipher Block Chaining Mode (CBC) Encryption Decryption C0 = Ek(P0Å IV) P0 = IVÅDk(C0) Pi = Ci-1ÅDk(Ci) Ci = Ek(PiÅ Ci-1) Pi+1 Pi-1 P0 Pi Ci+1 Ci Ci-1 Ci-2 Å Å Å Å IV Ek Ek Ek Dk Dk Ek Dk Å Å Å Ci-2 Ci-1 Ci Ci+1 C0 Pi-1 Pi Pi+1 Ciphertext = (IV C0C1 ... Cn)
CBC – Error Propagation • 1 bit error in the plaintext feed • Will affect that block and all others • Decryption will correct all but the flipped bit • 1 bit error in the ciphertext feed • Will affect two blocks • CBC mode is self recovering
CBC – Initialization Vector (IV) • If IV is same, every encryption of the same plaintext is the same. • With the IV being a random number, the same plaintext will be all different • IV can be in public, but should satisfy two req’s • otherwise, some attacks possible • two requirements for IV usage • no IV is reused under the same key • IV change should be unpredictable
Advantages and Limitations of CBC • each ciphertext block depends on allprevious blocks • encrypting a block requires the finish of encryption of all the previous blocks • no parallelism in encryption • parallelism in decryption
Cipher FeedBack (CFB) • message is treated as a stream of bits • can be a stream cipher • added to the output of the block cipher • result is feed back for next stage (hence name) • standard allows any number of bits (1,8 or 64 or whatever) to be feedback • denoted CFB-1, CFB-8, CFB-64 etc • is most efficient to use all 64 bits (CFB-64) Ci = Pi XOR EK1(Ci-1) C-1 = IV
Cipher Feedback Mode (CFB) Encryption Decryption C0 = P0ÅEk(IV) P0 = Ek(IV) Å C0 Ci = PiÅEk(Ci-1) Pi = CiÅEk(Ci-1) Pi+1 Ci-1 Pi-1 Pi Ci Ci+1 P0 Ek Ek Ek Ek Ek IV Å Å Å Å Å Ci-2 Å Ci-1 Ci+1 Pi Pi+1 C0 Ci Ciphertext = (IV C0C1 ... Cn)
CFB – Initialization Vector • CFB must use an IV • same requirements as CBC
CFB – Error Propagation • CFB mode is self recovering • one bit error in ciphertext corrupts some # of blocks • CFB-8 -> 8 bytes are garbled Bit errors in the incoming cipher block (i.e. a byte) will cause bit error at the same bit positions in the first plaintext block. This cipher block will then be fed to the shift register and cause bit errors in the plaintext for as long as the erroneous bits stay in the shift register. Hence, for 8-bit CFB, the following 8 bytes will be garbled. After that, the system recovers, and all following bytes is decrypted correctly.
Advantages and Limitations of CFB • appropriate when data arrives in bits/bytes: stream cipher • most common stream mode • encryption is not parallelizable • keystream cannot be generated in advance • decryption is parallelizable • note that the block cipher is used in encryption mode at both ends
output feedback mode (OFB) • can be a stream cipher • IV is used as a seed to generate OTP • actual encryption/decryption is only X-or • fast • no dependency • parallel encryption/decryption
Output Feedback Mode (OFB) Encryption Decryption Note: The plaintext is never encrypted. IV and successive encryptions act as an one time pad generator. C0 = P0ÅEk(IV) P0 = Ek(IV) Å C0 Ci = PiÅEk(Si-1) Pi = CiÅEk(Si-1)
OFB: advantages and limitations • no error propagation • 1 bit error in ciphertext affects only one bit in plaintext • a (key)stream can be generated in advance • fast due to parallelism • if attacker knows plaintext and ciphertext, he can modify the plaintext
counter mode (CTR) • can be a stream cipher • IV is called a counter • highly parallelizable • no linkage between blocks • very fast • counter should not be repeated for the same key • can decrypt from any arbitrary position unlike OFB • attacker can get of two plaintext blocks by taking the of two ciphertext blocks like OFB