2. High Level C Programming
Encryption
int key=[0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0];
int text=[0x43,0x6F,0x6D,0x70,0x41,0x72,0x63,0x68]; //plain text of "CompArch"
int RN=[0x11,0x90,0x52,0xC8,0xB7,0xCE,0xD4,0x31,
0xD3,0xCB,0xF1,0xB5,0x73,0xAB,0xBF,0x62];
int i,j,k;
Int mask = 0xF0;
for (i=0 ; i<length(text) ; i++){
for (j=0 ; j <length(key) ; j++){
text[i] = bitxor( text[i] , key[j] );
k = bitand(text[i],mask);
text[i]=RN[k];
}
}
3. High Level C Programming
Tag
int key=[0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0];
int text=[0x43,0x6F,0x6D,0x70,0x41,0x72,0x63,0x68]; //plain text of "CompArch"
int mask=0x80;
int tag = 0x00;
int text_temp , j=0;
Int N = length(text)/8 , R = length (text) % 8 ;
for(i=0 ; i<N ; i++){
for(cnt=0 ; cnt<8 ; cnt++) {
if (bitand(key[j],mask) == 0x80)
text_temp = bit_shift_left( text[i] , 1 );
else
text_temp = text[i];
tag = bitxor(text_temp,tag);
bit_shift_left(key[j] , 1); }
if(j==7){
j = 0; }
else{
j++;}
}
for(i=0 ; i<R ; i++){
if (bitand(key[j],mask) == 0x80)
text_temp = bit_shift_left( text[i] , 1 );
else
text_temp = text[i];
tag = bitxor(text_temp,tag);
bit_shift_left(key[j] , 1);
}
4. ISA
Op - Code rs rt rd
Op – Code rs rt offset
Op - Code rs rt instance
Op - Code rt/rd
Add
Sub
Xor
And
Beq
Bne
Load
Store
Addi
shift
5. Assembly Language
Encryption
(0) addi $s1 , $s0 , F # $s1 = 15
(1) addi $s1 , $s1 , 9 # $s1 the pointer of the plaintext (the head of the stack is 24)
(2) load $s2 , $s1 , 0 # $s2 the current char pointer
(3) load $s15 , $s2 , 0 # $s15 current char
(4) add $s3 , $s15 ,$s0 # $s3 working char which will be overwriten during encryption
loop
(5) addi $s4 , $s0 , 15 # $s4 key pointer (one element before because of the loop
starts with an increment)
(6) load $s6 , $s1 , 2 # $s6 = 15 the mask to get the index of RN table stored in
data_memory(26)
(7) load $s7 , $s1 , 3 # $s7 = F0 last key value need to be used in bne instruction
(8) load $s8 , $s1 , 4 # $s8 = 10 which stores the "encryption" tag address for
loop
(9) load $14, $1 , 1 # $s14 stores the pointer of cipher text
--data preparation
6. Assembly Language
Encryption
(10) addi $s4 , $s4 , 1 # increase the key pointer jump addr
(11) load $s5 , $s4 , 0 # $5 get the 16bit key value from the data memo
(12) xor $s9 , $s3 , $s5 # $s9 <= $s3 xor $s5
(13) and $s10, $s9 , $s6 # mask and get the rn table index
(14) load $s11, $s10, $s0 # $11 one loop result
(15) add $s3 , $s11, $s0 # overwrite the working char for next loop
(16) add $s12, $s5 , $s0 # tmp reg $s12 stores the current key for bne judgement
(17) bne $s12, $s7 , $s8 # if it is NOT the last key ,continue loop
(18) no op
(20) addi $2 , $2 , 1 # plaintext pointer move ahead
(21) load $15 , $2 , 0 # $15 current char
(22) add $3 , $15 ,$0 # $3 working char which will be overwriten during encryption loop
(23) addi $14 ,$14 , 1
(24) addi $4 , $0 , 15 # let the key pointer point to the head of the key again
(25) bne $15 , $0 , $8 # make a definate not equal to jump--Process 0 24 Char
pointer
Working
char
Key
pointer
Current
key value
0x000F
(mask)
Last key
Value
Jump addr Xor
result
RN
index
One loop
result
Current
key
Cipher
pointer
Current
char
10. The Original Design
:-/
1. ALU is just an adder
2. The pc can only run sequentially
3. Every memory is not big enough
11. The Overall Design
1. Change the adder to ALU
2. Program Counter can jump
3. Expand the memory
12. Special Feature 1 : ALU
1. New Input for hierarchical operation code
2. New out put for branch logical
13. Special Feature 2 : Branch
1. New input and output in Reg File for branch addressing
2. Branch logical in the top level between component ALU&PC
3. 7bit MUX to decide sequentially running or jump
18. Results
• VHDL model
plain text are stored from memory(34)
19. Results
• Explanation of simulation
Encryption
key points
1.How to achieve the
loop for encryption of
one char.
2.How to jump to the
next char.
3.how to jump to tag
20. Results
• Explanation of simulation
Tag
key points
1. How to determine "shift" or "no-shift"
2. How to use the second 8-bit key
3. How to reuse the key
21. Results
• Verification of the correctness of results
Encryption
1.initialization
2.Encryption loop for one char
3.Encryption loop for next char
4.jump to tag