blob: fae3fdd491ecbd153eca7324cef7252045c3557a [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gsm/a5.h
2 * Osmocom GSM A5 ciphering algorithm header. */
Sylvain Munautf1d33442011-04-23 15:34:11 +02003/*
Sylvain Munautf1d33442011-04-23 15:34:11 +02004 * 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
Sylvain Munaut12ba7782014-06-16 10:13:40 +020023#pragma once
Sylvain Munautf1d33442011-04-23 15:34:11 +020024
25#include <stdint.h>
26
Maxfdb3d8c2016-04-21 16:51:04 +020027#include <osmocom/core/defs.h>
Sylvain Munautf1d33442011-04-23 15:34:11 +020028#include <osmocom/core/bits.h>
29
Sylvain Munaut2735ac42011-11-17 21:01:46 +010030/*! \defgroup a5 GSM A5 ciphering algorithm
31 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020032 * \file a5.h */
Sylvain Munaut2735ac42011-11-17 21:01:46 +010033
Neels Hofmeyr87e45502017-06-20 00:17:59 +020034/*! Converts a frame number into the 22 bit number used in A5/x
Sylvain Munaut2735ac42011-11-17 21:01:46 +010035 * \param[in] fn The true framenumber
36 * \return 22 bit word
37 */
Sylvain Munautf1d33442011-04-23 15:34:11 +020038static inline uint32_t
39osmo_a5_fn_count(uint32_t fn)
40{
41 int t1 = fn / (26 * 51);
42 int t2 = fn % 26;
43 int t3 = fn % 51;
44 return (t1 << 11) | (t3 << 5) | t2;
45}
46
47 /* Notes:
Maxf8699ca2015-03-25 17:20:31 +010048 * - key must be 8 or 16 (for a5/4) bytes long (or NULL for A5/0)
Sylvain Munautf1d33442011-04-23 15:34:11 +020049 * - the dl and ul pointer must be either NULL or 114 bits long
50 * - fn is the _real_ GSM frame number.
51 * (converted internally to fn_count)
52 */
Sylvain Munautc1e9be92012-12-06 08:23:02 +010053int osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
Maxfdb3d8c2016-04-21 16:51:04 +020054void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) OSMO_DEPRECATED("Use generic osmo_a5() instead");
55void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) OSMO_DEPRECATED("Use generic osmo_a5() instead");
Sylvain Munautf1d33442011-04-23 15:34:11 +020056
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020057/*! @} */