blob: 649dbab19ef86f165f23f51d34fc9adac75fc7ca [file] [log] [blame]
Sylvain Munautf1d33442011-04-23 15:34:11 +02001/*
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#ifndef __OSMO_A5_H__
24#define __OSMO_A5_H__
25
26#include <stdint.h>
27
28#include <osmocom/core/bits.h>
29
Sylvain Munaut2735ac42011-11-17 21:01:46 +010030/*! \defgroup a5 GSM A5 ciphering algorithm
31 * @{
32 */
33
34/*! \file gsm/a5.h
35 * \brief Osmocom GSM A5 ciphering algorithm header
36 */
37
38/*! \brief Converts a frame number into the 22 bit number used in A5/x
39 * \param[in] fn The true framenumber
40 * \return 22 bit word
41 */
Sylvain Munautf1d33442011-04-23 15:34:11 +020042static inline uint32_t
43osmo_a5_fn_count(uint32_t fn)
44{
45 int t1 = fn / (26 * 51);
46 int t2 = fn % 26;
47 int t3 = fn % 51;
48 return (t1 << 11) | (t3 << 5) | t2;
49}
50
51 /* Notes:
52 * - key must be 8 bytes long (or NULL for A5/0)
53 * - the dl and ul pointer must be either NULL or 114 bits long
54 * - fn is the _real_ GSM frame number.
55 * (converted internally to fn_count)
56 */
Sylvain Munaut3e387cb2011-11-17 19:45:42 +010057void osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
58void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
59void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
Sylvain Munautf1d33442011-04-23 15:34:11 +020060
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020061/*! @} */
Sylvain Munaut2735ac42011-11-17 21:01:46 +010062
Sylvain Munautf1d33442011-04-23 15:34:11 +020063#endif /* __OSMO_A5_H__ */