# Trivium example

I started learning cryptography from Understanding Cryptography book of Christof Paar and Jan Pelzl. Here is the problem I have solved but I want to be sure that it is correct.

Assume the IV(initialization vector) and the key of Trivium each consists of 80 all-zero bits. Compute the first 70 bits s1....,s70 during the warm-up phase of Trivium. Note that these are only internal bits which are not used for encryption since the warm-up phase lasts for 1152 clock cycles.

Here is my code in Python:

reg_A = [''] * 93
reg_B = [''] * 84
reg_C = [''] * 111

for i in [93, 84, 111]:
for j in range(i):
if i == 93:
reg_A[j] = 0
elif i == 84:
reg_B[j] = 0
elif i == 111:
reg_C[j] = 0

reg_C = reg_C = reg_C = 1
for i in range(80):  # initializing key
reg_A[i] = 0
reg_B[i] = 0

stream = []
for i in range(70):
# first calculate output bits of every register
Cz = reg_C ^ reg_C ^ (reg_C & reg_C)
Ax = reg_A ^ reg_A ^ (reg_A & reg_A)
By = reg_B ^ reg_B ^ (reg_B & reg_B)
# then calculate first bit of every register
a1 = Cz ^ reg_A
b1 = Ax ^ reg_B
c1 = By ^ reg_C
for x in range(92, 0, -1):  # go to 1, because we already have first bit calculated
reg_A[x] = reg_A[x-1]
reg_A = a1
for x in range(83, 0, -1):
reg_B[x] = reg_B[x-1]
reg_B = b1
for x in range(110, 0, -1):
reg_C[x] = reg_C[x-1]
reg_C = c1
stream.append(Ax ^ By ^ Cz)

print reg_A, "FINAL"
print reg_B
print reg_C

print stream, "FINAL STREAM AFTER 70 CLOCKS"


Since I have no solution I don't know how to check if I did it right. That's why I am asking here for help.

• Comments are not for extended discussion; this conversation has been moved to chat. – e-sushi Nov 14 '15 at 19:49

## 1 Answer

I have found an interesting approach to the discussion. I have developed my own version of Trivium and I have tried to solve the exercise described by Nicolas which says:

### Exercise 2.12 - Understanding Cryptography

Assume the IV and the key of Trivium each consist of 80 all-zero bits. Compute the first 70 bits s1, . . . , s70 during the warm-up phase of Trivium. Note that these are only internal bits which are not used for encryption since the warm-up phase lasts for 1152 clock cycles

The exercise mention Warm-up phase. If you read the specifications of the algorithm it has one slight difference between 2.1 (key stream generation) and 2.2 (Key and IV setup). In the former the output is computed right after the 3 XOR operations between 2 bits of each register (as Henno has explained). But in the latter, all the operations are merge.

In conclusion, I have done the following:

1. I have modified the code to print the first 70 bits during 2.2 or warm-up phase and, as a result, I have obtained the following keystream

 0110000000000000000000000000000000000000000000000000000000000000000110

2. I have generated 70 bits using the 2.1 section or Key stream generation phase and the outcome was the keystream below

1110000000000000000000000000000000000000000000000000000000000000000110

As you can see, (1) is equal to Nikola output and (2) is equal to Henno output. It was a tricky exercise. Unfortunatelly, the answer is not provided.