A5/1 - stream cipher used to provide over-the-air communication privacy in the GSM

A5/1 stream cipher is used to ensure the privacy of communications in the standard GSM mobile phone . Specifications initially was kept secret but became public knowledge through leaks of information and the use of reverse engineering . Used in Europe and the United States.



Algorithm can be divided into several stages. Before the actual encryption need a proper initialization, filling the registers and calculating the TDMA frame (to provide time division multiple access), one which is required because the algorithm A5/1 is widely used in mobile telephony. Based on a number of TDMA base station determines the order data and the total initialization vector, which is what generated the seed of the frame number. On the basis of the generated vector registers are initialized to bits by some specific rules:

-Resetting all three shift registers.
-Random filling key and TDMA frame.
-Initiating registry key bits in 64 clock cycles without rules start / stop bit timing.
-Introduction to the registers bit TDMA frame in 22 cycles, also without the rule of bit timing.
-Followed by 100 cycles of mixing which take account of the principles behind the start / stop.

void a51_init() {
    int i = 0;
    for (i = 0; i < KEY_COUNT; i++) {
        reg1[0] = key[i] ^ reg1[0];
        reg2[0] = key[i] ^ reg2[0];
        reg3[0] = key[i] ^ reg3[0];

        lfsr_1();
        lfsr_2();
        lfsr_3();
    }

    for (i = 0; i < 100; i++) {
        a51();
    }
}

int a51() {
    int clock1 = reg1[8];
    int clock2 = reg2[10];
    int clock3 = reg3[10];

    int lf1 = reg1[18]; //Old bit value
    int lf2 = reg2[21]; //Old bit value
    int lf3 = reg3[22]; //Old bit value

    if (clock1 == clock2 || clock1 == clock3) {
        lfsr_1();
    }
    if (clock2 == clock1 || clock2 == clock3) {
        lfsr_2();
    }
    if (clock3 == clock2 || clock3 == clock1) {
        lfsr_3();
    }

    return lf1 ^ lf2 ^ lf3;
}
Full source code: https://github.com/khipis/c-unix-sandbox/blob/master/shift-registers/a51.c

Popularne posty