libosmogsm  0.9.3.20160317
Osmocom GSM library
a5.h
Go to the documentation of this file.
1 /*
2  * a5.h
3  *
4  * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
5  *
6  * All Rights Reserved
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include <stdint.h>
26 
27 #include <osmocom/core/bits.h>
28 
41 static inline uint32_t
42 osmo_a5_fn_count(uint32_t fn)
43 {
44  int t1 = fn / (26 * 51);
45  int t2 = fn % 26;
46  int t3 = fn % 51;
47  return (t1 << 11) | (t3 << 5) | t2;
48 }
49 
50  /* Notes:
51  * - key must be 8 or 16 (for a5/4) bytes long (or NULL for A5/0)
52  * - the dl and ul pointer must be either NULL or 114 bits long
53  * - fn is the _real_ GSM frame number.
54  * (converted internally to fn_count)
55  */
56 int osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
57 void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
58 void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
59 
int osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul)
Main method to generate a A5/x cipher stream.
Definition: a5.c:116
void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul)
Generate a GSM A5/1 cipher stream.
Definition: a5.c:381
void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul)
Generate a GSM A5/1 cipher stream.
Definition: a5.c:264
static uint32_t osmo_a5_fn_count(uint32_t fn)
Converts a frame number into the 22 bit number used in A5/x.
Definition: a5.h:42