HOMEWORK III ECE 3710 — Microcomputer Hardware and Software

$35.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (4 votes)

Problem 1. Write a program that uses bit-banding to copy data from PF.4 and PF.3 to PC.6 and
PC.7, respectively (i.e. PF.4 → PC.6 and PF.3 → PC.7).
Problem 2. Write a function that uses bit-banding and the IT instruction to check if a number
placed at a given memory location within the bit-band is
(a) even
(b) divisible by four.
If a number is even the function should return 01, if divisible by four 11, else 00. The memory
address of the number is placed on the stack prior to the function being called and the result
should be placed on the stack prior to the function returning.
Problem 3. (20 points) You’ve recently been hired by, let’s say, the No Such Agency (NSA) to
be part of a team building a block cipher encryption/decryption machine. Your task is to
implement a routine that encrypts an 8-bit input. The location of the input data (known as
the plaintext) is placed in R0 before the function is called; the location for the encrypted data
(known as the ciphertext) is to be placed in R0 before the routine returns. The 8-bit encryption
key is supplied on PB; i.e. you have to read PB to know the encryption key (this allows the
user to enter an arbitrary key).
The encryption algorithm you have to use only encrypts 4-bits of data at a time. Here’s how
we perform the encryption. Allow M1 to be the lower four bits of the 8-bit input M. Similarly,
let K1 denote the lower four bits of the encryption key K and K2 its upper four bits. To
encrypt M1:
(a) XOR M1 and K1;
(b) use the table below to map the result of the XORing to its substitute; and
(c) XOR the substitute with K2.
The same procedure is followed for the remaining 4 bits. The following figure illustrates this
process (the ‘S’ refers to the table).
3 Preliminary analysis
Di↵erential cryptanalysis is based on taking two plaintext/ciphertext pairs, looking at the difference of the two plaintexts and then at the di↵erence of the two ciphertexts. The “di↵erence”
between two values is usually measured using the exclusive-or operator due to its interesting
properties. So, the di↵erence between a and b is denoted a b. Now, let’s look at the properties
of the exclusive-or : it is commutative, and has the property that a a = 0 and a 0 = a. This
is interesting, because it means that :
(M1 K) (M2 K)=(M1 M2) (K K) = M1 M2
That is, if we want the di↵erential of two values M1 and M2, applying the key K to each of
them using the same operator exclusive-or will not a↵ect the di↵erential. And this is the reason
why it is useful.
4 Di↵erential cryptanalysis
This section will detail the di↵erential cryptanalysis of this cipher. Define the S-box as follows :
Input 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Output 7 4 3 11 0 9 14 5 8 12 1 6 13 11 2 10
Assume we have two plaintext/ciphertext pairs, respectively (M1, C1) and (M2, C2). One
knows the value of M1 M2 just before entering the S-box, and the value of C1 C2 just after
leaving it (since mixing the key using exclusive-or does not a↵ect the di↵erential. Now what we
need is some particular “input” di↵erential that will map to another “output” di↵erential very
often. This is called a characteristic and is required for the attack to be successful.
4.1 Finding a characteristic
No unidimensional S-box is “perfect” and we are guaranteed to find some di↵erential pair that
will occur more than the others (however the S-boxes can be tuned to strengthen them against
this type of attack, but in our case the S-box is not very resistant for our purposes). In our
case, by running a quick program to find a di↵erential, we find that if we have two values M1
and M2 with M1 M2 = 3, then C1 C2 = 7 holds with probability 0.375. We can denote our
characteristic as follows :
(3, 7) ) 0.375
We now need to make a list of which input/output pairs of the S-box satisfy this characteristic.
Runninganotherprogramquickly,wegetthefollowingtable:
For example, to encrypt M1 = 0101 using K = 00111100:
(a) 0101 XOR 1100 = 1001;
(b) 1001 = 9 → 12 = 1100; and
(c) 1100 XOR 0011 = 1111.
HINT: use the DCB directive to define the output line of the table in memory. That way, you
can add the starting address of the table to the value of the input to grab the correct output
(think about copying the string in lab one). Also, use the simulator!
NOTE: there is a typo in the table. An input of 3 should map to an output of 15.
Problem 4. Making use of at least one instruction that uses the flexible second operand with a
shift, write a program that reads from PD.4–6 and writes to PD.1–3 (i.e. PD.4 → PD.1,
PD.5 → PD.2, and PD.6 → PD.3). Your solution must not affect pins zero or seven.
Problem 5. (EXTRA CREDIT) Create a .lst by hand for the following code:
S t a r t
l d r r3 ,= S t a r t
mov l r , r 3
cmp r3 , l r
beq func
func
push { r 3 }
l d r r0 , [ SP,# 1 2]
bx l r
NOTE: You are free to check your work using an assembler or simulator; however, you must
show the steps you used to calculate the opcode and corresponding data, if any, for each
instruction to receive credit. To force the assembler to generate 16-bit instructions you can
use the CODE16 directive.