treewide: remove FSF address
[osmocom-bb.git] / src / shared / libosmocore / include / osmocom / gsm / a5.h
blob807a2d832acbaefe7245ace3ce46ada03462e05d
1 /*
2 * a5.h
4 * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
6 * All Rights Reserved
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.
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.
19 #ifndef __OSMO_A5_H__
20 #define __OSMO_A5_H__
22 #include <stdint.h>
24 #include <osmocom/core/bits.h>
26 /*! \defgroup a5 GSM A5 ciphering algorithm
27 * @{
30 /*! \file gsm/a5.h
31 * \brief Osmocom GSM A5 ciphering algorithm header
34 /*! \brief Converts a frame number into the 22 bit number used in A5/x
35 * \param[in] fn The true framenumber
36 * \return 22 bit word
38 static inline uint32_t
39 osmo_a5_fn_count(uint32_t fn)
41 int t1 = fn / (26 * 51);
42 int t2 = fn % 26;
43 int t3 = fn % 51;
44 return (t1 << 11) | (t3 << 5) | t2;
47 /* Notes:
48 * - key must be 8 bytes long (or NULL for A5/0)
49 * - 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)
53 void osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
54 void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
55 void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
57 /*! @} */
59 #endif /* __OSMO_A5_H__ */