home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / pc / crypto / eurocryp.doc < prev    next >
Encoding:
Text File  |  2003-06-11  |  26.5 KB  |  705 lines

  1. EVRYTHING YOU WANTED TO KNOW ABOUT EUROCRYPT
  2.  
  3. BUT
  4.  
  5. WERE AFRAID NOBODY WOULD TELL YOU
  6.  
  7. BY
  8.  
  9. JOHN MACDONALD
  10.  
  11. This file contains everything I know about the Eurocrypt TV scrambling
  12. system. I have built this knowledge up from scratch by reading articles 
  13. (very few and far between), disassembling PIC programs and then working out 
  14. what they do (interesting) and watching decoder<->card traffic using a 
  15. season-type PC interface (lots of tripping over cables and running between 
  16. rooms). Its not complete, but there's more in it than I've seen anywhere else. 
  17.  
  18. I have written this for two reasons:
  19.  
  20.     1 If any of this is new to you, I hope you find it useful,
  21.       enjoyable and instructive.
  22.  
  23.     2 If you know more than this, please share it with me and I
  24.       will update/correct this to form what will hopefully become
  25.       a definitive document on the subject.
  26.  
  27. You can contact me on the BBS where you found this file.
  28.  
  29. I'll describe the DC<->card protocol, what each instruction does, and how
  30. the DES-based decryption algorithm works for Eurocrypt M and S2. Unless
  31. specified, all numbers are in hex.
  32.  
  33. 1 The Decoder<->Card Protocol
  34.  
  35. When you insert the card into the DC the DC sends a signal down the reset
  36. line as per the ISO 7816 standard and waits for the card to respond. The 
  37. card sends an answer-to-reset sequence of bytes (ATR) which tells the DC
  38. information about the behaviour of the card itself, such as transmission
  39. parameters, manufacturing details etc.
  40.  
  41. For Eurocrypt, the ATR seems to be the 9 byte sequence 
  42.  
  43.     3f 67 2f 00 11 14 00 03 68
  44.  
  45. For anyone who is interested in the nitty-gritty of this, there's a very 
  46. good explanation in a file called atr.zip written by JC, available on BBSs
  47. and the web.
  48.  
  49. The ISO standard defines that the DC addresses the card by sending a 5 byte
  50. header to it containing:
  51.  
  52.     INSTRUCTION CLASS
  53.     INSTRUCTION CODE
  54.     followed by 3 parameters usually called P1, P2, P3.
  55.  
  56. The instruction class is either 87 or ca and can be ignored (I'm not sure
  57. of its significance) and the P3 byte is usually a length byte denoting the
  58. number of bytes to follow or the number of bytes expected to be received
  59. by the DC.
  60.  
  61. How the card behaves depends upon the values of the 5 byte header, but it 
  62. usually sends at some point a 2 byte message called SW1, SW2. This is 90 00
  63. meaning the instruction in the header executed OK or 90 08 meaning there 
  64. was some kind of error. This SW1, SW2 message is also sent at the end of the
  65. ATR.
  66.  
  67. 2 Instruction Processing
  68.  
  69. INSTRUCTION 02
  70.  
  71. After receiving the ATR, the DC sends instruction 02 as:
  72.  
  73.     87 02 00 00 03
  74.  
  75. The 02 instruction seems to be sending 3 bytes to the card - what these mean
  76. I've no idea. So to process an 02 instruction, if P3<>0 send 02 to the DC
  77. as an acknowledgement, then get P3 bytes (3 in the example). If any of these 
  78. bytes are 40 then send 90 08, else send 90 00.
  79.  
  80. INSTRUCTION 04
  81.  
  82. Next the DC sends a packet like
  83.  
  84.     87 04 00 00 07
  85.  
  86. The 04 instruction is requesting some result from the card following the 02 
  87. instruction. So first acknowledge by sending 04 (if P3<>0). All the PIC code
  88. I've looked at sends a fixed message 
  89.  
  90.     00 15 00 00 followed by 3 padding bytes such as ff
  91.  
  92. I don't know what this means. Finally, 90 00 is sent.
  93.  
  94. INSTRUCTION 06
  95.  
  96. The DC then sends
  97.  
  98.     87 06 00 00 04
  99.  
  100. which is asking for a block of data from the card. Again, all the PIC 
  101. programs send 
  102.  
  103.     10 02 ca 20 ff
  104.  
  105. followed by 90 00.
  106.  
  107. I guess this sequence of 02, 04, 06 is some kind of authentication of the 
  108. card and the fixed sequences give the right answers.
  109.  
  110. From here on in the instruction class changes to ca.
  111.  
  112. INSTRUCTION A4
  113.  
  114. The a4 instruction is used to give the card information about the channel's
  115. identity which is used by the card for key selection, expiry data,
  116. entitlements, parental control and pay-per-view (PPV) controls. There are 
  117. several forms of this instruction - we'll concentrate on the form for
  118. channel identification and come back to the others later.
  119.  
  120. The DC sends
  121.  
  122.     ca a4 04 00 03
  123.  
  124. which tells the card that 3 bytes are to be received which indicate the 
  125. channel's id. So since P3<>0 (3 in this case) send a4 to the DC then
  126. receive the three bytes. Then send 90 00. I think that if you send 90 08
  127. the DC displays the 'no access' message but I haven't tested this.
  128.  
  129. Actually the 3 bytes can identify a channel or a group of channels - 
  130. for example, all the TV3s are 00 04 00 and CANAL+ is 10 00 20. Card programs 
  131. typically use this data to construct a byte between 1 and n where n is 
  132. the number of ids supported by the card. We'll call this byte CHAN# and use
  133. it later on.
  134.  
  135. INSTRUCTION 88
  136.  
  137. Immediately after the a4 instruction the DC sends a packet like
  138.  
  139.     ca 88 00 08 24
  140.  
  141. 88 instruction processing is the main decoding work done by the card
  142. protocol handler. The P2 byte (08 in the example) is the key number to be 
  143. used to decode the encrypted data obtained shortly. Each channel has a 
  144. number of 7 byte keys which are used in the decryption and this byte defines
  145. which one is to be used. If the card doesn't have this key stored in its
  146. memory then no decryption can occur! The P3 byte indicates the number of 
  147. bytes to be received by the card, in this example hex 24 ie decimal 36.
  148. In the 24 byte string are two encrypted 8 byte words which have to be 
  149. decrypted using the 7 byte key. Obviously, the P2 and P3 values vary from
  150. channel to channel and time to time.
  151.  
  152. The card must send 77 to the DC in order to receive one of the P3 (24) bytes.
  153. It must do this repetitively until there are 8 bytes left, then it must send 
  154. 89 and receive the last 8 bytes directly. Finally the card sends 90 00.
  155.  
  156. A typical string obtained in this way would be (broken in to substrings for
  157. readibility)
  158.  
  159.     df 00  
  160.     e1 04 20 21 ff 7f
  161.     ea 10 ca a8 e2 1b 4b 7b db 66 8c 29 0a 3b 32 4d 61 5f
  162.     f0 08 8a 18 2d 8b 91 e2 cd 84
  163.  
  164. Byte 2 always seems to be zero, and the 4th byte indicates the length of the 
  165. next substring and I think is always 4 though I haven't checked this 
  166. exhaustively. Bytes 5 and 6 represent a date with the first 7 bits being
  167. the year from 1980, the next 4 bits the month and the last 5 the day of
  168. the month. So the date shown (20 21) is year 0010000 or decimal 16,
  169. month 0001 or 1, and day 00001 or 1 ie January 1 1996. Bytes 7 and 8 are
  170. theme and level.
  171.  
  172. The substring beginning ea contains a length byte (10 or decimal 16)
  173. followed by 2 8 byte words. These are the 2 encrypted words which have 
  174. to be decrypted into 2 8 byte plain words by the card using the 7 byte key 
  175. defined in the 88 packet for the channel defined in the preceding A4
  176. instruction. I'll explain how this is done later.
  177.  
  178. The substring beginning f0 contains a length byte (08) followed by 8 bytes.
  179. This is some kind of checksum which is compared with another bit of 
  180. decryption to verify the result, but I'm not sure of the details.
  181.  
  182. There are variations on this string which cause lots of complexity in the
  183. PIC code I've examined, but basically the idea is straightforward.
  184.  
  185. INSTRUCTION C0
  186.  
  187. Immediately after the exchange described in the last section the DC sends 
  188. the following packet
  189.  
  190.     ca c0 00 00 12
  191.  
  192. This instruction is asking the card to send the two plain words to the DC
  193. and if these are correct, the picture is unscrambled. (Hooray!)
  194.  
  195. The card should first send c0 acknowledging the instruction then ea 10,
  196. followed by the 10 (decimal 16) bytes of plain data. This equates to the 
  197. 12 bytes requested in P3.
  198.  
  199. I have seen another form of the c0 instruction, namely
  200.  
  201.     ca c0 00 00 06
  202.  
  203. From examination of PIC code it seems that this instruction is asking the
  204. card to send the 3 bytes of channel identification (obtained via the a4 04
  205. instruction) followed by 20 00 8f. I don't know what these last 3 bytes mean.
  206.  
  207. INSTRUCTION 18
  208.  
  209. Some of you may wonder how the auto-update feature on twin PIC cards works,
  210. where (usually once a month) the card can deduce what the new key is for 
  211. CANAL+ and Cine Cinemas. Well, this is where the 18 instruction comes in.
  212.  
  213. Prominent in the DC<->card traffic for these channels is a packet like
  214.  
  215.     ca 18 00 06 29
  216.  
  217. The P2 byte (06 in the example) is the key number to be used to decode the 
  218. encrypted data obtained shortly in order to obtain the new key. If the 
  219. card doesn't have this key stored in its memory then no decryption can occur 
  220. and the auto-update won't work. For a reason I don't know, CANAL+ and Cine 
  221. Cinemas use keys 05 and 06 only for this purpose. Therefore in all the PIC
  222. programs I've examined, these keys are present with space in the EEPROM for
  223. the new keys when they've been found.
  224.  
  225. The P3 byte indicates the number of bytes to be received by the card, in 
  226. this example hex 29 ie decimal 41.
  227. In the 29 byte string is an encrypted 8 byte word which has to be decrypted 
  228. using the 7 byte 06 key. The result of this operation is an 8 byte plain
  229. word of which the first 7 bytes are the new key.
  230.  
  231. Obviously, the P2 and P3 values vary from channel to channel and time to time.
  232.  
  233. The string of length P3 (29 in the example) is obtained in exactly the same
  234. way as for instruction 88 except that e7 is used instead of 77 to get a
  235. byte from the DC and 19 is used instead of 89 to get the last 8 bytes.
  236.  
  237. A typical string obtained in this way would be (broken into substrings 
  238. for readibility)
  239.  
  240.     a0 01 22
  241.     a1 03 10 00 36
  242.     a8 06 20 31 20 36 ff ff
  243.     a1 03 10 00 39
  244.     ef 08 14 c4 cb d7 2c 16 1a f2
  245.     f0 08 aa fa 7f c8 b2 65 db 4a
  246.  
  247. Byte 2 is the length of the first substring- I don't know the significance
  248. of this. Byte 5 is the length of the second substring which contains the 
  249. channel id bytes (10 00 30 for Cine Cinemas) concatenated with the base key
  250. to be used (06 in this case). The next substring is preceded by type and
  251. length bytes followed by what look like 2 dates (17th and 22nd Jan 1996)
  252. followed by either theme and level bytes or just ff padding.
  253.  
  254. The fourth substring is similar to the second except that it contains the
  255. number of the new key to be obtained (09 in the example). The fifth 
  256. substring (after the type and length bytes) is a 8 byte encrypted word.
  257. When this is fed through the decryption algorithm (see later) with the base
  258. key (06) a 8 byte plain word is obtained, the first 7 bytes of which are
  259. the new key (09).
  260.  
  261. Given the foregoing, I can't see the need for a touch pad on the twin PIC
  262. card, since the program can find the new key for itself when necessary - 
  263. perhaps someone can enlighten me.
  264.  
  265. The last substring is a checksum as per the 88 instruction.
  266.  
  267. Again there are variations in the number and length of substrings which
  268. can appear, and most of the complexity (and amateurish code) in the PIC
  269. programs I've seen is trying to cope with all the variations of 18 and
  270. 88 substrings with one piece of code. There must be lots of simple ECMs
  271. which would break this code very easily.
  272.  
  273. REMOTE CONTROL INTERFACE
  274.  
  275. There are some instructions which are only used when the remote control is 
  276. used (on mine its a PPV button) for display, parental lock, consultation
  277. and PPV purposes. The exact display format of these depends on the DC used,
  278. but this section describes how the DC<->traffic works. Of course if you're 
  279. only interested in decryption you don't need to implement any of this. 
  280.  
  281. The instructions used are AC, B8, 24 and two variations of the A4 instruction.
  282. The P1 parameter varies in these instructions and acts as a sub-instruction.
  283.  
  284. I'm going to assume that the card sends the instruction to the DC whenever
  285. P3<>0 as an acknowledgement and that it terminates with 90 00 as before.
  286.  
  287. PPV (or whatever its called on your handset)
  288.  
  289. When you ask for a display via the handset the decoder sends the following 
  290. packets
  291.  
  292.     ca a4 00 00 00
  293.     ca ac 08 00 00
  294.     ca b8 00 00 03
  295.  
  296. Remember CHANN# described when we discussed the a4 04 instruction? Well, the
  297. a4 00 instruction tells the card to zeroise this number. The ac 08 
  298. instruction tells the card to select the Lock Status (whatever that is!) and 
  299. the b8 is asking for 3 bytes from the card, presumably the Lock status. The
  300. card that I monitored sent 08 01 08 to the DC which then issued
  301.  
  302.     ca a4 00 00 00
  303.     ca 24 00 00 09
  304.  
  305. I'm not sure what is happening here, but the card sent 25 and the DC then
  306. sent 00 00 00 00 00 00 00 00 08 to the card.
  307.  
  308. CONSULTATION
  309.  
  310. When you take the consultation option from the main menu, the DC sends the
  311. following packet
  312.  
  313.     ca a4 00 00 00
  314.  
  315. to clear CHANN#, then 
  316.  
  317.     ca a4 02 00 00
  318.     ca ac a7 00 00
  319.     ca b8 00 00 12
  320.  
  321. which we'll call Packet A.
  322.  
  323. The a4 02 instruction tells the card to increment CHANN# by 1, the ac a7
  324. instruction asks the card to select the Label for that channel, and the b8
  325. instruction asks the card to send back 12 (decimal 18) bytes containing
  326. the channel Label (eg the literal TV 1000). The card should send a7 as an
  327. acknowledgement, 10 as a length byte, 0e Label bytes padded as necessary,
  328. and 00 00.
  329.  
  330. The DC continues to send Packet A until the supported limit of CHANN# is 
  331. exceeded, although its not exactly clear how this sequence terminates.
  332.  
  333. CONSULTATION - CHANNEL SELECT
  334.  
  335. You use the down arrow keys on your handset to select the channel you wish
  336. to consult and press a select key. The DC sends the following 
  337.  
  338.     ca a4 00 00 00
  339.  
  340. to clear CHANN# followed by
  341.  
  342.     ca a4 02 00 00
  343.  
  344. for each time you pressed the down arrow on your remote. This enables the 
  345. card to increment CHANN# to the correct value for the channel selected. The
  346. DC then sends
  347.  
  348.     ca ac a7 00 00
  349.     ca b8 00 00 12
  350.  
  351. requesting the channel Label and the card reponds as with Packet A. 
  352. Let's call this sequence Packet B. The DC then sends
  353.  
  354.     ca ac ac 00 00
  355.     ca ac b1 00 00
  356.     ca ac b2 00 00
  357.     ca ac ad 00 00
  358.  
  359. I've no idea what this does.
  360.  
  361. SUBSCRIPTION
  362.  
  363. When you take the Subscription option, Packet B is invoked followed by
  364.  
  365.     ca ac a8 00 04 
  366.  
  367. from the DC. The ac a8 instruction is asking for 2 dates (4 bytes) from
  368. the card, presumably subscription start/end dates. The card responds with
  369. (for example) 00 21 27 9f (Jan 1st 1989 and Dec 31st 1999). The DC then
  370. sends
  371.  
  372.     ca b8 00 00 08
  373.  
  374. asking for 8 bytes containg subscription data. The card I monitored sent
  375. a8 for acknowledgement, 06 as a length byte followed by 00 21 ff 9f ff ff.
  376. presumably this was 2 dates (Jan 1st 1980 and Dec 31st 2007) followed by
  377. theme and level bytes.
  378.  
  379. SUBSCRIPTION/LINK
  380.  
  381. I don't even know what this means, but the DC<->card traffic is Packet B to
  382. get the channel Label, then the DC sends
  383.  
  384.     ca ac a9 00 04
  385.  
  386. to which the card sends 4 date bytes, then the DC sends
  387.  
  388.     ca b8 00 00 02
  389.  
  390. asking for 2 data bytes. The card sends a9 05, then the DC sends
  391.  
  392.     ca b8 00 00 05 
  393.  
  394. and the card I monitored sent 00 21 ff 9f bc which was 4 date bytes 
  395. followed by a class byte (whatever that is).
  396.  
  397. PREBOOKED PPV
  398.  
  399. When this option is taken, the traffic is Packet B to get the Label, then
  400. the DC sends 
  401.  
  402.     ca ac aa 00 06
  403.  
  404. presumably asking for 6 bytes containing the PPV pool value. The card I
  405. monitored sent 00 00 00 ff ff ff which is probably some big number.
  406.  
  407. IMPULSE PPV
  408.  
  409. I observed this to be the same as for Prebooked PPV except that the ac
  410. subinstruction was e4 not aa. The DC also responded with the 4 packet 
  411. sequence at the end of Consultation - Channel Select above.
  412.  
  413. ACCESS CONTROL
  414.  
  415. My DC supports four locks, PPV, Consultation, Parental Control and New
  416. Secret Code and these are independent of any channel so no Packet B 
  417. processing is apparent. In each case the DC cleared CHANN# with the
  418. ca a4 00 00 00 packet first.
  419.  
  420. PPV LOCK
  421.  
  422. When I took the unlock option the DC sent 
  423.  
  424.     ca 24 00 00 09 
  425.  
  426. to the card which then received 8 zero bytes followed by 09. This 
  427. presumably would write some data to a genuine card.
  428.  
  429. CONSULTATION LOCK
  430.  
  431. This was as for PPV Lock.
  432.  
  433. PARENTAL CONTROL
  434.  
  435. The DC sent
  436.  
  437.     ca ac 06 00 00
  438.  
  439. which is asking the card to selct a Maturity Rating (Universal, PG etc),
  440. followed by 
  441.  
  442.     ca b8 00 00 03 
  443.  
  444. to which the card responded with 06 01 06. I would have thought the DC
  445. would send a 24 instruction to update the card with the Maturity
  446. rating selected from the onscreen menu, but I didn't observe this.
  447.  
  448. NEW SECRET CODE
  449.  
  450. The dialogue is as per the PPV Lock then the DC sends
  451.  
  452.     ca 24 01 00 10
  453.  
  454. and the card receives 0e bytes of zero followed by a four-nybble secret
  455. code.
  456.  
  457. INSTRUCTION 26
  458.  
  459. This instruction is catered for in the PIC code I've examined, but I've
  460. never monitored its purpose. All the PIC code does is send 6e 90 00 to 
  461. the DC.
  462.  
  463. THE DECRYPTION SYSTEM
  464.  
  465. So far I've described how the key for a channel is obtained, how the two
  466. encrypted words are obtained, and how the decrypted words are sent to the
  467. DC. The next sections deal with the algorithm which is applied to the key
  468. and an encrypted word to obtain a decrypted word.
  469.  
  470. The algorithm is based upon the Data Encryption Standard originally 
  471. created for the secure transmission of military data. There is a very good
  472. scholarly paper on this standard in a file called des-how-.txt by Matthew
  473. Fischer of The University of Iowa on the Web and BBSs which is worth a read.
  474.  
  475. The Eurocrypt system has two flavours, Eurocrypt-M and Eurocrypt-S2 which are
  476. currently used by TV channels. I'll describe M first, then S2.
  477.  
  478. In this section all numbers are decimal unless stated otherwise, not hex.
  479.  
  480. EUROCRYPT-M
  481.  
  482. The main steps in the process are:
  483.  
  484.     - key preparation
  485.     
  486.     - data word manipulation 
  487.     
  488.     - process iteration.
  489.  
  490. In other words, we perform some operations on the key, then manipulate
  491. the data word, do some interaction between the two (based on exclusive
  492. ORing) and repeat the process several times until we have the decrypted
  493. word. In fact the process is performed (decimal) 16 times.
  494.  
  495. KEY PREPARATION
  496.  
  497. This is very straightforward. We have a 7 byte or 56 bit key which we split 
  498. into two 28 bit halves and we rotate each half 1 or 2 bits to the left
  499. depending which of the 16 rounds we're on then put the two halves together.
  500. A single rotation left means that the first (most significant or left hand) 
  501. bit moves to the last (least significant or right hand) position and all the 
  502. other bits move one to the left.
  503.  
  504. The exact number of left rotations is determined by the table:
  505.  
  506. Round            1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16
  507. No of rotations  1  1  2  2  2  2  2  2  1   2   2   2   2   2   2   1
  508.  
  509. We then create a new 48 bit key by reordering 48 of the bits in the 56 bit 
  510. shifted key according to the pattern:
  511.  
  512.                14 17 11 24  1  5                            
  513.             3 28 15  6 21 10                           
  514.                23 19 12  4 26  8                           
  515.                16  7 27 20 13  2                           
  516.                41 52 31 37 47 55                           
  517.                30 40 51 45 33 48                           
  518.                44 49 39 56 34 53                           
  519.                46 42 50 36 29 32     
  520.                
  521. This means that the new 1st bit is the 14th old bit, new 2nd bit is old 17th
  522. and so on with the new 48th bit being the old 32nd bit. The old bits 9, 18, 
  523. 22, 25, 35, 38, 43, 54 are not used. This operation is called a Permutation
  524. and the table is called Permuted Choice 2 or PC-2 in DES terminology.
  525.  
  526. Preparation of the key is now complete for a single round. Note that net
  527. result is that we have a new 48 bit key for use later on.
  528.  
  529. DATA WORD MANIPULATION
  530.  
  531. The encrypted data word is 8 bytes or 64 bits long. The first thing to do is 
  532. to split this into two halves each 32 bits long called L and R. Then we 
  533. build a new R called R1 of length 48 bits by using the pattern:
  534.  
  535.                32  1  2  3  4  5                            
  536.             4  5  6  7  8  9                            
  537.             8  9 10 11 12 13                           
  538.                12 13 14 15 16 17                           
  539.                16 17 18 19 20 21                           
  540.                20 21 22 23 24 25                           
  541.                24 25 26 27 28 29                           
  542.                28 29 30 31 32  1
  543.  
  544. This means our R1 has its 1st bit as old R's last bit, its 2nd bit as old
  545. R's 1st bit and so on with its last bit being the ols R's 1st bit. As you
  546. can see, some of old R's bits are used more than once. The table is called
  547. the Expansion or E-Table.
  548.  
  549. We now XOR this 48 bit R1 with the 48 bit key we prepared earlier, and we 
  550. split the result up into eight 6-bit blocks. Each of these blocks is used
  551. to locate an entry in one of the eight tables below, called Substitution 
  552. or S-Boxes.
  553.  
  554.  
  555.                Substitution Box 1             
  556.            
  557.                14  4 13  1  2 15 11  8  3 10  6 12  5  9  0  7             
  558.             0 15  7  4 14  2 13  1 10  6 12 11  9  5  3  8             
  559.             4  1 14  8 13  6  2 11 15 12  9  7  3 10  5  0            
  560.                15 12  8  2  4  9  1  7  5 11  3 14 10  0  6 13                                  
  561.                
  562.                Substitution Box 2
  563.                
  564.                15  1  8 14  6 11  3  4  9  7  2 13 12  0  5 10             
  565.             3 13  4  7 15  2  8 14 12  0  1 10  6  9 11  5             
  566.             0 14  7 11 10  4 13  1  5  8 12  6  9  3  2 15            
  567.                13  8 10  1  3 15  4  2 11  6  7 12  0  5 14  9                                  
  568.                
  569.                Substitution Box 3
  570.                
  571.                10  0  9 14  6  3 15  5  1 13 12  7 11  4  2  8            
  572.                13  7  0  9  3  4  6 10  2  8  5 14 12 11 15  1            
  573.                13  6  4  9  8 15  3  0 11  1  2 12  5 10 14  7             
  574.             1 10 13  0  6  9  8  7  4 15 14  3 11  5  2 12                                  
  575.             
  576.                Substitution Box 4
  577.  
  578.             7 13 14  3  0  6  9 10  1  2  8  5 11 12  4 15            
  579.                13  8 11  5  6 15  0  3  4  7  2 12  1 10 14  9            
  580.                10  6  9  0 12 11  7 13 15  1  3 14  5  2  8  4             
  581.             3 15  0  6 10  1 13  8  9  4  5 11 12  7  2 14                                  
  582.             
  583.                Substitution Box 5
  584.  
  585.             2 12  4  1  7 10 11  6  8  5  3 15 13  0 14  9            
  586.                14 11  2 12  4  7 13  1  5  0 15 10  3  9  8  6             
  587.             4  2  1 11 10 13  7  8 15  9 12  5  6  3  0 14            
  588.                11  8 12  7  1 14  2 13  6 15  0  9 10  4  5  3                                  
  589.                
  590.                Substitution Box 6
  591.  
  592.                12  1 10 15  9  2  6  8  0 13  3  4 14  7  5 11            
  593.                10 15  4  2  7 12  9  5  6  1 13 14  0 11  3  8             
  594.             9 14 15  5  2  8 12  3  7  0  4 10  1 13 11  6             
  595.             4  3  2 12  9  5 15 10 11 14  1  7  6  0  8 13                                  
  596.             
  597.                Substitution Box 7 
  598.                
  599.             4 11  2 14 15  0  8 13  3 12  9  7  5 10  6  1            
  600.                13  0 11  7  4  9  1 10 14  3  5 12  2 15  8  6             
  601.             1  4 11 13 12  3  7 14 10 15  6  8  0  5  9  2             
  602.             6 11 13  8  1  4 10  7  9  5  0 15 14  2  3 12                                  
  603.             
  604.                Substitution Box 8 
  605.                
  606.                13  2  8  4  6 15 11  1 10  9  3 14  5  0 12  7             
  607.             1 15 13  8 10  3  7  4 12  5  6 11  0 14  9  2             
  608.             7 11  4  1  9 12 14  2  0  6 10 13 15  3  5  8             
  609.             2  1 14  7  4 10  8 13 15 12  9  0  3  5  6 11
  610.  
  611. The entry in the S-Box is found by using the 1st and 6th bits of the 6 bit
  612. block as the row (0, 1, 2, or 3) and the middle 4 bits as the column 
  613. (0 - 15). Also, the 1st 6 bit block uses S-1, the 2nd S-2, and so on with
  614. the 8th using S-8.
  615.  
  616. You will notice that each of the S-Box entries is between 0 and 15; we now
  617. form a new R called R2 from each of the located S-Box entries in order
  618. giving us a new 32 bit R2.
  619.  
  620. The last operation is to create a (third and final) R called R3 from R2 by 
  621. using the following Permutation or P Table:
  622.  
  623.                16  7 20 21                              
  624.                29 12 28 17                               
  625.             1 15 23 26                               
  626.             5 18 31 10                               
  627.             2  8 24 14                              
  628.                32 27  3  9                              
  629.                19 13 30  6                              
  630.                22 11  4 25
  631.  
  632. This means that the 1st bit of R3 is the 16th of R2, the 2nd is the 7th 
  633. and so on, with the 32nd being the 25th bit of R2. 
  634.  
  635. PROCESS ITERATION
  636.  
  637. The net result of the previous section was to split the encrypted word into
  638. two halves, ignore the left-hand one L and eventually create a new right-
  639. hand one R3.
  640.  
  641. Now we XOR L and R3 together, and we've finished a decryption round.
  642.  
  643. For the next round, we treat R3 as the left-hand half of a new data word and 
  644. the result of the XOR operation as the right-hand half and repeat the 
  645. process of key preparation (for that round) and data manipulation (of the 
  646. new data word). We do this 16 times and we end up with a last left-right 
  647. pair of 32 bits each. 
  648.  
  649. Put these together and we have a decrypted 8 byte word. 
  650.  
  651. Continue the whole decryption process for the second encrypted word obtained
  652. from the 88 instruction dialogue and then both can be sent to the DC via 
  653. the C0 instruction dialogue and the TV picture is unscrambled!
  654.  
  655. EUROCRYPT-S2
  656.  
  657. There are three variations on Eurocrypt-M which together form Eurocrypt-S2.
  658.  
  659. KEY PREPARATION
  660.  
  661. The key is split into a left and right pair as before. However, no left
  662. shifting is performed prior to data word manipulation; the shifting is 
  663. performed after the manipulation and the shifts are to the right, not the 
  664. left. 
  665.  
  666. DATA WORD MANIPULATION
  667.  
  668. Before performing the E-table operation, a new data word should be created
  669. using the following permutation:
  670.  
  671.                58 50 42 34 26 18 10  2                        
  672.                60 52 44 36 28 20 12  4                        
  673.                62 54 46 38 30 22 14  6                        
  674.                64 56 48 40 32 24 16  8                        
  675.                57 49 41 33 25 17  9  1                        
  676.                59 51 43 35 27 19 11  3                        
  677.                61 53 45 37 29 21 13  5                        
  678.                63 55 47 39 31 23 15  7
  679.  
  680. This means that the new data word is 64 bits long, and its 1st bit is the 
  681. original word's 58th and so on. This is called the Initial Permutation or IP
  682. and is performed once per 16 decryption rounds.
  683.  
  684. After the decryption is complete as per Eurocrypt-M (ie after 16 rounds),
  685. the decrypted data word is permuted using the following table:
  686.  
  687.                40  8 48 16 56 24 64 32                        
  688.                39  7 47 15 55 23 63 31                        
  689.                38  6 46 14 54 22 62 30                        
  690.                37  5 45 13 53 21 61 29                        
  691.                36  4 44 12 52 20 60 28                        
  692.                35  3 43 11 51 19 59 27                        
  693.                34  2 42 10 50 18 58 26                        
  694.                33  1 41  9 49 17 57 25
  695.  
  696. This means that the final decrypted word is 64 bits long and its first bit
  697. is the previous word's 40th and so on. This is called the Inverse Initial
  698. Permutation or IP**-1.
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.