Home
Writeups Misc About
Cofactor Cofantasy

Cofactor Cofantasy

We can factor N using the given phi, or just simply look up the number on FactorDB. If the number returned has the form of c=gk with some even number k, we have the observation that for every factor of N, c is a quadratic residue under that base, whereas the randomly generated number almost never generate a number that is a quadratic residue of all factors.

However, there is some chance that c=gq, where q is some odd number. Hence, with probability 12, the number returned (if the flag bit is 1) has a 12 chance of returning a quadratic residue to all bases. With 10 tries to generate the c value, the probability that one quadratic residue is returned is 10231024. Hence, we most likely will have some quadratic residue returned after 10 tries, if the flag bit is indeed 1.

Python Implementation:

There is also a solution that does not involve mathematics. When the i-th bit is 1, the server will perform the exponential operation with some random exponent. Otherwise, the server will send a random value. It is clear that picking random and doing exponential operation is slower than just picking out randomly.

Hence, we can do a timing side channel attack with this observation. The implementation is kudos to p4b:

Again, there are some other solution involving finding the order of element g in the multiplicative group formed under the integer modulo N. N is a product of 16 safe primes. Because of this, 216 divides ϕ(n). Hence, ϕ(n)=216s for some s. By Lagrange's theorem, the order of any element in a group divides the order of the group. Hence, |g| divides 216.

Computing gs, we observe that gs1modN, but g2s=1modN. Hence, if the flag bit is 1, and the server returns some even number e, then we have:

(ge)s=ges=1modN

If the ith bit is 0, the probability that the random number returned has the order of s is practically negligible. Hence it is unlikely that xs=1modN.