blob: 1b26842f251aa7b7ef166f75ec7dbf98378d046e [file] [log] [blame]
Sylvain Munautf1d33442011-04-23 15:34:11 +02001/*
Sylvain Munautf1d33442011-04-23 15:34:11 +02002 * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
3 *
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Sylvain Munautf1d33442011-04-23 15:34:11 +020015 */
16
Sylvain Munaut12ba7782014-06-16 10:13:40 +020017#pragma once
Sylvain Munautf1d33442011-04-23 15:34:11 +020018
19#include <stdint.h>
20
Maxfdb3d8c2016-04-21 16:51:04 +020021#include <osmocom/core/defs.h>
Sylvain Munautf1d33442011-04-23 15:34:11 +020022#include <osmocom/core/bits.h>
23
Sylvain Munaut2735ac42011-11-17 21:01:46 +010024/*! \defgroup a5 GSM A5 ciphering algorithm
25 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020026 * \file a5.h */
Sylvain Munaut2735ac42011-11-17 21:01:46 +010027
Neels Hofmeyr87e45502017-06-20 00:17:59 +020028/*! Converts a frame number into the 22 bit number used in A5/x
Sylvain Munaut2735ac42011-11-17 21:01:46 +010029 * \param[in] fn The true framenumber
30 * \return 22 bit word
31 */
Sylvain Munautf1d33442011-04-23 15:34:11 +020032static inline uint32_t
33osmo_a5_fn_count(uint32_t fn)
34{
35 int t1 = fn / (26 * 51);
36 int t2 = fn % 26;
37 int t3 = fn % 51;
38 return (t1 << 11) | (t3 << 5) | t2;
39}
40
41 /* Notes:
Maxf8699ca2015-03-25 17:20:31 +010042 * - key must be 8 or 16 (for a5/4) bytes long (or NULL for A5/0)
Sylvain Munautf1d33442011-04-23 15:34:11 +020043 * - the dl and ul pointer must be either NULL or 114 bits long
44 * - fn is the _real_ GSM frame number.
45 * (converted internally to fn_count)
46 */
Sylvain Munautc1e9be92012-12-06 08:23:02 +010047int osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul);
Maxfdb3d8c2016-04-21 16:51:04 +020048void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) OSMO_DEPRECATED("Use generic osmo_a5() instead");
49void 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 +020050
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020051/*! @} */