๐–„๐•บ๐ŸŒŽ๐•ฟ๐•ฝ๐•บยฅ

๐–„๐•บ๐ŸŒŽ๐•ฟ๐•ฝ๐•บยฅ

๐•ด ๐–‰๐–” ๐–’๐–†๐–Œ๐–Ž๐–ˆ
github

Linear Cryptanalysis in Computer Security and Forensics

XOR#

XOR is short for "exclusive or," a fundamental bitwise operation. Its rule is to compare two bits; if the two bits are the same, the result is 0; if the two bits are different, the result is 1.
Untitled

Screenshot_2024-03-07_at_14.12.44

Since โ‰  0.5, there is information. Thus, even with just one subset of values, the deviation can be exploited in a roughly similar manner. Even 0.5000001.

source of info = If the degree of consistency between the input expression and the output expression does not exceed 0.5, then one expression is the source of information for the other expression.

Screenshot_2024-03-07_at_14.12.30

Linear Cryptanalysis#

  • Plaintext and ciphertext are visible
  • It is a known plaintext attack
  • A sufficient number of plaintext and ciphertext pairs are needed to find the linear relationship between input bits and output bits.
  • Requires sufficiently good linear approximations.
  • Refers to a type of attack aimed at block ciphers.
  • Approximates block ciphers using linear expressions (some variables represented by mod-2 bit operations).
  • The truth (or falsehood) of these expressions carries a certain deviation, which is used to discover key bits.

Substitution Boxes (S-box)#

  1. Determine the bias of the S-box and construct the LAT.
  2. Use (biased) linear expressions.
  3. Link expressions from the initial plaintext to the intermediate ciphertext.
  4. Through Matsui's bias theorem.
  5. For the final subkey, determine the frequency of the expression's validity.
  6. If the bias matches, you have discovered the key!
  7. Repeat the above steps for each subkey.

Screenshot_2024-03-07_at_14.17.25

Implemented in the form of a lookup table, but cannot scale with increasing input size, so outputs must be computed differently, i.e., calculated as expressions of input bits. e.g.

Screenshot_2024-03-07_at_14.18.20

Approximating Sboxes#

Screenshot_2024-03-07_at_14.19.06

one key XORing and one Substitution Box

Assuming X3 โŠ• X4 = Y1 โŠ• Y4,

then K3 โŠ• K4 = P3 โŠ• P4 โŠ• Y1 โŠ• Y4

Screenshot_2024-03-07_at_14.25.06

Linear Approximation Table (LAT) for S-boxes#

Screenshot_2024-03-07_at_14.46.11

Analysis:

  • x represents input, y represents output
  • This is the bias table:
    • 0 means unbiased, so probability is 0.5.
      • means the actual occurrence is more than expected, - means the actual occurrence is less than expected
  • Non-zero indicates information; the larger the absolute value, the more information it contains

Screenshot_2024-03-18_at_12.21.07

A[1,2] means the input mask is '01', which means we only care about the second bit of the input. The output mask is '10', which means we only care about the first bit of the output.

Calculate the XOR value of the output bit corresponding to each input#

We need to perform the following sub-steps for each input:

  1. Look at the output value of that input in the S-box.
  2. Apply the input mask to the input value, keeping only the bits where the mask corresponds to 1.
  3. Apply the output mask to the output value, similarly keeping only the bits where the mask corresponds to 1.
  4. Calculate the XOR value of these two bits.

01 00 11 10 โ†’ 1010

11 01 10 00 โ†’ 1010

XOR โ†’ 0000 = 4/4

so answer is +2

also for B answer is -2

Matsuiโ€™s Piling Up Lemma#

Used to calculate the bias of multiple variables

  • e.g.: bias is not 0

Screenshot_2024-03-07_at_14.56.53

  • e.g.: As long as one is 0, the final result is unbiased. Example Z2 is unbiased, effectively randomizing Z1 โŠ• Z2

Screenshot_2024-03-07_at_15.09.09

  • Conclusion: The formula is as follows

Screenshot_2024-03-07_at_15.11.40

Linking S-box Approximations#

Steps:

  • How to calculate probability? Based on input rather than output, as illustrated to derive the approximation of G2
  • With the approximation, subtract the expected probability (usually 1/2) to get the bias
  • Common XOR, eliminate intermediate nodes to move to the right side of the equation, turning it into a probability of =0
  • Substitute into Matsuiโ€™s Lemma formula to find that value

Screenshot_2024-03-07_at_15.13.07

  • Continue calculating the overall, as illustrated
    • In the substitution steps, G2 appears, so XOR becomes 0, moving to the right side of the equation
    • At the same time, the probability of =1 is calculated as 5/8

Screenshot_2024-03-07_at_15.17.22

  • Transformation example

Screenshot_2024-03-07_at_15.24.54

  • Calculation example

Screenshot_2024-03-07_at_15.32.37

  • The transformation of the above XOR formula, so the result is the same

Screenshot_2024-03-07_at_15.31.42

  • Summary of the above transformations

Screenshot_2024-03-07_at_15.34.17

Discovering Keys#

Visible?#

  • The system only has plaintext P and ciphertext C visible, after all, it is linear cryptanalysis

Screenshot_2024-03-07_at_15.37.14

Final Round Key#

The last round S-box is invertible, so the corresponding U can be calculated.

For any round key guessed by the cryptanalyst, they can generate U.

Screenshot_2024-03-07_at_20.29.49

  1. Assume a last round key, obtaining the intermediate ciphertext, which represents the intermediate steps U1, U2, U3, U4, etc., in the encryption process.
  2. If the guessed key is correct, then the intermediate ciphertext is correct.
  3. Next, with P and U and C, calculate the approximate expression (approx. expression), which has a certain bias (bias), such as 1/8 or 3/8.
  4. If this approximate expression matches the observed bias, then the assumed key can be considered correct.
  5. If the guessed key is incorrect, then the intermediate ciphertext is also incorrect.
  6. If one or more key bits are guessed incorrectly, then this approximate expression will only hold true half the time, as the result is randomized.

Therefore, by comparing the approximate expression under the assumed key with the bias of 1/2, one can distinguish between correct and incorrect key guesses. Finally, try all possible last round keys to see which (P,U) approximation is least consistent with the bias of 1/2; this key is likely the actual key.

Applying#

Substitution Permutation Network (Heyโ€™s Cipher)#

  • In this system, Heys' Cipher enhances the security of encryption through repeated substitution and permutation operations and key mixing.
  • 3 rounds S-box: XORing, all S-boxes are the same.
  • P-box: Permutation box, permuting, it rearranges bits according to specific rules to diffuse any changes in input during each round.
  • 16-bit subkeys: Assumed to be independently generated, usually obtained through key scheduling, similar to the approach in DES (Data Encryption Standard).
  • Example: Each probability is based on input.
  • Key mixing uses bitwise XOR operations.

Screenshot_2024-03-07_at_21.44.31

  • E2E refers to end-to-end approximation, the entire encryption process from plaintext to ciphertext.

    Screenshot_2024-03-07_at_21.51.20

    Screenshot_2024-03-07_at_21.51.11

    If you have enough plaintext-ciphertext pairs, theoretically, you can use this linear approximation to decrypt or more accurately guess the key.

  • How to calculate? Similarly, Matsuiโ€™s Lemma

    Screenshot_2024-03-07_at_21.53.55

    Screenshot_2024-03-07_at_21.55.10

    Key sub-blocks and reverse engineering:

    • Goal: Generate Intermediate Ciphertexts through K5 and C (the second and fourth subsets)
    • Unrelated to the 1st and 3rd subsets, so the interest is in the 2nd and 4th.

    From C to U, the correct K yields the correct U, and vice versa.

    Screenshot_2024-03-08_at_12.39.05

    Screenshot_2024-03-08_at_12.57.15

    Try All Subkeys#

    • The table only shows a portion of the subkeys, assuming there are 64 subkeys.
    • Assuming there are 10,000 plaintext-ciphertext pairs, using 64 subkeys.
    • For each p-c pair, c and subkey generate p, calculating the bias.
    • The subkey with the largest bias is usually correct, but not always.
    • It can be seen that when the subkeys are 24, the bias is the largest, a candidate.

    Screenshot_2024-03-08_at_13.01.51

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.