The improved attack works, and I've been able to recover a few more keys, but it takes a lot of computation time--several hours per game.
I've also experienced some failures, e.g. I could find the key for dimahoo but not for gmahou. This might have been because of a false positive when looking for pairs with the complementation property, so now I'm trying again with a different pair. Since the searches take so long, experimenting isn't easy.
On the plus side, I've applied the improved attack also to some games for which XOR files were not available, and it worked in a number of cases--though it failed in many others.
One of the new versions supported is mshb, which I is the first Brazilian version of a CPS2 game to work.
Andreas has published details on a theoretical attack using differential cryptanalysis which looks promising. If Andy's calculations are correct, it should allow to retrive the key for the three most problematic games: spf2t, spf2xj, and spf2ta. It does require a lot of (E,D,k) triplets, something in the order of 216-217, which is a bit steep, but we should be able to do that in a few cases.
One thing to note about my attack, which I might not have explained clearly, is that it requires a remarkably small amount of data: it has worked for many games with just 7 (E,D) pairs. The problem is that those pairs must all be at the same address (as far as the encryption is concerned; that is, bits 1-16 of the address must be the same). Those 7 pairs allow to retrieve the 96-bit key for the second round at that address, and once that is known, the 64-bit master key can be found in less than 1 second, without having to know ANY other (E,D) pair at any address.
Unfortunately for game like spf2t, whose full encryption range covers just 2 repetitions of an address, we are never going to have 7 pairs so the attack will never work.
Friday, January 19, 2007
Wednesday, January 17, 2007
CPS2 The Fight Continues
I've finished going through all the games previously supported by MAME using XOR files, and generating keys using this attack.
The attack needs a minimum of 7 (E,D) pairs at some address in order to work, though with just 7 pairs it takes several hours to find the key.
Most of the games provided at least 8 pairs, a few 7, so the attack worked.
On 11 games the attack didn't work. Three of them only provide 2 pairs, so there's no way for the attack to work--a different approach will be needed.
The others provide 4 pairs, and I'm now trying to still perform the attack, using a new trick.
Remember the complementation property? For every address A, we know that exists another address A1 such that D(X, A) = D(X ^ 0xffff, A1) ^ 0xffff. The problem is that we don't know A1. We can search it, however, using the XOR data. Pick an address, look at the four (E,D) pairs associated to it, and then see if at another address there is a pair (E ^ 0xffff, D ^ 0xffff). That way we can put together the information from the two addresses, raising the number of pairs from 4 to 7, barely enough to run the attack.
There's a possibility of false positives when doing this, so avoid all pairs where E or D are 0x0000 or 0xffff, because those values are very common and make the probablity of a false positive much higher.
In theory this trick should work, though it will require some luck and a lot of time. The holy grail remains an attack which could use pairs from different addresses; that would be the only way to retrieve the key for the games that lack XORs.
The attack needs a minimum of 7 (E,D) pairs at some address in order to work, though with just 7 pairs it takes several hours to find the key.
Most of the games provided at least 8 pairs, a few 7, so the attack worked.
On 11 games the attack didn't work. Three of them only provide 2 pairs, so there's no way for the attack to work--a different approach will be needed.
The others provide 4 pairs, and I'm now trying to still perform the attack, using a new trick.
Remember the complementation property? For every address A, we know that exists another address A1 such that D(X, A) = D(X ^ 0xffff, A1) ^ 0xffff. The problem is that we don't know A1. We can search it, however, using the XOR data. Pick an address, look at the four (E,D) pairs associated to it, and then see if at another address there is a pair (E ^ 0xffff, D ^ 0xffff). That way we can put together the information from the two addresses, raising the number of pairs from 4 to 7, barely enough to run the attack.
There's a possibility of false positives when doing this, so avoid all pairs where E or D are 0x0000 or 0xffff, because those values are very common and make the probablity of a false positive much higher.
In theory this trick should work, though it will require some luck and a lot of time. The holy grail remains an attack which could use pairs from different addresses; that would be the only way to retrieve the key for the games that lack XORs.
Sunday, January 14, 2007
CPS2 Getting Closer
The correlations between the 96-bit keys of the two Feistel networks were crucial in getting the s-boxes with 4 or 5 inputs "in sync"--that is, make them idential to the real ones apart from a fixed XOR or permutation applied to the whole box.
Eventually, I ended with a layout which I'm 99.9% sure is equivalent to the real one. We cannot know the exact contents of the real s-boxes without getting them from the actual hardware, but the current ones should be matematically equivalent.
The result is here: http://xoomer.alice.it/nicola.salmoria/cps2crptv2.zip.
The most notable news is that the key is now reduced to 64 bits, and the one we are currently using should be identical to the one used by the hardware, apart from a fixed permutation of the bits.
Finding the real permutation would be nice, but obviously that's not something we can determine from the algorithm, since the order of the bits of the key is completely irrelevant.
What is interesting to note is that the keys used by some games don't seem to be random. If they were random one would expect there to be around 32 0s and 32 1s, but sometimes this isn't the case. E.g.
Of these, the last three literally scream "I'm not a random number!". Guessing the right bit order to make something appear, of course, is another matter.
Some of the watchdog values contain birth dates, e.g. cmpi.l #$19660419,D1, so I expect the same thing might be happening here.
Also, it makes sense for the pzloop2 one to be more regular than the others because it's third party game.
On the key extraction front, things are going reasonably well. The brute force attack described in the previous article is working decently on most games, however for some of them the available data isn't enough. I'll have a more precise list once I've finished going through all the games. After that, we'll need to devise a better attack if we want to get the missing keys.
The discovery that the key is only 64 bits might help to construct a better attack, though at the moment I don't have many ideas. The fact that the algorithm is divided in two parts, with the output of the first one affecting the key on the second part, complicates things.
Eventually, I ended with a layout which I'm 99.9% sure is equivalent to the real one. We cannot know the exact contents of the real s-boxes without getting them from the actual hardware, but the current ones should be matematically equivalent.
The result is here: http://xoomer.alice.it/nicola.salmoria/cps2crptv2.zip.
The most notable news is that the key is now reduced to 64 bits, and the one we are currently using should be identical to the one used by the hardware, apart from a fixed permutation of the bits.
Finding the real permutation would be nice, but obviously that's not something we can determine from the algorithm, since the order of the bits of the key is completely irrelevant.
What is interesting to note is that the keys used by some games don't seem to be random. If they were random one would expect there to be around 32 0s and 32 1s, but sometimes this isn't the case. E.g.
pzloop2: 3332206a0077f829
mshj: 01c0c951370f4c80
dstlka: 04048b4e2a498879
ringdest: 0405541367806575
cybotsj: 0404821534388354
Of these, the last three literally scream "I'm not a random number!". Guessing the right bit order to make something appear, of course, is another matter.
Some of the watchdog values contain birth dates, e.g. cmpi.l #$19660419,D1, so I expect the same thing might be happening here.
Also, it makes sense for the pzloop2 one to be more regular than the others because it's third party game.
On the key extraction front, things are going reasonably well. The brute force attack described in the previous article is working decently on most games, however for some of them the available data isn't enough. I'll have a more precise list once I've finished going through all the games. After that, we'll need to devise a better attack if we want to get the missing keys.
The discovery that the key is only 64 bits might help to construct a better attack, though at the moment I don't have many ideas. The fact that the algorithm is divided in two parts, with the output of the first one affecting the key on the second part, complicates things.
Friday, January 12, 2007
How to bruteforce CPS2
I couldn't devise an attack using differential cryptanalysis and the XOR files. The fact that the second 96-bit key changes with the address makes thing more difficult, and I couldn't think of a way to effectively use data from different addresses.
The XOR files give us no more than 8-16 (E,D) pairs at a given address (remember that the encryption only uses the low 16 bits of the address). We have no choice of what data we have, so we have to make the best of it.
So the idea I had is to use a meet in the middle brute force attack which exploits a weakness in the s-boxes.
Remember that
L1 = R0
R1 = L0 XOR f1(R0)
L2 = R1
R2 = L1 XOR f2(R1)
L3 = R2
R3 = L2 XOR f3(R2)
L4 = R3
R4 = L3 XOR f4(R3)
Remember also that the fn round functions are made of 4 s-boxes each.
These are the 16 s-boxes, with their inputs and outputs:
f2b1 is the weakest link. It has only four inputs, 0246. To get those four inputs, we need just three boxes in round 1: f1b1, which outputs 67, f1b3, which outputs 14, and f1b4, which outputs 02. We don't need f1b2, which outputs 35.
So if we start from the ciphertext and run it through the first two rounds of the Feistel network, scanning all 224 possible keys for f1b1, f1b3, f1b4, and f2b1, we'll get all possible values for bits 46 of R2.
Now let's start from the plaintext instead, and go up. If we scan all 26 keys for f4b2, we'll get all possible values for bits 47 of R2 again.
Now we impose that bit 4 calculated in these two ways is the same, and given enough (E,D) pairs we have a huge pruning of the valid keys. From experiments, at least 8 pairs are needed for the attack to work effectively, but with 12 it's faster.
When we have a match on bit 4, we start adding more key bits, 6 or 12 at a time. First f4b4, to match bit 6 of R2. Then f1b2 and f2b3, to match bit 7 of R2. At this point, we are most likely already left with a single key, so adding more key bits doesn't increase the computation time. The important thing is to do it 6 bits at a time, in order to avoid unnecessary calculations. Soon enough, we have reconstructed the whole 96-bit key.
This will be the key at a specific address--of course, before running the search we'd have scanned the whole data and selected the address with most different pairs, in order to make the attack more effective.
After the 96-bit key at one address is found, the rest is easy. Since the 96-bit key is modified by the 16-bit result of the first FN in a fixed way, we just use brute force to find the correct 16-bit value at every address, and then we have a full subkey table as when we had the full 8GB tables at the beginning.
The process is working reasonably well, it's taking me 20-40 minutes to find the 192-bit key for a game. It could be made faster, probably. I've done some games for which I had more data, and Razoola was kind enough to provide additional data that will help with many other games. I'm not yet sure that the attack will work on all games, but it surely will on a good percentage.
Some very good news after obtaining more keys is that I found strong correlations between the first and second 96-bit keys, so they are effectively the same key, just permuted. This will also allow to fix the order of the subtables in the s-boxes of the first FN, in the same way I did for the second.
Should we consider ourselves finished after that?
Not yet: whether it will be possible to generate keys for games for which we lack XOR data is an open problem. In that case, the best we can expect to do is to match the startup code from a different version of the game, so we'll have several (E,D) pairs at consecutive addresses, and no more than one pair at a given address. A new attack will have to be devised in order to use that kind of information. Hopefully the discovery that the first and second 96-bit keys are correlated will help.
The XOR files give us no more than 8-16 (E,D) pairs at a given address (remember that the encryption only uses the low 16 bits of the address). We have no choice of what data we have, so we have to make the best of it.
So the idea I had is to use a meet in the middle brute force attack which exploits a weakness in the s-boxes.
Remember that
L1 = R0
R1 = L0 XOR f1(R0)
L2 = R1
R2 = L1 XOR f2(R1)
L3 = R2
R3 = L2 XOR f3(R2)
L4 = R3
R4 = L3 XOR f4(R3)
Remember also that the fn round functions are made of 4 s-boxes each.
These are the 16 s-boxes, with their inputs and outputs:
f1b1 03457- 67
f1b2 12346- 35
f1b3 124567 14
f1b4 023567 02
f2b1 0246-- 46
f2b2 134567 03
f2b3 013457 17
f2b4 123567 25
f3b1 2346-- 35
f3b2 01357- 02
f3b3 012357 16
f3b4 024567 47
f4b1 01367- 03
f4b2 012456 47
f4b3 023457 12
f4b4 234567 56
f2b1 is the weakest link. It has only four inputs, 0246. To get those four inputs, we need just three boxes in round 1: f1b1, which outputs 67, f1b3, which outputs 14, and f1b4, which outputs 02. We don't need f1b2, which outputs 35.
So if we start from the ciphertext and run it through the first two rounds of the Feistel network, scanning all 224 possible keys for f1b1, f1b3, f1b4, and f2b1, we'll get all possible values for bits 46 of R2.
Now let's start from the plaintext instead, and go up. If we scan all 26 keys for f4b2, we'll get all possible values for bits 47 of R2 again.
Now we impose that bit 4 calculated in these two ways is the same, and given enough (E,D) pairs we have a huge pruning of the valid keys. From experiments, at least 8 pairs are needed for the attack to work effectively, but with 12 it's faster.
When we have a match on bit 4, we start adding more key bits, 6 or 12 at a time. First f4b4, to match bit 6 of R2. Then f1b2 and f2b3, to match bit 7 of R2. At this point, we are most likely already left with a single key, so adding more key bits doesn't increase the computation time. The important thing is to do it 6 bits at a time, in order to avoid unnecessary calculations. Soon enough, we have reconstructed the whole 96-bit key.
This will be the key at a specific address--of course, before running the search we'd have scanned the whole data and selected the address with most different pairs, in order to make the attack more effective.
After the 96-bit key at one address is found, the rest is easy. Since the 96-bit key is modified by the 16-bit result of the first FN in a fixed way, we just use brute force to find the correct 16-bit value at every address, and then we have a full subkey table as when we had the full 8GB tables at the beginning.
The process is working reasonably well, it's taking me 20-40 minutes to find the 192-bit key for a game. It could be made faster, probably. I've done some games for which I had more data, and Razoola was kind enough to provide additional data that will help with many other games. I'm not yet sure that the attack will work on all games, but it surely will on a good percentage.
Some very good news after obtaining more keys is that I found strong correlations between the first and second 96-bit keys, so they are effectively the same key, just permuted. This will also allow to fix the order of the subtables in the s-boxes of the first FN, in the same way I did for the second.
Should we consider ourselves finished after that?
Not yet: whether it will be possible to generate keys for games for which we lack XOR data is an open problem. In that case, the best we can expect to do is to match the startup code from a different version of the game, so we'll have several (E,D) pairs at consecutive addresses, and no more than one pair at a given address. A new attack will have to be devised in order to use that kind of information. Hopefully the discovery that the first and second 96-bit keys are correlated will help.
Tuesday, January 09, 2007
CPS2 coming to MAME
I've submitted to MAMEDEV the code to replace the 4GB CHDs with 192-bit keys.
The code is here: http://xoomer.alice.it/nicola.salmoria/cps2crpt.zip
It contains all the information needed to understand the algorithm, including the s-boxes.
There is still a lot of uncertainty about the contents of the s-boxes. They do their job, but since they are different from the originals they also affect the key. Using the real s-boxes might make correlations between the key bits more apparent, if they exist (anyway, having only 7 keys to look at, there's not enough data to speculate on any kind of correlation).
I'm hoping that it will be possible to extract the s-boxes contents from photos of the decapped CPS2 chip. That would be an important step forward in the accuracy of the emulation.
Now the next challenge is finding the keys for the other CPS2 games that have XOR files but not full tables. I have some ideas, but it doesn't look simple.
We have a lot of (E,D,k) triplets for those games, but unfortunately not many once you fix k (the 96-bit key used in the second FN), and that would be the most important part.
Note that we don't have to find the whole 192-bit key all at once. Once the second 96-bit was found, then we could easily use brute force to get the 16-bit key seed at every address, and therefore easily find the first 96-bit key.
The code is here: http://xoomer.alice.it/nicola.salmoria/cps2crpt.zip
It contains all the information needed to understand the algorithm, including the s-boxes.
There is still a lot of uncertainty about the contents of the s-boxes. They do their job, but since they are different from the originals they also affect the key. Using the real s-boxes might make correlations between the key bits more apparent, if they exist (anyway, having only 7 keys to look at, there's not enough data to speculate on any kind of correlation).
I'm hoping that it will be possible to extract the s-boxes contents from photos of the decapped CPS2 chip. That would be an important step forward in the accuracy of the emulation.
Now the next challenge is finding the keys for the other CPS2 games that have XOR files but not full tables. I have some ideas, but it doesn't look simple.
We have a lot of (E,D,k) triplets for those games, but unfortunately not many once you fix k (the 96-bit key used in the second FN), and that would be the most important part.
Note that we don't have to find the whole 192-bit key all at once. Once the second 96-bit was found, then we could easily use brute force to get the 16-bit key seed at every address, and therefore easily find the first 96-bit key.
Monday, January 08, 2007
CPS2 Fundamental Breakthrough
Today I realised why I was having problems with the correlations between subkey bits, where some bits had to be derived from the others not only using XOR, but also AND and OR.
The reason was again in the s-boxes that only have 4 or 5 data inputs instead of the full 6. Those boxes contain 2 or 4 subtables, and the order of the subtables inside the box or the order of the bits inside each subtable isn't particularly important when decrypting a single address, because they can always be compensated by appropriate bits in the subkey.
However, when putting all subkeys together, those things became important. E.g. I could be finding that when using subtable #3 in a box, then two of the inputs had to be inverted. To fix this, I had to rearrange the subtables inside the s-boxes to make everything in sync.
The result was excellent. Previously, some of the correlations among the 96 bits were overly complex, taking up to 4 bits at once. Now every bit is directly correlated to another. The only exception is the bits that correspond to the "empty" inputs of s-boxes that take only 4 or 5 data inputs. What this means is that all 6 inputs of all s-boxes always receive the XOR of three sources: either a data bit, a key seed bit, and a global key bit; or two key seed bits, and a global key bit.
That's only the beginning of the good news, though. After fixing the s-boxes, I could attack again the first part on the algorithm on the assumption it was a 4-round Feistel network, and indeed it was.
So the algorithm turns out to be like this:
So now, for the first time, I would be able to produce a program that algorithmically decrypts one of the game for which we have full tables, without using any table.
It's not yet time to celebrate, though: the s-boxes for the first Feistel network still have to be properly determined, and this might require having access to some more games.
Once that is done, producing keys for games that we have complete tables for will be quite simple.
Finding keys for games for which we don't have full tables, however, is an entirely different matter. As said above, we are potentially dealing with a 192-bit key here; it's possible that the key is smaller and the bits are reused, however since we don't know how they would be, we have to treat it like a 192-bit one. For a key of that size, obviously brute force is out of the question; and while the XOR tables do provide some information, it's probably not the kind of information that would allow to use the differential cryptanalysis techniques we'd need.
The reason was again in the s-boxes that only have 4 or 5 data inputs instead of the full 6. Those boxes contain 2 or 4 subtables, and the order of the subtables inside the box or the order of the bits inside each subtable isn't particularly important when decrypting a single address, because they can always be compensated by appropriate bits in the subkey.
However, when putting all subkeys together, those things became important. E.g. I could be finding that when using subtable #3 in a box, then two of the inputs had to be inverted. To fix this, I had to rearrange the subtables inside the s-boxes to make everything in sync.
The result was excellent. Previously, some of the correlations among the 96 bits were overly complex, taking up to 4 bits at once. Now every bit is directly correlated to another. The only exception is the bits that correspond to the "empty" inputs of s-boxes that take only 4 or 5 data inputs. What this means is that all 6 inputs of all s-boxes always receive the XOR of three sources: either a data bit, a key seed bit, and a global key bit; or two key seed bits, and a global key bit.
That's only the beginning of the good news, though. After fixing the s-boxes, I could attack again the first part on the algorithm on the assumption it was a 4-round Feistel network, and indeed it was.
So the algorithm turns out to be like this:
- Take the 16-bit address and a 96-bit key and run them through the first Feistel network, to produce a 16-bit subkey.
- Take the 16-bit ciphertext, 16-bit subkey, and another 96-bit key and run them through the second Feistel network, to produce the 16-bit plaintext
So now, for the first time, I would be able to produce a program that algorithmically decrypts one of the game for which we have full tables, without using any table.
It's not yet time to celebrate, though: the s-boxes for the first Feistel network still have to be properly determined, and this might require having access to some more games.
Once that is done, producing keys for games that we have complete tables for will be quite simple.
Finding keys for games for which we don't have full tables, however, is an entirely different matter. As said above, we are potentially dealing with a 192-bit key here; it's possible that the key is smaller and the bits are reused, however since we don't know how they would be, we have to treat it like a 192-bit one. For a key of that size, obviously brute force is out of the question; and while the XOR tables do provide some information, it's probably not the kind of information that would allow to use the differential cryptanalysis techniques we'd need.
Sunday, January 07, 2007
CPS2 Won't Be Tamed That Easily
Some people thought we were almost finished with the CPS2 algorithm, but this doesn't seem to be the case.
True, at least the 4GB tables could now be replaced with a single 128kB table, but that's still not how the hardware works, and it wouldn't be possible to generate proper keys for the games that are missing the full 8GB tables, which is the main concern.
From the full tables, we can extract a 96-bit subkey for every address.
Edit: I had a link to a file here. I've removed it since I've found an error which I'll correct soon.
These wouldn't be the actual keys used by the hardware, however I think me and Andy have agreed that they are, apart from a fixed XOR and bit permutation that wouldn't change from game to game. So we can forget about this step of the decryption for the time being, and move on.
The problem now is to understand how the hardware generates the 96-bit subkey starting from the address and from the global key.
I have determined that only 16 bits are needed to generate the 96-bit subkey; this was sort of expected, but it isn't without problems.
We can generate only 94 bits of the subkey starting from those 16 bits and using only XOR operations. The remaining 2 bits need AND/OR operations, something which I have no explaination for at this point.
That was the least of the problems anyway. The major hurdle at this point is that the mapping from address to 16-bit key seed is very far from trivial.
The scheme should be as follows:
I think it would make sense for the algorithm in step 1. to be another 4-round Feistel network.
If this is the case, things are quite harder than before. To break the other Feistel network, we could rely on complete knowledge of ciphertext-plaintext relationship. Now we can't: we only have a vague idea of what the 16-bit key seed could be.
If we could rely on a 16-bit value except for a constant XOR and permutation, it wouldn't be a problem, since that wouldn't change the nature of the Feistel network. Unfortunately, we don't have that luxury.
Let's see that with an example. Let's say that the first algorithm generates a 4-bit key seed, abcd, which is expanded into the 6-bit subkey ABCDEF this way:
A = a
B = a XOR b
C = a XOR c
D = b XOR c
E = b XOR d
F = b XOR c XOR d
We don't know anything about abcd, all we see is ABCDEF, but we need to guess what abcd looks like. So we notice that
D = B XOR C
F = A XOR C XOR E
and we decide that
a' = A
b' = B
c' = C
d' = E
so we would have
A = a'
B = b'
C = c'
D = b' XOR c'
E = d'
F = a' XOR c' XOR d'
This all works as far as generating the subkey from the seed goes, the problem is that abcd and a'b'c'd' are two completely different numbers! We have that
a'b'c'd' = abcd XOR aab
so this isn't simply a XOR with a constant value, it's a variable modification of the number. And this is something that the Feistel network cannot handle.
True, at least the 4GB tables could now be replaced with a single 128kB table, but that's still not how the hardware works, and it wouldn't be possible to generate proper keys for the games that are missing the full 8GB tables, which is the main concern.
From the full tables, we can extract a 96-bit subkey for every address.
Edit: I had a link to a file here. I've removed it since I've found an error which I'll correct soon.
These wouldn't be the actual keys used by the hardware, however I think me and Andy have agreed that they are, apart from a fixed XOR and bit permutation that wouldn't change from game to game. So we can forget about this step of the decryption for the time being, and move on.
The problem now is to understand how the hardware generates the 96-bit subkey starting from the address and from the global key.
I have determined that only 16 bits are needed to generate the 96-bit subkey; this was sort of expected, but it isn't without problems.
We can generate only 94 bits of the subkey starting from those 16 bits and using only XOR operations. The remaining 2 bits need AND/OR operations, something which I have no explaination for at this point.
That was the least of the problems anyway. The major hurdle at this point is that the mapping from address to 16-bit key seed is very far from trivial.
The scheme should be as follows:
- take 16-bit address, N-bit global key, and generate a 16-bit key seed using an unknown algorithm.
- take 16-bit key seed, M-bit global key, and generate 96-bit subkey using an unknown algorithm.
- take 16-bit ciphertext, 96-bit subkey, and generate 16-bit plaintext using the algorithm we have discovered.
I think it would make sense for the algorithm in step 1. to be another 4-round Feistel network.
If this is the case, things are quite harder than before. To break the other Feistel network, we could rely on complete knowledge of ciphertext-plaintext relationship. Now we can't: we only have a vague idea of what the 16-bit key seed could be.
If we could rely on a 16-bit value except for a constant XOR and permutation, it wouldn't be a problem, since that wouldn't change the nature of the Feistel network. Unfortunately, we don't have that luxury.
Let's see that with an example. Let's say that the first algorithm generates a 4-bit key seed, abcd, which is expanded into the 6-bit subkey ABCDEF this way:
A = a
B = a XOR b
C = a XOR c
D = b XOR c
E = b XOR d
F = b XOR c XOR d
We don't know anything about abcd, all we see is ABCDEF, but we need to guess what abcd looks like. So we notice that
D = B XOR C
F = A XOR C XOR E
and we decide that
a' = A
b' = B
c' = C
d' = E
so we would have
A = a'
B = b'
C = c'
D = b' XOR c'
E = d'
F = a' XOR c' XOR d'
This all works as far as generating the subkey from the seed goes, the problem is that abcd and a'b'c'd' are two completely different numbers! We have that
a'b'c'd' = abcd XOR aab
so this isn't simply a XOR with a constant value, it's a variable modification of the number. And this is something that the Feistel network cannot handle.
Saturday, January 06, 2007
CPS2 Subkeys
I said earlier that I was going to post the program to extract subkeys from a CHD, and the subkey lists for a few games, however after extracting the subkeys I found important relationships between the subkey bits so I'll have to work on that first.
A subkey consists of 24*4 = 96 bits. There are 65536 subkeys, so the total is 786kB of data.
What I found that one bit of the subkey is constant, while 59 can be derived from the others with a XOR (which is constant for all 65536 addresses, but changes from game to game).
So this hints at a 64-bit global key, while the independent subkey bits drop for now at 96-1-59 = 36 bits.
A subkey consists of 24*4 = 96 bits. There are 65536 subkeys, so the total is 786kB of data.
What I found that one bit of the subkey is constant, while 59 can be derived from the others with a XOR (which is constant for all 65536 addresses, but changes from game to game).
So this hints at a 64-bit global key, while the independent subkey bits drop for now at 96-1-59 = 36 bits.
Friday, January 05, 2007
CPS2 S-Boxes ready
Andy has published his program but is reporting some problems in recreating the original tables--the values generated by his program are XORed with a constant value when compared with the original table.
I have just verified that this doesn't happen to me, so I presume this is due to a different method we used to reconstruct the Feistel function for the first two rounds.
Let's recap how this was done. The fundamental idea was published by Andy:
since R4 = L3 XOR F4(L4), if you pick (E,D) and (E',D') such that L4 = L'4, then
R'4 = L'3 XOR F4(L'4) = L'3 XOR F4(L4) = L'3 XOR R4 XOR L3
therefore
L3 XOR L'3 = R4 XOR R'4
Now if we pick (E,D) and (E',D') such that L4 = L'4 and E and E' differ by only one bit, we can see how flipping a single bit in the input changes the output after the third round. Andy's fundamental discovery was that flipping certain bits never affects certain other bits.
That knowledge can easily be used to determine F4. Take (E,D) and (E',D'), where E and E' differ only by one bit which we know doesn't affect bit b in L3. Then we know that
Bb(L3 XOR L'3) = 0
where Bb(x) gives me the value of bit b of x.
Therefore
Bb(R4 XOR F4(L4) XOR R'4 XOR F4(L'4)) = 0
that is,
Bb(F4(L4) XOR F4(L'4)) = Bb(R4 XOR R'4)
Do that for all b and for all E, E' pairs, and you quickly reconstruct the whole F4 structure. I'm saying its structure and not F4 itself, because it's all done through XOR so you need to set F4(0) arbitrarily, then all the others are derived from it through XOR.
After F4 is reconstructed, it can be used to undo the fourth round of the encryption. Then you repeat exactly the same process to reconstruct F3 (still XOR an arbitrary value). Then use F3 to undo the third round, and you are left with just two rounds.
Now things get really simple, because by definition
L2 = L0 XOR F1(R0)
R2 = R0 XOR F2(L2)
and since you know all of L0, R0, L2, and R2, F1 and F2 are immediately derived as
F1(R0) = L0 XOR L2
F2(L2) = R0 XOR R2
Note that here we derive F1 and F2 explicitly, not XOR an arbitrary value.
I have just verified that this doesn't happen to me, so I presume this is due to a different method we used to reconstruct the Feistel function for the first two rounds.
Let's recap how this was done. The fundamental idea was published by Andy:
since R4 = L3 XOR F4(L4), if you pick (E,D) and (E',D') such that L4 = L'4, then
R'4 = L'3 XOR F4(L'4) = L'3 XOR F4(L4) = L'3 XOR R4 XOR L3
therefore
L3 XOR L'3 = R4 XOR R'4
Now if we pick (E,D) and (E',D') such that L4 = L'4 and E and E' differ by only one bit, we can see how flipping a single bit in the input changes the output after the third round. Andy's fundamental discovery was that flipping certain bits never affects certain other bits.
That knowledge can easily be used to determine F4. Take (E,D) and (E',D'), where E and E' differ only by one bit which we know doesn't affect bit b in L3. Then we know that
Bb(L3 XOR L'3) = 0
where Bb(x) gives me the value of bit b of x.
Therefore
Bb(R4 XOR F4(L4) XOR R'4 XOR F4(L'4)) = 0
that is,
Bb(F4(L4) XOR F4(L'4)) = Bb(R4 XOR R'4)
Do that for all b and for all E, E' pairs, and you quickly reconstruct the whole F4 structure. I'm saying its structure and not F4 itself, because it's all done through XOR so you need to set F4(0) arbitrarily, then all the others are derived from it through XOR.
After F4 is reconstructed, it can be used to undo the fourth round of the encryption. Then you repeat exactly the same process to reconstruct F3 (still XOR an arbitrary value). Then use F3 to undo the third round, and you are left with just two rounds.
Now things get really simple, because by definition
L2 = L0 XOR F1(R0)
R2 = R0 XOR F2(L2)
and since you know all of L0, R0, L2, and R2, F1 and F2 are immediately derived as
F1(R0) = L0 XOR L2
F2(L2) = R0 XOR R2
Note that here we derive F1 and F2 explicitly, not XOR an arbitrary value.
Wednesday, January 03, 2007
CPS2 is not a 4-round Feistel network (...NOT)
Edit: As Andy pointed out, the following reasoning is fatally flawed by the fact that the fn functions are not bijective.
So, given the strong evidence Andy has found, it really looks like the algorithm is a 4-round Feistel network.
This is actually good news, I have to say I am relieved ;)
Remember that
L1 = R0
R1 = L0 XOR f1(R0)
L2 = R1
R2 = L1 XOR f2(R1)
L3 = R2
R3 = L2 XOR f3(R2)
L4 = R3
R4 = L3 XOR f4(R3)
In the previous article I showed that if we take (E,D) and (E',D') such that L0 XOR L4 = L'0 XOR L'4 and R0 = R'0, then
R2 = R'2.
I'll now take a different route from the one I took yesterday, to avoid the flaw that Andy noticed.
From R2 = R'2 follows that
L1 XOR f2(R1) = L'1 XOR f2(R'1), that is
R0 XOR f2(R1) = R'0 XOR f2(R'1), that is (since R0 = R'0)
f2(R1) = f2(R'1), that is (since f2 is bijective)
R1 = R'1, that is
L0 XOR f1(R0) = L'0 XOR f1(R'0), that is (since R0 = R'0)
L0 = L'0, therefore
(E,D) = (E',D')
Therefore two different pairs with the requested property cannot exist.
When converting the 16-bit values to and from (L,R) pairs, we need to take the initial and final permutation into account. Note that we are not using R4 in the above; we are only using L0, R0, and L4. Also, we don't care about the effects of the permutation on L0 and R0, the only thing we care about is that when we do L0 XOR L4 we XOR the correct bits together. So we can arbitrarily fix the permutation on L0 and R0, and try all possible permutations on L4.
So if the CPS2 algorithm were a Feistel network, for some permutation of the bits in L4 it should not be possible to select two different pairs (E,D) and (E',D') with the requested property.
This doesn't happen: for every permutation, such pairs exist. Therefore CPS2 is not just a 4-round Feistel network.
This is not to say that Andy isn't on the right track, on the contrary, the findings in CPS-2 (5) are extremely interesting, but the algorithm cannot be just a 4-round Feistel network. There's something else we are missing.
So, given the strong evidence Andy has found, it really looks like the algorithm is a 4-round Feistel network.
This is actually good news, I have to say I am relieved ;)
Remember that
L1 = R0
R1 = L0 XOR f1(R0)
L2 = R1
R2 = L1 XOR f2(R1)
L3 = R2
R3 = L2 XOR f3(R2)
L4 = R3
R4 = L3 XOR f4(R3)
In the previous article I showed that if we take (E,D) and (E',D') such that L0 XOR L4 = L'0 XOR L'4 and R0 = R'0, then
R2 = R'2.
I'll now take a different route from the one I took yesterday, to avoid the flaw that Andy noticed.
From R2 = R'2 follows that
L1 XOR f2(R1) = L'1 XOR f2(R'1), that is
R0 XOR f2(R1) = R'0 XOR f2(R'1), that is (since R0 = R'0)
f2(R1) = f2(R'1), that is (since f2 is bijective)
R1 = R'1, that is
L0 XOR f1(R0) = L'0 XOR f1(R'0), that is (since R0 = R'0)
L0 = L'0, therefore
(E,D) = (E',D')
Therefore two different pairs with the requested property cannot exist.
When converting the 16-bit values to and from (L,R) pairs, we need to take the initial and final permutation into account. Note that we are not using R4 in the above; we are only using L0, R0, and L4. Also, we don't care about the effects of the permutation on L0 and R0, the only thing we care about is that when we do L0 XOR L4 we XOR the correct bits together. So we can arbitrarily fix the permutation on L0 and R0, and try all possible permutations on L4.
So if the CPS2 algorithm were a Feistel network, for some permutation of the bits in L4 it should not be possible to select two different pairs (E,D) and (E',D') with the requested property.
This doesn't happen: for every permutation, such pairs exist. Therefore CPS2 is not just a 4-round Feistel network.
This is not to say that Andy isn't on the right track, on the contrary, the findings in CPS-2 (5) are extremely interesting, but the algorithm cannot be just a 4-round Feistel network. There's something else we are missing.
Tuesday, January 02, 2007
CPS2 is not a 4-round Feistel network (maybe)
Edit Jan 3: Andy has pointed out a flaw in this article. The order of the bits in the L and R groups is important, so we cannot draw any conclusion yet.
Andreas Naive has been doing some very interesting observations lately.
I thought it would make sense to check if we were lucky and the algorithm was indeed structured like a 4-round Feistel network as Andy supposed.
The basic idea of a Feistel network if that you have a round function f() which operates on some bits of the data (8 in our case), and modifies them depending on a key. The function f is the same on every round, while the key changes.
We don't need to care about a key at this point, since we don't know anything about the algorithm. It's easier (and more general) to simply assume that at every round a different function fn is used, where fn describes a permutation of the values 0 to 255.
We have decided that there is strong evidence indicating that the 16 bits of the data should be split in two groups of 8 bits like this:
L = { 0, 1, 2, 4, 6, 7, 13, 14 }
R = { 3, 5, 8, 9, 10, 11, 12, 15 }
So a 4-round Feistel network would work like this:
Given the ciphertext E = (L0, R0),
L1 = R0
R1 = L0 XOR f1(R0)
L2 = R1
R2 = L1 XOR f2(R1)
L3 = R2
R3 = L2 XOR f3(R2)
L4 = R3
R4 = L3 XOR f4(R3)
and the resulting plaintext is D = (L4, R4)
By the properties of a Feistel network, we can also go backwards, starting from D = (L4, R4)
R3 = L4
L3 = R4 XOR f4(L4)
R2 = L3
L2 = R3 XOR f3(L3)
R1 = L2
L1 = R2 XOR f2(L2)
R0 = L1
L0 = R1 XOR f1(L1)
Now let's start from both sides and meet in the middle. Going from E to D we have
L2 = R1 = L0 XOR f1(R0)
Going from D to E we have
L2 = R3 XOR f3(L3) = L4 XOR f3(R2)
Putting the two together we have
L0 XOR f1(R0) = L4 XOR f3(R2), that is
L0 XOR L4 = f1(R0) XOR f3(R2)
Now remember that we know all (E,D) pairs, so we can take advantage of that.
If we take (E,D) and (E',D') such that L0 XOR L4 = L'0 XOR L'4, then it follows that
f1(R0) XOR f3(R2) = f1(R'0) XOR f3(R'2)
If additionally E and E' are such that R0 = R'0, then we are left with just
f3(R2) = f3(R'2)
and since f3 is a bijective function, this implies that
R2 = R'2, that is
L3 = L'3, that is
R4 XOR f4(L4) = R'4 XOR f4(L'4), that is
f4(L4) XOR f4(L'4) = R4 XOR R'4
Now we can repeat the procedure for all (E,D) pairs, and get a large number of equations on f4.
If the CPS2 encryption was a 4-round Feistel network, all those equations would not be contradictory, and they would allow us to reconstruct the structure of f4.
Unfortunately, they are contradictory. E.g. you get something like this:
f4(0xff) XOR f4(0xfc) = 0x11
f4(0xff) XOR f4(0xfc) = 0x48
Therefore CPS2 is not a 4-round Feistel network.
Andreas Naive has been doing some very interesting observations lately.
I thought it would make sense to check if we were lucky and the algorithm was indeed structured like a 4-round Feistel network as Andy supposed.
The basic idea of a Feistel network if that you have a round function f() which operates on some bits of the data (8 in our case), and modifies them depending on a key. The function f is the same on every round, while the key changes.
We don't need to care about a key at this point, since we don't know anything about the algorithm. It's easier (and more general) to simply assume that at every round a different function fn is used, where fn describes a permutation of the values 0 to 255.
We have decided that there is strong evidence indicating that the 16 bits of the data should be split in two groups of 8 bits like this:
L = { 0, 1, 2, 4, 6, 7, 13, 14 }
R = { 3, 5, 8, 9, 10, 11, 12, 15 }
So a 4-round Feistel network would work like this:
Given the ciphertext E = (L0, R0),
L1 = R0
R1 = L0 XOR f1(R0)
L2 = R1
R2 = L1 XOR f2(R1)
L3 = R2
R3 = L2 XOR f3(R2)
L4 = R3
R4 = L3 XOR f4(R3)
and the resulting plaintext is D = (L4, R4)
By the properties of a Feistel network, we can also go backwards, starting from D = (L4, R4)
R3 = L4
L3 = R4 XOR f4(L4)
R2 = L3
L2 = R3 XOR f3(L3)
R1 = L2
L1 = R2 XOR f2(L2)
R0 = L1
L0 = R1 XOR f1(L1)
Now let's start from both sides and meet in the middle. Going from E to D we have
L2 = R1 = L0 XOR f1(R0)
Going from D to E we have
L2 = R3 XOR f3(L3) = L4 XOR f3(R2)
Putting the two together we have
L0 XOR f1(R0) = L4 XOR f3(R2), that is
L0 XOR L4 = f1(R0) XOR f3(R2)
Now remember that we know all (E,D) pairs, so we can take advantage of that.
If we take (E,D) and (E',D') such that L0 XOR L4 = L'0 XOR L'4, then it follows that
f1(R0) XOR f3(R2) = f1(R'0) XOR f3(R'2)
If additionally E and E' are such that R0 = R'0, then we are left with just
f3(R2) = f3(R'2)
and since f3 is a bijective function, this implies that
R2 = R'2, that is
L3 = L'3, that is
R4 XOR f4(L4) = R'4 XOR f4(L'4), that is
f4(L4) XOR f4(L'4) = R4 XOR R'4
Now we can repeat the procedure for all (E,D) pairs, and get a large number of equations on f4.
If the CPS2 encryption was a 4-round Feistel network, all those equations would not be contradictory, and they would allow us to reconstruct the structure of f4.
Unfortunately, they are contradictory. E.g. you get something like this:
f4(0xff) XOR f4(0xfc) = 0x11
f4(0xff) XOR f4(0xfc) = 0x48
Therefore CPS2 is not a 4-round Feistel network.
Tuesday, December 19, 2006
CPS2 notes, part 5
In part 1 I showed some constant values in the table that shows how many times flipping a bit in the ciphertext flips a bit in the plaintext.
But there's more than that. It seems that there are more properties which are true for all games, regardless of the key.
    are constant.
    are correlated and can be only one of 2 quadruplets.
                are all correlated and values can be taken in one of 4 "groups".
Once chosen the group:
    are correlated and can be only one of 2 pairs.
    are correlated and can be only one of 2 pairs.
    are correlated and can be only one of 4 pairs.
    are fixed by     and    .
So in total there are 2x4x2x2x4 = 128 combinations. Each combination is used by exactly 256 tables.
Note the symmetry of it all. 16 values are affected, related to 2 bits of the ciphertext and 8 bits of the plaintext.
This suggests that the algorithm might work on the data 8 bits at a time, or even only 4 bits at a time. The regular behaviour could be caused by a step, at the beginning or at the end of the algorithm, that doesn't use the key.
Another thing we can do is check which of the 128 combinations corresponds to each memory address, and look for a way to correlate the two. Unfortunately there doesn't seem to be a simple way to do that.
But there's more than that. It seems that there are more properties which are true for all games, regardless of the key.
0 1 2 3 4 5 6 7
0 7FE0 75B0 8028 7AF4 6EB0 8284 734C 7420
1 8208 7FE0 7E48 7FA4 81CC 8050 72F8 7FDC
2 7F38 7F8C 8000 7FD0 87B0 7EF4 7BF8 8068
3 7200 6CA0 7B00 76E0 6800 8044 B280 8180
4 7F18 7FCC 7F84 8130 7BC4 80E4 8154 8014
5 8980 7B80 7780 81D4 6200 7D78 7540 7DE0
6 83C0 7E98 7F3C 831C 6CF0 8080 7BD8 7D20
7 80B0 81B0 7EAC 8190 7DB4 8050 8364 7F68
8 7D80 80E0 7D80 8110 78C0 7FC4 6F40 8DA0
9 5080 7510 C000 643C 6DC0 8414 4800 72C0
10 7BE0 7A30 7F40 7F08 6A00 8110 7720 7B80
11 8040 81A0 7E80 7E2C 5680 7FFC 73C0 8020
12 7A80 8370 7100 818C 7E80 7BE8 6200 8060
13 8018 7D24 8040 7F60 7E2C 80EC 7F9C 7EA0
14 7D18 7F00 7EEC 80DC 799C 7F90 7F34 8010
15 7E80 8710 8540 8128 8200 7F50 7C40 8540
8 9 10 11 12 13 14 15
0 8054 7C58 7BF4 7E88 7C80 7610 7C7C 7C28
1 8008 7FA4 80F0 8020 7FB8 7E24 7EE8 8078
2 7FB8 7F18 7FE4 7F14 7FDC 80C0 7C3C 8130
3 80DC 7F34 7EE0 8124 77F0 7800 5A80 7064
4 800C 7F98 7D3C 7E60 803C 7C74 80E0 80A0
5 8024 7BA8 79C8 8020 7A24 7E00 7F60 7AAC
6 7F80 7E94 7B08 7FE8 7E98 6DA0 7FD4 7E50
7 7FE8 7E20 7D6C 7F88 8004 7BD4 803C 7FCC
8 7F4C 7FE4 7E48 7F10 7F40 7FC0 74C0 82B4
9 812C 8064 6520 78D8 7D5C 5040 5800 8588
10 7D50 7FB8 883C 7E00 7EDC 8A00 78E0 7FDC
11 7EF8 7F64 7860 7E30 804C 6780 82C0 81E8
12 8094 7CCC 7A44 7EF0 7FC0 7C80 8100 7EF4
13 8180 7FA0 7FF4 8084 8000 8088 7F9C 8024
14 8004 8080 809C 7F44 806C 8044 7A5C 7FEC
15 7EC0 814C 7A10 7F2C 7E80 9200 7E20 8064
    are constant.
    are correlated and can be only one of 2 quadruplets.
                are all correlated and values can be taken in one of 4 "groups".
Once chosen the group:
    are correlated and can be only one of 2 pairs.
    are correlated and can be only one of 2 pairs.
    are correlated and can be only one of 4 pairs.
    are fixed by     and    .
So in total there are 2x4x2x2x4 = 128 combinations. Each combination is used by exactly 256 tables.
Note the symmetry of it all. 16 values are affected, related to 2 bits of the ciphertext and 8 bits of the plaintext.
This suggests that the algorithm might work on the data 8 bits at a time, or even only 4 bits at a time. The regular behaviour could be caused by a step, at the beginning or at the end of the algorithm, that doesn't use the key.
Another thing we can do is check which of the 128 combinations corresponds to each memory address, and look for a way to correlate the two. Unfortunately there doesn't seem to be a simple way to do that.
CPS2 notes, part 4
I have to stress that there is NO progress being made in breaking the encryption. The things I am showing in these notes have been known for over a year and haven't lead to any breakthrough. Hopefully, a public discussion of these properties could generate some valuable feedback.
There also isn't any kind of competition against the people that are attacking the CPS2 encryption in hardware. On the contrary, I think that the hardware path will be the only way to gather more information about the algorithm.
In these notes I have shown several properties that are always true, regardless of the key. This means that they are properties of the algorithm itself, and therefore are hardcoded in hardware. For example, there almost surely are fixed substitution boxes which could be extracted from the custom CPU.
If an algorithm is reconstructed by studying the CPU, we can also test it against the known properties, regardless of the key. If it doesn't match, then the algorithm isn't right. Once an algorithm fitting the properties is found, we can start looking for the key.
There also isn't any kind of competition against the people that are attacking the CPS2 encryption in hardware. On the contrary, I think that the hardware path will be the only way to gather more information about the algorithm.
In these notes I have shown several properties that are always true, regardless of the key. This means that they are properties of the algorithm itself, and therefore are hardcoded in hardware. For example, there almost surely are fixed substitution boxes which could be extracted from the custom CPU.
If an algorithm is reconstructed by studying the CPU, we can also test it against the known properties, regardless of the key. If it doesn't match, then the algorithm isn't right. Once an algorithm fitting the properties is found, we can start looking for the key.
Monday, December 18, 2006
CPS2 notes, part 3
In part 1 we were flipping bits in the ciphertext, and seeing what happened to bits in the plaintext.
We can do the opposite, of course, and there's something unexpected in the results.
I'll show the total number of times the bits change (in hex) instead of percentages, to make the point more visible.
The values highlighted in orange are the only two that are constant in every table (there were four in the inverse table).
But the values highlighted in red are the most interesting. They are not constant--they can vary among a few possible values. But the sum of the two values in each column is constant, and it's always 0x10000.
Why? I have no idea.
We can do the opposite, of course, and there's something unexpected in the results.
I'll show the total number of times the bits change (in hex) instead of percentages, to make the point more visible.
0 1 2 3 4 5 6 7
0 80BC 7844 7E24 7FD4 7EBC 8090 8138 8044
1 7FB0 8138 7A90 7EB0 7D54 7F04 7FE4 8074
2 7F20 7F30 81A4 8018 80C4 7FB4 7F08 7EF8
3 7F30 8180 7D10 7EA0 6F40 7E30 85E0 79E0
4 7EA8 7B1C 8240 7FD4 7DE4 7F24 7F44 80C4
5 A2C0 6D00 6CC0 69E0 6700 7F28 5E00 4E00
6 7F5C 7ECC 7FB8 7FF8 7C38 7FF0 7EF0 7CAC
7 7FD0 7D80 8168 8058 8104 7FA0 7FAC 80E8
8 71E0 B500 8E80 8020 7900 8124 7980 8240
9 7A20 6E40 7AE0 7FA8 8080 7F84 8240 88E0
10 7930 6900 7A50 81BC 7220 7C48 7A20 6FC0
11 7950 8C00 7600 8054 6F20 806C 7CE0 89C0
12 6F40 4B00 85C0 8010 7600 809C 7E00 7E80
13 7F30 7B20 7FB8 8028 803C 80B4 7E80 8140
14 7A90 8034 7D4C 8124 80D8 7E8C 7FC8 7FC0
15 73F0 79C0 7990 80D0 9440 7D94 7AC0 6EA0
8 9 10 11 12 13 14 15
0 8048 7E84 7DB8 801C 80B8 80A4 62BC 7FB0
1 803C 7FE8 7E20 81E8 80F0 7D68 8144 7FBC
2 807C 80C4 7F80 7FFC 7F90 7EE0 82B0 80B4
3 7EB0 80E0 7E68 7F70 7E78 8010 7580 7BBC
4 7FF0 7F68 7FB8 7FFC 7FAC 8074 7DD4 813C
5 7F08 6FA0 7254 6BB8 6C10 6380 6300 7AE8
6 7FF4 7F9C 8018 7FCC 8138 8118 6E14 80BC
7 8088 80DC 7FC0 7DB8 7F8C 7EE4 84E0 7F48
8 7EEC 8090 84EC 7E28 8328 8960 2D00 85AC
9 7F94 7EA4 7D6C 8080 8068 8200 5FC0 82F0
10 7AF0 80AC 80C8 7CB4 8054 8640 7100 7F8C
11 81F0 8080 7F2C 8064 7F94 82C0 6E80 7B30
12 809C 7FD0 7F98 7ED0 75C8 83C0 D300 7CE8
13 8134 8160 80A0 7F40 7D6C 809C 80E4 7F58
14 7F68 7F14 7F44 7F28 8010 7EB4 7F10 7F80
15 82E0 7D4C 78D8 804C 8000 78A0 6240 75DC
The values highlighted in orange are the only two that are constant in every table (there were four in the inverse table).
But the values highlighted in red are the most interesting. They are not constant--they can vary among a few possible values. But the sum of the two values in each column is constant, and it's always 0x10000.
Why? I have no idea.
CPS2 notes, part 2
The complementation property was an important discovery--and not just because it reduces the size of the tables in half. Still, we haven't taken full advantage of it yet.
Let's recap the basics of the CPS2 encryption first.
Inputs:
Outputs:
Let's call D(X,A,K) the decryption of value X at address A using key K.
The complementation property says that for every A there is exactly one A1 such that
D(X,A,K) = D'(X',A1,K)
where x' is the complement of x.
This finding is important because it shows that A has an algorithmical effect on the encryption. In Sega's FD1094 CPU, the key for every address is just stored in a huge table. If the CPS2 CPU worked in the same way, the complementation property wouldn't happen.
This isn't too much of a surprise: with the Kabuki CPU, we had already seen that Capcom preferred a complex algorithm with a small key, while Sega preferred a simpler algorithm with a huge key.
Unfortunately we don't yet know how to calculate A1 given A. It varies from game to game so it must be a function of the key.
The complementation property isn't unheard of, even in strong ciphers, so it isn't necessarily a weakness in the algorithm. For example, DES has it. In that case, it reads D(X,K) = D'(X',K').
In general, the complementation property indicates that there are probably XOR operations happening, which cause the complement operation to cancel out. Let's see this with an example: consider a substitution function f, and an algorithm such that
d = e XOR f(e XOR k)
if we take the complements we have
e' XOR f(e' XOR k') = e' XOR f(e XOR k) = (e XOR f(e XOR k))' = d'
of course this is a very simple example. Note that x' doesn't have to be the complement in this case: you can define it as e.g. x' = x XOR 1, and it will still work. So the CPS2 algorithm obviously isn't that simple.
A more realistic example would be a Feistel network (note that DES is an example of a Feistel network).
If you define the Feistel network as
Li = Ri-1
Ri = Li-1 XOR f(Ri-1 XOR Ki-1)
it should be easy to see how the complementation property would ensue.
The idea of the CPS2 encryption being a Feistel network is tempting, however I don't think this is the case, because I would expect the diffusion to be much better than what we have seen in part 1.
Let's recap the basics of the CPS2 encryption first.
Inputs:
- 16-bit value stored in ROM
- 16-bit address (bits 1-17 of the physical address)
- key of unknown size, different for every game
Outputs:
- 16-bit decrypted value
Let's call D(X,A,K) the decryption of value X at address A using key K.
The complementation property says that for every A there is exactly one A1 such that
D(X,A,K) = D'(X',A1,K)
where x' is the complement of x.
This finding is important because it shows that A has an algorithmical effect on the encryption. In Sega's FD1094 CPU, the key for every address is just stored in a huge table. If the CPS2 CPU worked in the same way, the complementation property wouldn't happen.
This isn't too much of a surprise: with the Kabuki CPU, we had already seen that Capcom preferred a complex algorithm with a small key, while Sega preferred a simpler algorithm with a huge key.
Unfortunately we don't yet know how to calculate A1 given A. It varies from game to game so it must be a function of the key.
The complementation property isn't unheard of, even in strong ciphers, so it isn't necessarily a weakness in the algorithm. For example, DES has it. In that case, it reads D(X,K) = D'(X',K').
In general, the complementation property indicates that there are probably XOR operations happening, which cause the complement operation to cancel out. Let's see this with an example: consider a substitution function f, and an algorithm such that
d = e XOR f(e XOR k)
if we take the complements we have
e' XOR f(e' XOR k') = e' XOR f(e XOR k) = (e XOR f(e XOR k))' = d'
of course this is a very simple example. Note that x' doesn't have to be the complement in this case: you can define it as e.g. x' = x XOR 1, and it will still work. So the CPS2 algorithm obviously isn't that simple.
A more realistic example would be a Feistel network (note that DES is an example of a Feistel network).
If you define the Feistel network as
Li = Ri-1
Ri = Li-1 XOR f(Ri-1 XOR Ki-1)
it should be easy to see how the complementation property would ensue.
The idea of the CPS2 encryption being a Feistel network is tempting, however I don't think this is the case, because I would expect the diffusion to be much better than what we have seen in part 1.
Sunday, December 17, 2006
CPS2 notes, part 1
Since the finding of the complementation property almost one year ago, there has been no progress at all on the CPS2 encryption.
I'm going to explain here some of the (remarkably few) things we know about the encryption.
A common misconception is that the decryption tables look like "random data". They may look so to the naked eye, but the most basic statistical checks show that this isn't the case.
Take an encrypted value, change a bit in it, and look at what happens to the output. For a random table, you'd expect every bit in the decrypted value to change with 50% probability. This isn't happening.
Take a look at the following statistics taken on a single table: on rows, you have the encrypted bit that changes; on columns, the frequency with which the decrypted bit changes.
So there is a large number of values around 50%, which look just random, but there are also values very far from that.
This indicates that the encryption algorithm doesn't have good diffusion. This is a weakness, though it hasn't been exploited yet.
Of particular interest are the four values I highlighted in red. While the other values change from game to game and from table to table, those four values are always the same. E.g. flipping bit 9 in the encrypted value causes bit 0 in the decrypted value to flip exactly 0x5080 times out of 0x10000, for every game, at every address.
This property is quite interesting. It is the most obvious "signature" of the algorithm. Does it help? Well, it tells us that if the algorithm contains bit permutations that depend on the key, those permutations cannot affect bits 3 and 9 in the encrypted value, nor bits 0 and 14 of the decrypted data. Apart from that, however, the property doesn't tell us much, because even if we know that the bits have to change that many times, we don't know exactly when to flip them. Discovering that would be a significant advance in the understanding of the algorithm.
I'm going to explain here some of the (remarkably few) things we know about the encryption.
A common misconception is that the decryption tables look like "random data". They may look so to the naked eye, but the most basic statistical checks show that this isn't the case.
Take an encrypted value, change a bit in it, and look at what happens to the output. For a random table, you'd expect every bit in the decrypted value to change with 50% probability. This isn't happening.
Take a look at the following statistics taken on a single table: on rows, you have the encrypted bit that changes; on columns, the frequency with which the decrypted bit changes.
0 1 2 3 4 5 6 7
0 50,26% 44,09% 50,98% 49,68% 42,94% 50,81% 44,99% 43,87%
1 49,52% 49,73% 49,87% 49,90% 49,32% 49,77% 45,37% 50,43%
2 49,62% 50,05% 49,67% 50,25% 51,56% 49,86% 49,07% 50,07%
3 44,53% 45,75% 48,05% 48,93% 40,63% 50,22% 69,73% 44,29%
4 49,83% 50,19% 49,62% 49,98% 48,35% 49,88% 50,38% 50,57%
5 50,24% 46,53% 50,78% 50,21% 28,13% 49,79% 44,63% 47,80%
6 51,92% 49,73% 50,10% 50,17% 38,28% 50,10% 48,35% 47,86%
7 50,29% 49,51% 49,16% 49,86% 48,35% 49,93% 50,85% 50,07%
8 51,95% 52,51% 51,37% 48,71% 49,22% 50,07% 43,55% 46,78%
9 31,45% 48,32% 75,00% 43,55% 46,39% 50,51% 28,13% 46,92%
10 50,20% 50,95% 51,37% 49,78% 28,13% 50,06% 47,17% 51,66%
11 45,17% 45,85% 47,66% 50,38% 25,20% 50,58% 44,43% 53,37%
12 47,85% 47,51% 44,14% 50,04% 53,03% 49,24% 38,28% 49,17%
13 49,68% 49,90% 49,43% 50,10% 50,02% 49,46% 50,05% 49,89%
14 49,35% 50,32% 49,98% 49,80% 48,29% 49,65% 49,48% 50,42%
15 48,97% 51,59% 51,07% 49,57% 67,19% 49,55% 45,70% 50,39%
8 9 10 11 12 13 14 15
0 50,43% 48,46% 49,02% 49,49% 49,21% 43,35% 49,05% 47,69%
1 49,85% 49,69% 50,57% 49,76% 50,01% 49,40% 49,88% 50,15%
2 50,14% 50,05% 49,86% 49,57% 50,25% 50,96% 48,99% 50,18%
3 49,46% 50,18% 48,31% 50,30% 46,96% 40,63% 35,35% 44,34%
4 49,82% 50,43% 49,70% 50,34% 49,79% 47,74% 50,16% 49,57%
5 49,91% 48,74% 49,68% 49,88% 48,79% 28,91% 49,02% 48,36%
6 49,74% 49,21% 50,24% 49,62% 49,40% 39,32% 49,91% 49,62%
7 50,14% 50,03% 49,63% 50,39% 49,65% 47,67% 50,43% 49,37%
8 49,83% 49,96% 48,57% 50,43% 49,15% 40,63% 46,97% 50,50%
9 50,15% 49,08% 44,80% 48,27% 49,65% 50,78% 34,38% 50,81%
10 49,76% 49,92% 50,28% 49,24% 49,21% 67,97% 49,27% 49,87%
11 47,55% 50,00% 50,16% 47,17% 49,61% 25,39% 48,93% 51,68%
12 49,83% 48,97% 49,69% 49,86% 49,30% 52,93% 50,39% 49,90%
13 49,85% 50,37% 50,52% 49,94% 49,60% 51,22% 49,96% 49,92%
14 49,85% 50,18% 49,97% 49,89% 50,09% 49,84% 47,50% 49,64%
15 49,49% 49,37% 49,39% 50,09% 49,57% 38,28% 49,17% 49,57%
So there is a large number of values around 50%, which look just random, but there are also values very far from that.
This indicates that the encryption algorithm doesn't have good diffusion. This is a weakness, though it hasn't been exploited yet.
Of particular interest are the four values I highlighted in red. While the other values change from game to game and from table to table, those four values are always the same. E.g. flipping bit 9 in the encrypted value causes bit 0 in the decrypted value to flip exactly 0x5080 times out of 0x10000, for every game, at every address.
This property is quite interesting. It is the most obvious "signature" of the algorithm. Does it help? Well, it tells us that if the algorithm contains bit permutations that depend on the key, those permutations cannot affect bits 3 and 9 in the encrypted value, nor bits 0 and 14 of the decrypted data. Apart from that, however, the property doesn't tell us much, because even if we know that the bits have to change that many times, we don't know exactly when to flip them. Discovering that would be a significant advance in the understanding of the algorithm.
Friday, December 08, 2006
Katamino
(This article is not MAME related)
Some time ago I was shopping looking for a set of Pentomino pieces and found this game called Katamino®.
It looked like a decent enough set of wooden pieces, so I bought it. Pentominoes are a decades old puzzle, so I didn't expect anything more than that. Instead, when I opened the box, I was blown away by how cleverly the puzzle is presented.
The idea is credited to André Perriolat, who is the owner of the company that produces the game, DJ Games.
Here is how it works: take four pentominoes, and make a 5x4 rectangle with them. After you've accomplished that, add another pentomino, and make a 5x5 square. Then add another, and make a 5x6 rectangle. And so on, until you add the final piece to make a 5x12 rectangle. The box contains a board with a moving slider to place your pieces in.
There is only one rule: when you add the I piece, you cannot place it vertically. Otherwise it would be cheating, since you could take the solution to the previous puzzle and just stick the I to the side.
For the same reason, the I piece is not used for the 5x5 puzzles, since even if you put it horizontally it would still be a 5x4 rectangle with the I stuck to the side.
In the box there's a list of 12 such sequences that you can follow, each one ending with a different piece.
This is absolutely brilliant. You start with easy puzzles wich practically anyone can solve, and then gradually increase the difficulty until you complete the full puzzle--or run out of patience, whichever comes first.
Every time you complete one of the puzzles there's a sense of achivement--and then immediately of frustration, because to add one more piece you have to throw away the perfect shape you just created, and start again from scratch.
I liked this idea so much that I started thinking about it. How many ways are there to build sequences to play the game? Are the ones provided the best possible, or can they be improved? Let's see what the goal is:
Things get interesting from the start. There are only 19 ways to select 4 pieces that can form a 5x4 rectangle; but 6 of them cannot be extended to 5x5 without using the I piece. This leaves us with 13 initial choices, just one more than what we need.
How can we rate our sequences to decide which ones are better than others? The obvious answer is to look at the number of different solutions for each combination of pieces. The less the solutions, the better the puzzle is. If two sequences have the same number of solutions, then the one that contains more puzzles which have a single solution is better.
The 5x11 puzzles are obviously the same for every choice, so we don't have to count them. This leaves us with 12 sets of 7 puzzles (from 5x4 to 5x10) for a total of 84 puzzles, which we want to be as hard as possible.
Turns out that the sequences accompanying my copy of the game aren't very good: there's a total of 3084 solutions, and only 20 puzzles with a single solution. Even worse, one of the puzzles is repeated twice.
It seems that I have and old version of the game (the instructions say (c) 1992-1998). The version currently being produced uses a better list, whith 1556 solutions and 26 single solutions (and no duplicates).
Writing a program to find the best solution is a remarkably difficult task. I'm not even sure if it has been classified. If it is, I'd expect it to be as part of problems related to graph theory.
With a mix of manual pruning and computer search, I've selected this sequence which looks quite good:
The numbers in square brackets are the solutions for each puzzle.
The total is 331 solutions, and 45 puzzles with a single solution.
I think this should be quite close to the minimum, but I don't have a way to prove it.
Can anyone do better?
Some time ago I was shopping looking for a set of Pentomino pieces and found this game called Katamino®.
It looked like a decent enough set of wooden pieces, so I bought it. Pentominoes are a decades old puzzle, so I didn't expect anything more than that. Instead, when I opened the box, I was blown away by how cleverly the puzzle is presented.
The idea is credited to André Perriolat, who is the owner of the company that produces the game, DJ Games.
Here is how it works: take four pentominoes, and make a 5x4 rectangle with them. After you've accomplished that, add another pentomino, and make a 5x5 square. Then add another, and make a 5x6 rectangle. And so on, until you add the final piece to make a 5x12 rectangle. The box contains a board with a moving slider to place your pieces in.
There is only one rule: when you add the I piece, you cannot place it vertically. Otherwise it would be cheating, since you could take the solution to the previous puzzle and just stick the I to the side.
For the same reason, the I piece is not used for the 5x5 puzzles, since even if you put it horizontally it would still be a 5x4 rectangle with the I stuck to the side.
In the box there's a list of 12 such sequences that you can follow, each one ending with a different piece.
This is absolutely brilliant. You start with easy puzzles wich practically anyone can solve, and then gradually increase the difficulty until you complete the full puzzle--or run out of patience, whichever comes first.
Every time you complete one of the puzzles there's a sense of achivement--and then immediately of frustration, because to add one more piece you have to throw away the perfect shape you just created, and start again from scratch.
I liked this idea so much that I started thinking about it. How many ways are there to build sequences to play the game? Are the ones provided the best possible, or can they be improved? Let's see what the goal is:
- build 12 sequences, each one ending with a different piece
- every combination of pieces must be used only once
Things get interesting from the start. There are only 19 ways to select 4 pieces that can form a 5x4 rectangle; but 6 of them cannot be extended to 5x5 without using the I piece. This leaves us with 13 initial choices, just one more than what we need.
How can we rate our sequences to decide which ones are better than others? The obvious answer is to look at the number of different solutions for each combination of pieces. The less the solutions, the better the puzzle is. If two sequences have the same number of solutions, then the one that contains more puzzles which have a single solution is better.
The 5x11 puzzles are obviously the same for every choice, so we don't have to count them. This leaves us with 12 sets of 7 puzzles (from 5x4 to 5x10) for a total of 84 puzzles, which we want to be as hard as possible.
Turns out that the sequences accompanying my copy of the game aren't very good: there's a total of 3084 solutions, and only 20 puzzles with a single solution. Even worse, one of the puzzles is repeated twice.
It seems that I have and old version of the game (the instructions say (c) 1992-1998). The version currently being produced uses a better list, whith 1556 solutions and 26 single solutions (and no duplicates).
Writing a program to find the best solution is a remarkably difficult task. I'm not even sure if it has been classified. If it is, I'd expect it to be as part of problems related to graph theory.
With a mix of manual pruning and computer search, I've selected this sequence which looks quite good:
L P U F [1] W [1] I [4] Z [1] T [5] N [1] V [83] Y [1277] X [786]
L Y U F [3] Z [1] I [2] N [2] T [4] X [2] V [16] P [ 508] W "
Y N V T [1] F [1] I [3] W [1] U [5] X [1] L [ 8] P [ 371] Z "
L Y P W [5] N [1] V [1] I [5] X [1] Z [5] F [25] U [ 216] T "
Y P U F [1] T [1] I [2] Z [1] N [2] X [1] W [ 2] L [ 183] V "
L Y P T [1] W [1] F [1] N [5] X [3] Z [1] I [ 8] V [ 133] U "
L V P Z [2] Y [1] T [2] I [5] X [1] W [1] F [15] U [ 125] N "
L Y P Z [1] W [2] T [1] V [1] X [1] U [3] N [21] I [ 116] F "
L N P U [2] Z [2] X [1] V [1] F [1] T [2] W [14] Y [ 112] I "
L N V Z [2] U [1] T [1] F [2] I [6] W [3] X [ 1] P [ 101] Y "
Y N P U [1] V [1] Z [1] X [1] F [2] T [1] W [ 1] I [ 59] L "
L Y V U [2] Z [1] F [1] W [1] X [1] N [1] T [ 1] I [ 14] P "
The numbers in square brackets are the solutions for each puzzle.
The total is 331 solutions, and 45 puzzles with a single solution.
I think this should be quite close to the minimum, but I don't have a way to prove it.
Can anyone do better?
Saturday, August 05, 2006
Completed, at Last
As you'd probably noticed, the pics in the previous post are of the Bubble Bobble custom MCU.
Despite being one of the most popular games of all times, and having been in MAME for many years, the emulation of this game has never been perfect due to the lack of the original ROM for the MCU.
For some time, we had been using a 68705 program found in a bootleg board, believing it had been extracted from the original. However, monster behaviour was wrong and there were other problems, like the wrong behaviour of the clock item.
After some study of the program and of the game schematics, it became clear that the original MCU is not a 68705 at all (the pinout doesn't match) but looked more like a 68701.
The 68705 program had been written from scratch by the bootleggers using black box reverse engineering techniques, by running the original MCU and logging all its reads and writes from memory. Indeed, the 68705 program does a lot of reads from memory without doing anything with them--simply because the original MCU would read that memory and do some unknown action with it.
Eventually, the useless 68705 program was replaced by simulation code inside the emulator, which greatly improved the emulation accuracy. Monster behaviour was improved, the clock item behaviour fixed. However, there were still some unknown things, like how the randomisation of the EXTEND bubbles really worked.
At last, thanks to excellent work by Trinity, the original MCU ROM has been extracted. This required removing the cover from the chip, taking photographs of it under a microscope, and manually decoding the contents of the ROM bit by bit. The photo shown in the previous post confirms that it's in the 6801 class, not a 68701 however as it was conjectured, but a 6801U4.
With this ROM, we finally have the final piece of the puzzle for a 100% guaranteed perfect emulation.
Checking the original MCU program was very interesting. It was designed to provide many protection features that were eventually not used by the game, like:
So, how close was the simulation to the real thing? Very close; "too good", actually. Let's see why.
The clock item behaviour was spot on, but off by one frame (the simulation made the counter expire one frame too late).
The EXTEND randomisation simply doesn't exist in the original MCU. While the simulation code used a RNG to provide truly random letters, the original MCU simply increases the counter every frame. This seriously affects the game, making the EXTEND letters predictable.
Since a new bubble enters the screen exactly 128 frames after the previous one, and the remainder of 128 / 6 is 2, this means that if you get consecutive letters each one will be 2 places after the previous one. So if you get 3 letters you can get either E, T, N or X, E, D. After that they will repeat. There are exceptions, though: if you create a new bubble in exactly the same frame when a new bubble should enter the screen, the bubble is delayed by one frame. So by timing the fire button exactly right you can change the bubble order. In theory you could get all 6 letters in a single level--let me know if you manage to do that! :)
Also, new bubbles will not appear if there are already 16 bubbles on the screen, so that will change the order as well.
The last, and most important, thing that the MCU does is compare the player coordinates with the monsters. The results are returned as flags indicating whether each coordinate is >, =, or <, and the absolute difference. This was done correctly in the simulation code, however there appears to be a bug in the original MCU. The code there attempts to check if the player collided with a moster and set a flag and indicate which monster in that case, but it just doesn't work. It would set the flag even if the player's Y coordinate matches one monster and the X coordinate matches a different monster!
This isn't much of a problem since the main program just ignores the flag--the collision detection is done correctly by the second Z80.
However, the MCU also completely stops processing the monster coordinates as soon as it finds a monster whose X coordinate is within 8 pixels of the player. So e.g. if you have a monster right above you three platforms up, and that monster is the first in the list, the other monsters could stop following you. This is a very subtle effect that's completely unnoticeable from what I can tell, though in theory it exists.
Despite being one of the most popular games of all times, and having been in MAME for many years, the emulation of this game has never been perfect due to the lack of the original ROM for the MCU.
For some time, we had been using a 68705 program found in a bootleg board, believing it had been extracted from the original. However, monster behaviour was wrong and there were other problems, like the wrong behaviour of the clock item.
After some study of the program and of the game schematics, it became clear that the original MCU is not a 68705 at all (the pinout doesn't match) but looked more like a 68701.
The 68705 program had been written from scratch by the bootleggers using black box reverse engineering techniques, by running the original MCU and logging all its reads and writes from memory. Indeed, the 68705 program does a lot of reads from memory without doing anything with them--simply because the original MCU would read that memory and do some unknown action with it.
Eventually, the useless 68705 program was replaced by simulation code inside the emulator, which greatly improved the emulation accuracy. Monster behaviour was improved, the clock item behaviour fixed. However, there were still some unknown things, like how the randomisation of the EXTEND bubbles really worked.
At last, thanks to excellent work by Trinity, the original MCU ROM has been extracted. This required removing the cover from the chip, taking photographs of it under a microscope, and manually decoding the contents of the ROM bit by bit. The photo shown in the previous post confirms that it's in the 6801 class, not a 68701 however as it was conjectured, but a 6801U4.
With this ROM, we finally have the final piece of the puzzle for a 100% guaranteed perfect emulation.
Checking the original MCU program was very interesting. It was designed to provide many protection features that were eventually not used by the game, like:
- process coin inputs and update the credit counter
- handle the number of remaining lives for both players
- handle the current round number
- handle variable speed incrementing for four variables
- return values from a 1280 bytes table of seemingly random data
So, how close was the simulation to the real thing? Very close; "too good", actually. Let's see why.
The clock item behaviour was spot on, but off by one frame (the simulation made the counter expire one frame too late).
The EXTEND randomisation simply doesn't exist in the original MCU. While the simulation code used a RNG to provide truly random letters, the original MCU simply increases the counter every frame. This seriously affects the game, making the EXTEND letters predictable.
Since a new bubble enters the screen exactly 128 frames after the previous one, and the remainder of 128 / 6 is 2, this means that if you get consecutive letters each one will be 2 places after the previous one. So if you get 3 letters you can get either E, T, N or X, E, D. After that they will repeat. There are exceptions, though: if you create a new bubble in exactly the same frame when a new bubble should enter the screen, the bubble is delayed by one frame. So by timing the fire button exactly right you can change the bubble order. In theory you could get all 6 letters in a single level--let me know if you manage to do that! :)
Also, new bubbles will not appear if there are already 16 bubbles on the screen, so that will change the order as well.
The last, and most important, thing that the MCU does is compare the player coordinates with the monsters. The results are returned as flags indicating whether each coordinate is >, =, or <, and the absolute difference. This was done correctly in the simulation code, however there appears to be a bug in the original MCU. The code there attempts to check if the player collided with a moster and set a flag and indicate which monster in that case, but it just doesn't work. It would set the flag even if the player's Y coordinate matches one monster and the X coordinate matches a different monster!
This isn't much of a problem since the main program just ignores the flag--the collision detection is done correctly by the second Z80.
However, the MCU also completely stops processing the monster coordinates as soon as it finds a monster whose X coordinate is within 8 pixels of the player. So e.g. if you have a monster right above you three platforms up, and that monster is the first in the list, the other monsters could stop following you. This is a very subtle effect that's completely unnoticeable from what I can tell, though in theory it exists.
Thursday, August 03, 2006
Tuesday, June 20, 2006
Political Digression
Forgive me for abusing of this space to talk about an important matter of Italian politics.
Il 25 e 26 giugno siamo chiamati alle urne per uno dei più importanti voti della storia della Repubblica. Dovremo decidere se mantenere la nostra Costituzione del 1947, o se adottarne una nuova.
Questo è l'articolo 70 nella nostra Costituzione:
"La funzione legislativa è esercitata collettivamente dalle due Camere."
Questo è l'articolo con cui verrebbe sostituito se la nuova Costituzione sarà approvata dal referendum:
"La Camera dei deputati esamina i disegni di legge concernenti le materie di cui all'articolo 117, secondo comma, fatto salvo quanto previsto dal terzo comma del presente articolo. Dopo l'approvazione da parte della Camera, a tali disegni di legge il Senato federale della Repubblica, entro trenta giorni, può proporre modifiche, sulle quali la Camera decide in via definitiva. I termini sono ridotti alla metà per i disegni di legge di conversione dei decreti-legge.
Il Senato federale della Repubblica esamina i disegni di legge concernenti la determinazione dei princìpi fondamentali nelle materie di cui all'articolo 117, terzo comma, fatto salvo quanto previsto dal terzo comma del presente articolo. Dopo l'approvazione da parte del Senato, a tali disegni di legge la Camera dei deputati, entro trenta giorni, può proporre modifiche, sulle quali il Senato decide in via definitiva. I termini sono ridotti alla metà per i disegni di legge di conversione dei decreti-legge.
La funzione legislativa dello Stato è esercitata collettivamente dalle due Camere per l'esame dei disegni di legge concernenti le materie di cui all'articolo 117, secondo comma, lettere m) e p), e 119, l'esercizio delle funzioni di cui all'articolo 120, secondo comma, il sistema di elezione della Camera dei deputati e per il Senato federale della Repubblica, nonché nei casi in cui la Costituzione rinvia espressamente alla legge dello Stato o alla legge della Repubblica, di cui agli articoli 117, commi quinto e nono, 118, commi secondo e quinto, 122, primo comma, 125, 132, secondo comma, e 133, secondo comma. Se un disegno di legge non è approvato dalle due Camere nel medesimo testo i Presidenti delle due Camere possono convocare, d'intesa tra di loro, una commissione, composta da trenta deputati e da trenta senatori, secondo il criterio di proporzionalità rispetto alla composizione delle due Camere, incaricata di proporre un testo unificato da sottoporre al voto finale delle due Assemblee. I Presidenti delle Camere stabiliscono i termini per l'elaborazione del testo e per le votazioni delle due Assemblee.
Qualora il Governo ritenga che proprie modifiche a un disegno di legge, sottoposto all'esame del Senato federale della Repubblica ai sensi del secondo comma, siano essenziali per l'attuazione del suo programma approvato dalla Camera dei deputati, ovvero per la tutela delle finalità di cui all'articolo 120, secondo comma, il Presidente della Repubblica, verificati i presupposti costituzionali, può autorizzare il Primo ministro ad esporne le motivazioni al Senato, che decide entro trenta giorni. Se tali modifiche non sono accolte dal Senato, il disegno di legge è trasmesso alla Camera che decide in via definitiva a maggioranza assoluta dei suoi componenti sulle modifiche proposte.
L'autorizzazione da parte del Presidente della Repubblica di cui al quarto comma può avere ad oggetto esclusivamente le modifiche proposte dal Governo ed approvate dalla Camera dei deputati ai sensi del secondo periodo del secondo comma.
I Presidenti del Senato federale della Repubblica e della Camera dei deputati, d'intesa tra di loro, decidono le eventuali questioni di competenza tra le due Camere, sollevate secondo le norme dei rispettivi regolamenti, in ordine all'esercizio della funzione legislativa. I Presidenti possono deferire la decisione ad un comitato paritetico, composto da quattro deputati e da quattro senatori, designati dai rispettivi Presidenti. La decisione dei Presidenti o del comitato non è sindacabile in alcuna sede. I Presidenti delle Camere, d'intesa tra di loro, su proposta del comitato, stabiliscono sulla base di norme previste dai rispettivi regolamenti i criteri generali secondo i quali un disegno di legge non può contenere disposizioni relative a materie per cui si dovrebbero applicare procedimenti diversi"
La nuova Costituzione modifica più di 50 articoli della Costituzione originale. Credo che questo articolo da solo sarebbe sufficiente per decidere quale delle due è migliore. La nostra Costituzione è elegante, essenziale, efficace. La si vuole sostituire con una cosa verbosa e incomprensibile, scritta come una leggina qualsiasi, in cui si fa riferimento all'articolo X comma Y lettera Z. E' una cosa vergognosa. Non si può. Non va bene. E' la nostra Costituzione, non è una leggina qualsiasi. E' il documento fondante della nostra Repubblica, un documento che un ragazzo della scuola media dovrebbe poter leggere e capire senza difficoltà.
Il 25 e 26 giugno siamo chiamati alle urne per uno dei più importanti voti della storia della Repubblica. Dovremo decidere se mantenere la nostra Costituzione del 1947, o se adottarne una nuova.
Questo è l'articolo 70 nella nostra Costituzione:
"La funzione legislativa è esercitata collettivamente dalle due Camere."
Questo è l'articolo con cui verrebbe sostituito se la nuova Costituzione sarà approvata dal referendum:
"La Camera dei deputati esamina i disegni di legge concernenti le materie di cui all'articolo 117, secondo comma, fatto salvo quanto previsto dal terzo comma del presente articolo. Dopo l'approvazione da parte della Camera, a tali disegni di legge il Senato federale della Repubblica, entro trenta giorni, può proporre modifiche, sulle quali la Camera decide in via definitiva. I termini sono ridotti alla metà per i disegni di legge di conversione dei decreti-legge.
Il Senato federale della Repubblica esamina i disegni di legge concernenti la determinazione dei princìpi fondamentali nelle materie di cui all'articolo 117, terzo comma, fatto salvo quanto previsto dal terzo comma del presente articolo. Dopo l'approvazione da parte del Senato, a tali disegni di legge la Camera dei deputati, entro trenta giorni, può proporre modifiche, sulle quali il Senato decide in via definitiva. I termini sono ridotti alla metà per i disegni di legge di conversione dei decreti-legge.
La funzione legislativa dello Stato è esercitata collettivamente dalle due Camere per l'esame dei disegni di legge concernenti le materie di cui all'articolo 117, secondo comma, lettere m) e p), e 119, l'esercizio delle funzioni di cui all'articolo 120, secondo comma, il sistema di elezione della Camera dei deputati e per il Senato federale della Repubblica, nonché nei casi in cui la Costituzione rinvia espressamente alla legge dello Stato o alla legge della Repubblica, di cui agli articoli 117, commi quinto e nono, 118, commi secondo e quinto, 122, primo comma, 125, 132, secondo comma, e 133, secondo comma. Se un disegno di legge non è approvato dalle due Camere nel medesimo testo i Presidenti delle due Camere possono convocare, d'intesa tra di loro, una commissione, composta da trenta deputati e da trenta senatori, secondo il criterio di proporzionalità rispetto alla composizione delle due Camere, incaricata di proporre un testo unificato da sottoporre al voto finale delle due Assemblee. I Presidenti delle Camere stabiliscono i termini per l'elaborazione del testo e per le votazioni delle due Assemblee.
Qualora il Governo ritenga che proprie modifiche a un disegno di legge, sottoposto all'esame del Senato federale della Repubblica ai sensi del secondo comma, siano essenziali per l'attuazione del suo programma approvato dalla Camera dei deputati, ovvero per la tutela delle finalità di cui all'articolo 120, secondo comma, il Presidente della Repubblica, verificati i presupposti costituzionali, può autorizzare il Primo ministro ad esporne le motivazioni al Senato, che decide entro trenta giorni. Se tali modifiche non sono accolte dal Senato, il disegno di legge è trasmesso alla Camera che decide in via definitiva a maggioranza assoluta dei suoi componenti sulle modifiche proposte.
L'autorizzazione da parte del Presidente della Repubblica di cui al quarto comma può avere ad oggetto esclusivamente le modifiche proposte dal Governo ed approvate dalla Camera dei deputati ai sensi del secondo periodo del secondo comma.
I Presidenti del Senato federale della Repubblica e della Camera dei deputati, d'intesa tra di loro, decidono le eventuali questioni di competenza tra le due Camere, sollevate secondo le norme dei rispettivi regolamenti, in ordine all'esercizio della funzione legislativa. I Presidenti possono deferire la decisione ad un comitato paritetico, composto da quattro deputati e da quattro senatori, designati dai rispettivi Presidenti. La decisione dei Presidenti o del comitato non è sindacabile in alcuna sede. I Presidenti delle Camere, d'intesa tra di loro, su proposta del comitato, stabiliscono sulla base di norme previste dai rispettivi regolamenti i criteri generali secondo i quali un disegno di legge non può contenere disposizioni relative a materie per cui si dovrebbero applicare procedimenti diversi"
La nuova Costituzione modifica più di 50 articoli della Costituzione originale. Credo che questo articolo da solo sarebbe sufficiente per decidere quale delle due è migliore. La nostra Costituzione è elegante, essenziale, efficace. La si vuole sostituire con una cosa verbosa e incomprensibile, scritta come una leggina qualsiasi, in cui si fa riferimento all'articolo X comma Y lettera Z. E' una cosa vergognosa. Non si può. Non va bene. E' la nostra Costituzione, non è una leggina qualsiasi. E' il documento fondante della nostra Repubblica, un documento che un ragazzo della scuola media dovrebbe poter leggere e capire senza difficoltà.
Subscribe to:
Posts (Atom)