summaryrefslogtreecommitdiffstats
path: root/src/gsm/a5.c
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2011-11-17 20:36:50 +0100
committerSylvain Munaut <tnt@246tNt.com>2011-11-17 20:36:50 +0100
commit7f975d231bf8b7267a65057185cdbc83dfd40ab7 (patch)
tree6563e4c431ace0cc930668edc1262603afe64ce3 /src/gsm/a5.c
parent810c33483eeeff4ff7cebf28ad03fbbb3f5f8b43 (diff)
gsm/a5: Rewrite A5/2 algo to avoid the delayed bit
It's just clearer that way ... Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src/gsm/a5.c')
-rw-r--r--src/gsm/a5.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/gsm/a5.c b/src/gsm/a5.c
index fe341a6a..31c2ba95 100644
--- a/src/gsm/a5.c
+++ b/src/gsm/a5.c
@@ -224,23 +224,18 @@ _a5_2_clock(uint32_t r[], int force)
}
static inline uint8_t
-_a5_2_get_output(uint32_t r[], uint8_t *db)
+_a5_2_get_output(uint32_t r[])
{
- uint8_t cb, tb;
+ uint8_t b;
- tb = (r[0] >> (A5_R1_LEN-1)) ^
- (r[1] >> (A5_R2_LEN-1)) ^
- (r[2] >> (A5_R3_LEN-1));
-
- cb = *db;
-
- *db = ( tb ^
- _a5_12_majority( r[0] & 0x08000, ~r[0] & 0x04000, r[0] & 0x1000) ^
- _a5_12_majority(~r[1] & 0x10000, r[1] & 0x02000, r[1] & 0x0200) ^
- _a5_12_majority( r[2] & 0x40000, r[2] & 0x10000, ~r[2] & 0x2000)
- );
+ b = (r[0] >> (A5_R1_LEN-1)) ^
+ (r[1] >> (A5_R2_LEN-1)) ^
+ (r[2] >> (A5_R3_LEN-1)) ^
+ _a5_12_majority( r[0] & 0x08000, ~r[0] & 0x04000, r[0] & 0x1000) ^
+ _a5_12_majority(~r[1] & 0x10000, r[1] & 0x02000, r[1] & 0x0200) ^
+ _a5_12_majority( r[2] & 0x40000, r[2] & 0x10000, ~r[2] & 0x2000);
- return cb;
+ return b;
}
void
@@ -249,7 +244,6 @@ osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul)
uint32_t r[4] = {0, 0, 0, 0};
uint32_t fn_count;
uint32_t b;
- uint8_t db = 0, o;
int i;
/* Key load */
@@ -286,26 +280,21 @@ osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul)
r[3] |= 1 << 10;
/* Mix */
- for (i=0; i<100; i++)
+ for (i=0; i<99; i++)
{
_a5_2_clock(r, 0);
}
- _a5_2_get_output(r, &db);
-
-
/* Output */
for (i=0; i<114; i++) {
_a5_2_clock(r, 0);
- o = _a5_2_get_output(r, &db);
if (dl)
- dl[i] = o;
+ dl[i] = _a5_2_get_output(r);
}
for (i=0; i<114; i++) {
_a5_2_clock(r, 0);
- o = _a5_2_get_output(r, &db);
if (ul)
- ul[i] = o;
+ ul[i] = _a5_2_get_output(r);
}
}