14
Computer Science 320 Massive Parallelism

Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Embed Size (px)

Citation preview

Page 1: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Computer Science 320

Massive Parallelism

Page 2: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Example Problem: Breaking a Cipher

Somehow obtain a sample plaintext and its ciphertext

Then search for the AES key, using encrypt(pt, k)

Exhaustive search might examine potentially 2256 or 1077 possible values, requiring more time than the lifetime of the universe

Page 3: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Partial Key Search

• Work with a partial key having, say, all but at most the least significant 30 bits known

• Solve for just these bits by an exhaustive search

• Inputs: plaintext, ciphertext (128 bits each), key (256 bits), and the number of bits for which to solve

Page 4: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Generate a Random, 256-Bit Keyimport edu.rit.util.Hex;import java.security.SecureRandom;

public class MakeKey{ public static void main(String[] args) throws Exception{ System.out.println(Hex.toString(SecureRandom.getSeed(32))); }}

Use SecureRandom to get a 256-bit number from the system’s entropy source file

java.util.Random uses only 48 bits

Page 5: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Generate a Plaintext and Ciphertextimport edu.rit.util.Hex;import edu.rit.crypto.blockcipher.AES256Cipher;

public class Encrypt{

public static void main(String[] args) throws Exception{

// Parse command line arguments. if (args.length != 3) usage(); String message = args[0]; byte[] key = Hex.toByteArray(args[1]); int n = Integer.parseInt(args[2]);

Inputs: a plaintext (string), a key (hex string), and the number of bits to zero out (digit string)

Page 6: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Generate a Plaintext and Ciphertextimport edu.rit.util.Hex;import edu.rit.crypto.blockcipher.AES256Cipher;

public class Encrypt{

public static void main(String[] args) throws Exception{

// Set up plaintext block. byte[] msg = message.getBytes(); byte[] block = new byte [16]; System.arraycopy(msg, 0, block, 0, Math.min(msg.length, 16)); System.out.println(Hex.toString(block));

Page 7: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Generate a Plaintext and Ciphertextimport edu.rit.util.Hex;import edu.rit.crypto.blockcipher.AES256Cipher;

public class Encrypt{

public static void main(String[] args) throws Exception{

// Set up plaintext block. byte[] msg = message.getBytes(); byte[] block = new byte [16]; System.arraycopy(msg, 0, block, 0, Math.min(msg.length, 16)); System.out.println(Hex.toString(block));

// Encrypt plaintext. AES256Cipher cipher = new AES256Cipher(key); cipher.encrypt(block); System.out.println(Hex.toString(block));

Page 8: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Generate a Plaintext and Ciphertextimport edu.rit.util.Hex;import edu.rit.crypto.blockcipher.AES256Cipher;

public class Encrypt{

public static void main(String[] args) throws Exception{

// Wipe out n least significant bits of the key. int off = 31; int len = n; while (len >= 8){ key[off] = (byte) 0; -- off; len -= 8; } key[off] &= mask[len]; System.out.println(Hex.toString(key)); System.out.println(n); }

Page 9: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Sequential Key Search Programimport edu.rit.util.Hex;import edu.rit.crypto.blockcipher.AES256Cipher;

public class FindKeySeq{

// Command line arguments. static byte[] plaintext; static byte[] ciphertext; static byte[] partialkey; static int n;

// Variables for doing trial encryptions. static int keylsbs; static int maxcounter; static byte[] foundkey; static byte[] trialkey; static byte[] trialciphertext; static AES256Cipher cipher;

Inputs: plaintext, ciphertext, key (hex strings), and number of bits (digit string > 0 and < 30)

Page 10: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Sequential Key Search Programimport edu.rit.util.Hex;import edu.rit.crypto.blockcipher.AES256Cipher;

public class FindKeySeq{

public static void main(String[] args){

// Parse command line arguments. if (args.length != 4) usage(); plaintext = Hex.toByteArray (args[0]); ciphertext = Hex.toByteArray (args[1]); partialkey = Hex.toByteArray (args[2]); n = Integer.parseInt (args[3]);

Page 11: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Sequential Key Search Programimport edu.rit.util.Hex;import edu.rit.crypto.blockcipher.AES256Cipher;

public class FindKeySeq{

public static void main(String[] args){

// Set up variables for doing trial encryptions. keylsbs = ((partialkey[28] & 0xFF) << 24) | ((partialkey[29] & 0xFF) << 16) | ((partialkey[30] & 0xFF) << 8) | ((partialkey[31] & 0xFF) ); maxcounter = (1 << n) - 1; trialkey = new byte[32]; System.arraycopy(partialkey, 0, trialkey, 0, 32); trialciphertext = new byte [16]; cipher = new AES256Cipher(trialkey);

Page 12: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Sequential Key Search Program // Try every possible combination of low-order key bits. for (int counter = 0; counter <= maxcounter; ++ counter){ // Fill in low-order key bits. int lsbs = keylsbs | counter; trialkey[28] = (byte) (lsbs >>> 24); trialkey[29] = (byte) (lsbs >>> 16); trialkey[30] = (byte) (lsbs >>> 8); trialkey[31] = (byte) (lsbs );

// Try the key. cipher.setKey(trialkey); cipher.encrypt(plaintext, trialciphertext);

// If the result equals the ciphertext, we found the key. if (match(ciphertext, trialciphertext)){ foundkey = new byte[32]; System.arraycopy(trialkey, 0, foundkey, 0, 32); } }

Page 13: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Sequential Key Search Program /** * Returns true if the two byte arrays match. */ private static boolean match(byte[] a, byte[] b){ boolean matchsofar = true; int n = a.length; for (int i = 0; i < n; ++ i) matchsofar = matchsofar && a[i] == b[i]; return matchsofar; }

Page 14: Computer Science 320 Massive Parallelism. Example Problem: Breaking a Cipher Somehow obtain a sample plaintext and its ciphertext Then search for the

Massively Parallel Problem

• If we had 2n processors, each one could try a key simultaneously

• We must clump the search space into subranges and dispatch these to parallel for loops

• Also called embarrassingly parallel