Class 25: Reversing Reverse

16
Class 25: Reversing Reverse cs1120 Fall 2011 David Evans 21 October 2011

description

Reverse Engineeringlist-reverseAnalyzing running time and spacemlist-reverse!

Transcript of Class 25: Reversing Reverse

Page 1: Class 25: Reversing Reverse

Class 25: Reversing Reverse

cs1120 Fall 2011David Evans21 October 2011

Page 2: Class 25: Reversing Reverse

2

Reverse Engineering

Forward (Normal) Engineering

What you Want Design a Solution

Reverse Engineering

Some ArtifactUnderstand how it works

48-bit LFSR

f( )∙

RNG

Challenge Key stream

ID

+

Response

++

48-bit stream cipherMutual authentication protocol

Note: when the artifact you start with is natural, this is called “science”!

Page 3: Class 25: Reversing Reverse

3

Reversing Crypto Circuits

Pictures from Karsten Nohl (UVa CpE PhD 2009)

500x Magnification Microscope

Page 4: Class 25: Reversing Reverse

4

Chip Logic Layer

4 NAND: Y = !(A & B & C & D)

Page 5: Class 25: Reversing Reverse

5

(Mostly) Automated Analysis

Identify Logic Gates Trace Wires Connecting Them

Page 6: Class 25: Reversing Reverse

48-bit LFSR

f( )∙

RNG

Challenge Key stream

ID

+

Response

++

48-bit stream cipherMutual authentication

protocol

Page 8: Class 25: Reversing Reverse

8

Plan

Review: list-reverse(Forward and Reversing) mlist-reverse!Forward and Reverse Lists (Doubly-Linked Lists)

I still have unclaimed Exams! I will start charging exam storage fees Monday.Note: if you want to reverse engineering my storage fees protocol, you could try waiting later (but I don’t recommend it!)

Page 9: Class 25: Reversing Reverse

9

Reversing

Page 10: Class 25: Reversing Reverse

10

Analyzing list-reverse(define (list-reverse p) (if (null? p) null (list-append (list-reverse (cdr p)) (list (car p)))))

Page 11: Class 25: Reversing Reverse

11

Reversing(define (list-reverse p) (if (null? p) null (list-append (list-reverse (cdr p)) (list (car p)))))

Running time is in (N2) where N is number of elements in p.

Number of new cons cells: for the list-appends: N-1 + N-2 + … + 1 = N2/ 2 + for the (list (car p)): N memory use is in (N2)

Page 12: Class 25: Reversing Reverse

12

mlist-reverse!Define a mlist-reverse! that reverses the elements of a mutable list. The output should be a mutable list with the elements in the reverse order. The number of cons cells it creates should not scale with the length of the list. (The input list can be mutated arbitrarily!)

Page 13: Class 25: Reversing Reverse

Revers!ing a List

1

m1:

2 3

revm1:

Page 14: Class 25: Reversing Reverse

14

Page 15: Class 25: Reversing Reverse

15

Close…but not quite

(define (mlist-reverse! p) (if (null? (mcdr p)) p (let ((rest (mlist-reverse! (mcdr p)))) (set-mcdr! p null) (mlist-append! rest p) rest)))

(define (mlist-reverse! p) (if (null? (mcdr p)) p ((lambda (rest) (begin (set-mcdr! p null) (mlist-append! rest p) rest)) (mlist-reverse! (mcdr p))))) > m1

{1 2 3 4}> (mlist-reverse! m1){4 3 2 1}> m1{1}

Page 16: Class 25: Reversing Reverse

16

Charge

Next week: Finish mlist-reverse!Programming with Objects, Python

I still have unclaimed Exams! I will start charging exam storage fees Monday. You can come to my office now to get yours.