![]() |
A52HackTool 1.3.0
Turnkey & easy to use tool for cracking the GSM A5/2 cipher
|
Implementation of first attack phase: matrices dictionary generation. More...
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <time.h>
#include "utils.h"
#include "matrices_generation.h"
#include "code.h"
#include "keygen.h"
Data Structures | |
struct | GenerationArgs |
Set of arguments related to a thread in a multithreaded generation context. More... | |
Defines | |
#define | NULLIFY(op) do {memset(op, 0, REGS_TOTAL_VARS*sizeof(byte));} while(0) |
#define | LOADR1(op, tap, x) |
#define | LOADR2(op, tap, x) |
#define | LOADR3(op, tap, x) |
Functions | |
void | matrices_generation_clockR1 (byte R1[R1_BITS][1+R1_SIMPLE_VARS]) |
Clock register R1 contents. | |
void | matrices_generation_clockR2 (byte R2[R2_BITS][1+R2_SIMPLE_VARS]) |
Clock register R2 contents. | |
void | matrices_generation_clockR3 (byte R3[R3_BITS][1+R3_SIMPLE_VARS]) |
Clock register R3 contents. | |
void | matrices_generation_clockR4 (byte R4[]) |
Clock register R4 contents. | |
void | matrices_generation_clockingUnit (byte R1[R1_BITS][1+R1_SIMPLE_VARS], byte R2[R2_BITS][1+R2_SIMPLE_VARS], byte R3[R3_BITS][1+R3_SIMPLE_VARS], byte R4[R4_BITS], int clockAll) |
Performs register clocking according to the rules of the Clocking Unit. | |
void | matrices_generation_doubleProduct (const byte a1[], const byte a2[], byte out[]) |
Performs a double product of two vectors of variables. | |
void | matrices_generation_getOutBit (byte R1[R1_BITS][1+R1_SIMPLE_VARS], byte R2[R2_BITS][1+R2_SIMPLE_VARS], byte R3[R3_BITS][1+R3_SIMPLE_VARS], byte out[REGS_TOTAL_VARS]) |
Returns the current out keystream bit (here a set of xored variables) corresponding to a particular LFSR state. | |
void | matrices_generation_processKeystreamEqns (const byte initialR4[], byte keystream[][REGS_TOTAL_VARS], const int len) |
Generates the desired amount of keystream dependancy equations (skipping first 99cycles) considering one initial R4 state. | |
int | matrices_generation_getRealVariableIndex (unsigned int Reg, unsigned int index) |
Processes the correct location of a variable inside a LFSR from the variable index. | |
byte | matrices_generation_solveEquation (byte eqn[], byte R1[], byte R2[], byte R3[]) |
Returns the result of the evaluation of an expression with the given values of initial variables (for test purpose) | |
void | getR4fromIndex (const int index, byte R4[R4_BITS]) |
Returns the value of LFSR R4 corresponding to a particular index in [0..TOTAL_MATRICES-1]. | |
int | matrices_generation_exportMatrices (const char *filename, const int lowindex, const int highindex) |
Thread generation method. | |
void * | matrices_generation_launchExport (void *data) |
Thread initializer. | |
int | exportAllMatrices (const char *filename) |
Exports all Resolution Matrices into the specified file. | |
int | matrices_generation_test () |
Autotests the matrices generation on a verified set. |
Implementation of first attack phase: matrices dictionary generation.
#define LOADR1 | ( | op, | |
tap, | |||
x | |||
) |
do {NULLIFY(op); \ memcpy((op), R1[(tap)]+sizeof(byte), R1_SIMPLE_VARS*sizeof(byte));\ op[REGS_TOTAL_VARS-1] = R1[(tap)][0] ^ ((x)&1); \ } while(0)
#define LOADR2 | ( | op, | |
tap, | |||
x | |||
) |
do {NULLIFY(op); \ memcpy((op)+R1_SIMPLE_VARS, R2[(tap)]+sizeof(byte), R2_SIMPLE_VARS*sizeof(byte));\ op[REGS_TOTAL_VARS-1] = R2[(tap)][0] ^ ((x)&1); \ } while(0)
#define LOADR3 | ( | op, | |
tap, | |||
x | |||
) |
do {NULLIFY(op); \ memcpy((op)+R1_SIMPLE_VARS+R2_SIMPLE_VARS, R3[(tap)]+sizeof(byte), R3_SIMPLE_VARS*sizeof(byte));\ op[REGS_TOTAL_VARS-1] = R3[(tap)][0] ^ ((x)&1); \ } while(0)
int exportAllMatrices | ( | const char * | filename | ) |
Exports all Resolution Matrices into the specified file.
[in] | filename | Path of the file to export to |
References BUFFER_SIZE, DEBUG, GenerationArgs::highindex, GenerationArgs::lowindex, matrices_generation_launchExport(), PROCESSING_THREADS, and THREAD_CHUNKSIZE.
Referenced by main().
void getR4fromIndex | ( | const int | index, |
byte | R4[R4_BITS] | ||
) |
Returns the value of LFSR R4 corresponding to a particular index in [0..TOTAL_MATRICES-1].
[in] | index | Considered index |
[in] | R4 | Corresponding value of R4 |
References R4, and R4_INITIAL_CONST_POS.
Referenced by attack_decipherSecretKey().
void matrices_generation_clockingUnit | ( | byte | R1[R1_BITS][1+R1_SIMPLE_VARS], |
byte | R2[R2_BITS][1+R2_SIMPLE_VARS], | ||
byte | R3[R3_BITS][1+R3_SIMPLE_VARS], | ||
byte | R4[R4_BITS], | ||
int | clockAll | ||
) |
Performs register clocking according to the rules of the Clocking Unit.
[in,out] | R1 | First LFSR |
[in,out] | R2 | Second LFSR |
[in,out] | R3 | Third LFSR |
[in,out] | R4 | Fourth LFSR |
[in] | clockAll | When non-zero, bypass Clocking Unit decision: always clock (initialization phase) |
References MAJORITY, matrices_generation_clockR1(), matrices_generation_clockR2(), matrices_generation_clockR3(), matrices_generation_clockR4(), R1, R2, R3, R4, R4_CLOCKTAP_R1, R4_CLOCKTAP_R2, and R4_CLOCKTAP_R3.
Referenced by matrices_generation_processKeystreamEqns().
void matrices_generation_clockR1 | ( | byte | R1[R1_BITS][1+R1_SIMPLE_VARS] | ) |
Clock register R1 contents.
[in,out] | R1 | Register to clock |
References R1, R1_BITS, R1_SHIFTTAP_1, R1_SHIFTTAP_2, R1_SHIFTTAP_3, R1_SHIFTTAP_4, R1_SIMPLE_VARS, and XOR_CHARARRAYS.
Referenced by matrices_generation_clockingUnit().
void matrices_generation_clockR2 | ( | byte | R2[R2_BITS][1+R2_SIMPLE_VARS] | ) |
Clock register R2 contents.
[in,out] | R2 | Register to clock |
References R2, R2_BITS, R2_SHIFTTAP_1, R2_SHIFTTAP_2, R2_SIMPLE_VARS, and XOR_CHARARRAYS.
Referenced by matrices_generation_clockingUnit().
void matrices_generation_clockR3 | ( | byte | R3[R3_BITS][1+R3_SIMPLE_VARS] | ) |
Clock register R3 contents.
[in,out] | R3 | Register to clock |
References R3, R3_BITS, R3_SHIFTTAP_1, R3_SHIFTTAP_2, R3_SHIFTTAP_3, R3_SHIFTTAP_4, R3_SIMPLE_VARS, and XOR_CHARARRAYS.
Referenced by matrices_generation_clockingUnit().
void matrices_generation_clockR4 | ( | byte | R4[] | ) |
Clock register R4 contents.
[in,out] | R4 | Register to clock |
References R4_BITS, R4_SHIFTTAP_1, and R4_SHIFTTAP_2.
Referenced by matrices_generation_clockingUnit().
Performs a double product of two vectors of variables.
We assume here that the given vectors are correctly formed, meaning that all the present variables either belong to the same LFSR simple set, or represent the constant value "1".
[in] | a1 | First Vector |
[in] | a2 | Second Vector |
[out] | out | Product of a1 and a2 |
References DEBUG, MAX, MIN, R1_PROD_VARS, R1_SIMPLE_VARS, R2_PROD_VARS, R2_SIMPLE_VARS, R3_SIMPLE_VARS, REGS_SIMPLE_VARS, and REGS_TOTAL_VARS.
Referenced by matrices_generation_getOutBit().
int matrices_generation_exportMatrices | ( | const char * | filename, |
const int | lowindex, | ||
const int | highindex | ||
) |
Thread generation method.
[in] | filename | Path of the file to write the generated data to |
[in] | lowindex | Index to start the generation form (inclusive) |
[in] | highindex | Last index to be processed (exclusive) |
References BINPRODUCT_MATRIX_MATRIX, BUFFER_SIZE, CODEWORD_LENGTH, DEBUG, EQN_SYSTEM_SIZE, matrices_generation_processKeystreamEqns(), NEEDED_ENCRYPTED_MESSAGES, processFullEncodingGMatrix(), processFullEncodingHMatrix(), PROGRESSBAR, R4, R4_BITS, R4_INITIAL_CONST_POS, REGS_TOTAL_VARS, SOURCEWORD_LENGTH, SYNDROME_LENGTH, and THREAD_CHUNKSIZE.
Referenced by matrices_generation_launchExport().
void matrices_generation_getOutBit | ( | byte | R1[R1_BITS][1+R1_SIMPLE_VARS], |
byte | R2[R2_BITS][1+R2_SIMPLE_VARS], | ||
byte | R3[R3_BITS][1+R3_SIMPLE_VARS], | ||
byte | out[REGS_TOTAL_VARS] | ||
) |
Returns the current out keystream bit (here a set of xored variables) corresponding to a particular LFSR state.
[in] | R1 | First LFSR |
[in] | R2 | Second LFSR |
[in] | R3 | Third LFSR |
[out] | out | Set of variables describing the current out keystream bit |
References matrices_generation_doubleProduct(), R1_BITS, R1_OUTTAP_1, R1_OUTTAP_2, R1_OUTTAP_3, R2_BITS, R2_OUTTAP_1, R2_OUTTAP_2, R2_OUTTAP_3, R3_BITS, R3_OUTTAP_1, R3_OUTTAP_2, R3_OUTTAP_3, REGS_TOTAL_VARS, and XOR_CHARARRAYS.
Referenced by matrices_generation_processKeystreamEqns().
int matrices_generation_getRealVariableIndex | ( | unsigned int | Reg, |
unsigned int | index | ||
) |
Processes the correct location of a variable inside a LFSR from the variable index.
Only variables were recorded in equations, thus there is a small gap in the location of the constant "1" in the LFSR. This function is mandatory to allow a transparent access to the array.
[in] | Reg | Considered register id. May be (1), (2) or (3) |
[in] | index | Variable index |
References DEBUG, R1_INITIAL_CONST_POS, R2_INITIAL_CONST_POS, and R3_INITIAL_CONST_POS.
Referenced by matrices_generation_solveEquation().
void * matrices_generation_launchExport | ( | void * | data | ) |
Thread initializer.
[in] | data | Pointer to the thread's arguments |
References GenerationArgs::filename, GenerationArgs::highindex, GenerationArgs::lowindex, and matrices_generation_exportMatrices().
Referenced by exportAllMatrices().
void matrices_generation_processKeystreamEqns | ( | const byte | initialR4[], |
byte | keystream[][REGS_TOTAL_VARS], | ||
const int | len | ||
) |
Generates the desired amount of keystream dependancy equations (skipping first 99cycles) considering one initial R4 state.
[in] | initialR4 | Inferred initial value of the fourth LFSR |
[out] | keystream | Keystream dependancy equations to be generated |
[in] | len | Desired amount of keystream dependancy equations |
References DEBUG, matrices_generation_clockingUnit(), matrices_generation_getOutBit(), R1, R1_BITS, R1_INITIAL_CONST_POS, R1_SIMPLE_VARS, R2, R2_BITS, R2_INITIAL_CONST_POS, R2_SIMPLE_VARS, R3, R3_BITS, R3_INITIAL_CONST_POS, R3_SIMPLE_VARS, R4, R4_BITS, R4_INITIAL_CONST_POS, and REGS_TOTAL_VARS.
Referenced by matrices_generation_exportMatrices(), and matrices_generation_test().
Returns the result of the evaluation of an expression with the given values of initial variables (for test purpose)
[in] | eqn | Considered expression |
[in] | R1 | Contents of the first LFSR |
[in] | R2 | Contents of the second LFSR |
[in] | R3 | Contents of the third LFSR |
References matrices_generation_getRealVariableIndex(), R1_SIMPLE_VARS, R2_SIMPLE_VARS, R3_SIMPLE_VARS, REGS_SIMPLE_VARS, and REGS_TOTAL_VARS.
Referenced by matrices_generation_test().
int matrices_generation_test | ( | ) |
Autotests the matrices generation on a verified set.
References DEBUG, FRAMEID_BITS, getKeystream(), keysetup(), matrices_generation_processKeystreamEqns(), matrices_generation_solveEquation(), R1, R1_BITS, R2, R2_BITS, R3, R3_BITS, R4_BITS, REGS_TOTAL_VARS, and SECRETKEY_BITS.
Referenced by main().