Home
Writeups Misc About
The Matrix Reloaded

The Matrix Reloaded

Useful Sage documentation link about the syntax for matrices.

We are given a somewhat similar to a Diffie-Hellman key-exchange, a secret s is picked out, then H=Gs is calculated. They also generate a random vector v in the matrix space. The product of H×v=w is calculated. Given the two vectors v,w, we have to derive the value of the secret s to obtain the decryption key.

The solution was just under my nose. Seems like Googling for some plural version discrete logarithm matrices leads us to this excellent resource to solve this problem.

I initially Google something like discrete logarithm matrix ctf, which leads to this CTF Writeup, discussing how to solve Gx=H, with given matrices A and B. The challenge name is Neo-Classical Key Exchange, detailing how we can use Jordan Canonical Form of the generator matrix G to solve for x.

Unfortunately, the above does not work as generally, there are infinitely many solutions for H given v,w (as one can only construct n equations, while we need n2 entries to reconstruct matrix H). Hence, this approach is discarded.

The first link on Crypto StackExchange should shed light on how to solve the problem, so I don't want to go into the math again. The Wikipedia link shows the concepts of "blocks" in Jordan Canonical Form. With this established, let's dive into the analysis.

We can first analyze the Jordan Normal form of the given generator matrix G. The mathematical form is PJP1. The formula for H, or Gs will thus be PJsP1.

Hence, the given equation becomes:

PJsP1v=w

I did in this way:

There are also neater ways to display the matrix also, kudos to hellman:

The output will look something like this:

where X represent some non-zero element. Hence, we can observe that the matrix "almost" diagonalizes. If it DOES diagonalize, then solving DLP is hard. Luckily, we can still consider the non-diagonalized block in the bottom right corner.

[θ10θ]

Call this mini-matrix J, then Jk is given by:

[θk10θk]

Following the CryptoStackExchange link, we can manipulate the given equation a bit:

P1PJsP1v=P1w
JsP1v=P1w

Thus, denote a=P1v=(x1,x2,...,xn1,xn) and b=P1w=(y1,y2,...,yn1,yn), we can recover s by doing:

s=θ(yn1xn1ynxn)/yn

We can easily verify the correctness of this formula, and again, the first Crypto StackExchange link should show why. Since the 2×2 matrix we are trying to do this is in the rightmost corner, hence only the terms of xn1,xn and yn1,yn are involved (this link should clarify if you do not understand what I am talking about).

With these, we can obtain the secret s, and thus the flag.

Sage Implementation: